Skip to content

Commit 7330195

Browse files
GustavoARSilvaSteve French
authored andcommitted
smb: client, common: Avoid multiple -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. So, in order to avoid ending up with flexible-array members in the middle of other structs, we use the `__struct_group()` helper to separate the flexible arrays from the rest of the members in the flexible structures. We then use the newly created tagged `struct smb2_file_link_info_hdr` and `struct smb2_file_rename_info_hdr` to replace the type of the objects causing trouble: `rename_info` and `link_info` in `struct smb2_compound_vars`. We also want to ensure that when new members need to be added to the flexible structures, they are always included within the newly created tagged structs. For this, we use `static_assert()`. This ensures that the memory layout for both the flexible structure and the new tagged struct is the same after any changes. So, with these changes, fix 86 of the following warnings: fs/smb/client/cifsglob.h:2335:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/smb/client/cifsglob.h:2334:38: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 654292a commit 7330195

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

fs/smb/client/cifsglob.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,8 +2324,8 @@ struct smb2_compound_vars {
23242324
struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
23252325
struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
23262326
struct kvec close_iov;
2327-
struct smb2_file_rename_info rename_info;
2328-
struct smb2_file_link_info link_info;
2327+
struct smb2_file_rename_info_hdr rename_info;
2328+
struct smb2_file_link_info_hdr link_info;
23292329
struct kvec ea_iov;
23302330
};
23312331

fs/smb/common/smb2pdu.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,23 +1707,33 @@ struct smb2_file_internal_info {
17071707
} __packed; /* level 6 Query */
17081708

17091709
struct smb2_file_rename_info { /* encoding of request for level 10 */
1710-
__u8 ReplaceIfExists; /* 1 = replace existing target with new */
1711-
/* 0 = fail if target already exists */
1712-
__u8 Reserved[7];
1713-
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1714-
__le32 FileNameLength;
1710+
/* New members MUST be added within the struct_group() macro below. */
1711+
__struct_group(smb2_file_rename_info_hdr, __hdr, __packed,
1712+
__u8 ReplaceIfExists; /* 1 = replace existing target with new */
1713+
/* 0 = fail if target already exists */
1714+
__u8 Reserved[7];
1715+
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1716+
__le32 FileNameLength;
1717+
);
17151718
char FileName[]; /* New name to be assigned */
17161719
/* padding - overall struct size must be >= 24 so filename + pad >= 6 */
17171720
} __packed; /* level 10 Set */
1721+
static_assert(offsetof(struct smb2_file_rename_info, FileName) == sizeof(struct smb2_file_rename_info_hdr),
1722+
"struct member likely outside of __struct_group()");
17181723

17191724
struct smb2_file_link_info { /* encoding of request for level 11 */
1720-
__u8 ReplaceIfExists; /* 1 = replace existing link with new */
1721-
/* 0 = fail if link already exists */
1722-
__u8 Reserved[7];
1723-
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1724-
__le32 FileNameLength;
1725+
/* New members MUST be added within the struct_group() macro below. */
1726+
__struct_group(smb2_file_link_info_hdr, __hdr, __packed,
1727+
__u8 ReplaceIfExists; /* 1 = replace existing link with new */
1728+
/* 0 = fail if link already exists */
1729+
__u8 Reserved[7];
1730+
__u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1731+
__le32 FileNameLength;
1732+
);
17251733
char FileName[]; /* Name to be assigned to new link */
17261734
} __packed; /* level 11 Set */
1735+
static_assert(offsetof(struct smb2_file_link_info, FileName) == sizeof(struct smb2_file_link_info_hdr),
1736+
"struct member likely outside of __struct_group()");
17271737

17281738
/*
17291739
* This level 18, although with struct with same name is different from cifs

0 commit comments

Comments
 (0)