Re: [PATCH][next] tty: tty_buffer: Avoid hundreds of -Wflex-array-member-not-at-end warnings

From: Greg Kroah-Hartman
Date: Wed Feb 05 2025 - 03:16:56 EST


On Wed, Feb 05, 2025 at 06:33:13PM +1030, Gustavo A. R. Silva wrote:
>
>
> On 05/02/25 17:29, Jiri Slaby wrote:
> > On 05. 02. 25, 7:49, Gustavo A. R. Silva wrote:
> > > If the above changes are better for you then I'll send a new patch. :)
> >
> > No, you are supposed to switch tty_buffer to tty_buffer_hdr too.
>
> Do you mean something like the following:
>
> struct tty_buffer {
> - union {
> - struct tty_buffer *next;
> - struct llist_node free;
> - };
> - unsigned int used;
> - unsigned int size;
> - unsigned int commit;
> - unsigned int lookahead; /* Lazy update on recv, can become less than "read" */
> - unsigned int read;
> - bool flags;
> + struct tty_buffer_hdr hdr;
> /* Data points here */
> u8 data[] __aligned(sizeof(unsigned long));
> };
>
> +struct tty_buffer_hdr {
> + union {
> + struct tty_buffer *next;
> + struct llist_node free;
> + };
> + unsigned int used;
> + unsigned int size;
> + unsigned int commit;
> + unsigned int lookahead; /* Lazy update on recv, can become less than "read" */
> + unsigned int read;
> + bool flags;
> +};
> +

Yes!

> The problem with this is that then we have to modify a lot of
> lines from, let's say, instance->used, instance->size, etc...
> to instance->hdr.used, instance->hdr.size, and so on...

Great, let's do that and get it right please.

> This code churn is avoided if we use the struct_group() helper.

It's not "churn" if it is "fix the code to be correct" :)

thanks,

greg k-h