Re: drivers/media/v4l2-core/v4l2-ioctl.c:303:28: warning: taking address of packed member 'pixelformat' of class or structure 'v4l2_pix_format_mplane' may result in an unaligned pointer value

From: Petr Mladek
Date: Thu Aug 26 2021 - 09:22:55 EST


On Thu 2021-08-19 11:10:53, Sakari Ailus wrote:
> On Fri, Jul 16, 2021 at 03:12:11PM +0300, Andy Shevchenko wrote:
> > On Fri, Jul 16, 2021 at 02:41:05PM +0300, Sakari Ailus wrote:
> > > On Wed, Jul 14, 2021 at 10:45:26PM +0300, Andy Shevchenko wrote:
> > > > > >> drivers/media/v4l2-core/v4l2-ioctl.c:347:37: warning: taking address of packed member 'pixelformat' of class or structure 'v4l2_sdr_format' may result in an unaligned pointer value [-Waddress-of-packed-member]
> > > >

Is there any plan to fix this, please?


> > > > Why is it packed in the first place? Is it used on unaligned addresses
> > > > in other structures? But even so, why should it matter?
> > >
> > > It's packed since we wanted to avoid having holes in the structs. There are
> > > other ways to do that but it's ABI dependent and is prone to human errors,
> > > too.

> > What holes can you think about in the above mention structure?
>
> Probably not that one but it has happened in the past that the struct
> memory layout has been unintentionally different in different ABIs and that
> has not been the intention, but rather a bug.

What kind of bugs did the different ABI caused, please? Incompatibly
between 3rd party drivers that were built with different compilers?

I am not familiar with these problems. I wonder if there is a better
solution. I guess that it might be a common problem affecting most
drivers.

Anyway, the non-aligned struct members might create slower code.

> Packing has been added in newer structs to avoid that.

And this smells with cargo-cult programming. People might make all new
structures packed even when it is not really needed.

Best Regards,
Petr