Re: [PATCH 1/2] tty: Convert tty_buffer flags to bool

From: Ilpo Järvinen
Date: Wed Oct 19 2022 - 08:03:45 EST


On Wed, 19 Oct 2022, Greg KH wrote:

> On Wed, Oct 19, 2022 at 12:42:39PM +0300, Ilpo Järvinen wrote:
> > The struct tty_buffer has flags which is only used for storing TTYB_NORMAL.
> > There is also a few quite confusing operations for checking the presense
> > of TTYB_NORMAL. Simplify things by converting flags to bool.
> >
> > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
> > ---
> > drivers/tty/tty_buffer.c | 28 ++++++++++++++--------------
> > include/linux/tty_buffer.h | 5 +----
> > include/linux/tty_flip.h | 4 ++--
> > 3 files changed, 17 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
> > index 5e287dedce01..be3431575a19 100644
> > --- a/drivers/tty/tty_buffer.c
> > +++ b/drivers/tty/tty_buffer.c
> > @@ -107,7 +107,7 @@ static void tty_buffer_reset(struct tty_buffer *p, size_t size)
> > p->commit = 0;
> > p->lookahead = 0;
> > p->read = 0;
> > - p->flags = 0;
> > + p->flags = true;
> > }
> >
> > /**
> > @@ -249,7 +249,7 @@ void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld)
> > * __tty_buffer_request_room - grow tty buffer if needed
> > * @port: tty port
> > * @size: size desired
> > - * @flags: buffer flags if new buffer allocated (default = 0)
> > + * @flags: buffer flags if new buffer allocated
>
> If all this does is store TTYB_NORMAL, why not name it "ttyb_normal"?
> Leaving it at "flags" and having that be a boolean is just confusing.

No, it's intentional.

"Flags" (as boolean) here refer to whether the buffer stores flag array
along with the character data array. Previously it perhaps could be
interpreted differently meaning that the member variable itself stored
flags such as TTYB_NORMAL.

Flags is much better name than ttyb_normal, IMHO.

--
i.