Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] tty: pty: remove redundant local variable
@ 2025-02-26 20:47 Valentin Vidic
  2025-02-27  0:49 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Valentin Vidic @ 2025-02-26 20:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-kernel, linux-serial, Valentin Vidic

The value of to is only used once, so no need to store it in a
variable.

Signed-off-by: Valentin Vidic <vvidic@valentin-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);
 }
 
 /**
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tty: pty: remove redundant local variable
  2025-02-26 20:47 [PATCH] tty: pty: remove redundant local variable Valentin Vidic
@ 2025-02-27  0:49 ` Greg Kroah-Hartman
  2025-02-27 18:40   ` Valentin Vidić
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2025-02-27  0:49 UTC (permalink / raw)
  To: Valentin Vidic; +Cc: Jiri Slaby, linux-kernel, linux-serial

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@valentin-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?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tty: pty: remove redundant local variable
  2025-02-27  0:49 ` Greg Kroah-Hartman
@ 2025-02-27 18:40   ` Valentin Vidić
  0 siblings, 0 replies; 3+ messages in thread
From: Valentin Vidić @ 2025-02-27 18:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-kernel, linux-serial

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@valentin-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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-27 18:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26 20:47 [PATCH] tty: pty: remove redundant local variable Valentin Vidic
2025-02-27  0:49 ` Greg Kroah-Hartman
2025-02-27 18:40   ` Valentin Vidić

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox