[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z8CxraJaTBFuKSIQ@valentin-vidic.from.hr>
Date: Thu, 27 Feb 2025 19:40:45 +0100
From: Valentin Vidić <vvidic@...entin-vidic.from.hr>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Jiri Slaby <jirislaby@...nel.org>, linux-kernel@...r.kernel.org,
linux-serial@...r.kernel.org
Subject: Re: [PATCH] tty: pty: remove redundant local variable
On Wed, Feb 26, 2025 at 04:49:45PM -0800, Greg Kroah-Hartman wrote:
> On Wed, Feb 26, 2025 at 09:47:07PM +0100, Valentin Vidic wrote:
> > The value of to is only used once, so no need to store it in a
> > variable.
> >
> > Signed-off-by: Valentin Vidic <vvidic@...entin-vidic.from.hr>
> > ---
> > drivers/tty/pty.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
> > index df08f13052ff..c6eb711500b6 100644
> > --- a/drivers/tty/pty.c
> > +++ b/drivers/tty/pty.c
> > @@ -110,12 +110,10 @@ static void pty_unthrottle(struct tty_struct *tty)
> >
> > static ssize_t pty_write(struct tty_struct *tty, const u8 *buf, size_t c)
> > {
> > - struct tty_struct *to = tty->link;
> > -
> > if (tty->flow.stopped || !c)
> > return 0;
> >
> > - return tty_insert_flip_string_and_push_buffer(to->port, buf, c);
> > + return tty_insert_flip_string_and_push_buffer(tty->link->port, buf, c);
>
> does this actually change the resulting code any?
>
> "to" actually means something here, the tty is the "from" and the link
> is the "to" where the data is going, so having it be "to" makes the code
> easier to understand by humans, which is the first goal of code.
> Maintaining it for long periods of time is key.
>
> Otherwise your change "tty->link->port" doesn't make it all that obvious
> that the this is being written not to the tty device itself, but to
> somewhere else, right?
Right, the resulting code does not change, it only simplifies the
function. For example, already the next one is very similar and does not
use the helper variable:
static unsigned int pty_write_room(struct tty_struct *tty)
{
if (tty->flow.stopped)
return 0;
return tty_buffer_space_avail(tty->link->port);
}
--
Valentin
Powered by blists - more mailing lists