Thread (69 messages) 69 messages, 8 authors, 2026-02-27

Re: [PATCH v8 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

From: Andrew Lunn <andrew@lunn.ch>
Date: 2026-02-20 17:42:18
Also in: imx, linux-devicetree, linux-doc, linux-gpio, linux-remoteproc, lkml

quoted
quoted
struct msg_hdr {
    u8  id;
    u32 size;
    u8  flags;
};
That is just a bad design. The point of not allowing __packed is that it forces you
to design your structures correctly. Maybe AI has no idea of taste, but Maintainer
do and would not allow a u32 to be unaligned like this.
Let’s keep the discussion technical instead of taste. 😊

My point with the earlier example was simply to illustrate how layout differences can 
happen across architectures or compilers. I’m more interested in understanding how 
you would prefer this specific structure to be defined so that it avoids unaligned fields 
while still maintaining a stable on‑wire format.
struct msg_hdr {
    u32 size;
    u8  id;
    u8  flags;
};

The compiler will lay this out as you expect, it won't add any padding
between the fields.

You need to be careful with sizeof(struct msg_hdr). On 8 and 16 bit
machines, it is probably 6. On 32, or 64 bit machine it is probably 8.

I would say having a 6 byte message is probably a bad design, and you
should try to make the u32 a u16 if you can. Again, not using the
__packed is making you think about the design, and probably makes the
design better as a result.

    Andrew

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help