Skip to content

Commit

Permalink
smb: smb2pdu.h: Use static_assert() to check struct sizes
Browse files Browse the repository at this point in the history
Commit 9f9bef9 ("smb: smb2pdu.h: Avoid -Wflex-array-member-not-at-end
warnings") introduced tagged `struct create_context_hdr`. We want to
ensure that when new members need to be added to the flexible structure,
they are always included within this tagged struct.

So, we use `static_assert()` to ensure that the memory layout for
both the flexible structure and the tagged struct is the same after
any changes.

Acked-by: Namjae Jeon <[email protected]>
Signed-off-by: Gustavo A. R. Silva <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
GustavoARSilva authored and Steve French committed Aug 12, 2024
1 parent 9fae888 commit 022ee3a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fs/smb/common/smb2pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,8 @@ struct create_context {
);
__u8 Buffer[];
} __packed;
static_assert(offsetof(struct create_context, Buffer) == sizeof(struct create_context_hdr),
"struct member likely outside of __struct_group()");

struct smb2_create_req {
struct smb2_hdr hdr;
Expand Down

0 comments on commit 022ee3a

Please sign in to comment.