Skip to content

Commit

Permalink
smb: smb2pdu.h: Avoid -Wflex-array-member-not-at-end warnings
Browse files Browse the repository at this point in the history
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.

So, in order to avoid ending up with a flexible-array member in the
middle of multiple other structs, we use the `__struct_group()` helper
to separate the flexible array from the rest of the members in the
flexible structure, and use the tagged `struct create_context_hdr`
instead of `struct create_context`.

So, with these changes, fix 51 of the following warnings[1]:

fs/smb/client/../common/smb2pdu.h:1225:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Link: https://gist.github.com/GustavoARSilva/772526a39be3dd4db39e71497f0a9893 [1]
Link: KSPP/linux#202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
GustavoARSilva authored and Steve French committed Apr 24, 2024
1 parent 47406f6 commit c29e09c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
12 changes: 6 additions & 6 deletions fs/smb/client/smb2pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct durable_context_v2 {
} __packed;

struct create_durable_v2 {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct durable_context_v2 dcontext;
} __packed;
Expand All @@ -167,28 +167,28 @@ struct durable_reconnect_context_v2_rsp {
} __packed;

struct create_durable_handle_reconnect_v2 {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct durable_reconnect_context_v2 dcontext;
__u8 Pad[4];
} __packed;

/* See MS-SMB2 2.2.13.2.5 */
struct crt_twarp_ctxt {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
__le64 Timestamp;

} __packed;

/* See MS-SMB2 2.2.13.2.9 */
struct crt_query_id_ctxt {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
} __packed;

struct crt_sd_ctxt {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct smb3_sd sd;
} __packed;
Expand Down Expand Up @@ -415,7 +415,7 @@ struct smb2_posix_info_parsed {
};

struct smb2_create_ea_ctx {
struct create_context ctx;
struct create_context_hdr ctx;
__u8 name[8];
struct smb2_file_full_ea_info ea;
} __packed;
Expand Down
33 changes: 18 additions & 15 deletions fs/smb/common/smb2pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1171,12 +1171,15 @@ struct smb2_server_client_notification {
#define SMB2_CREATE_FLAG_REPARSEPOINT 0x01

struct create_context {
__le32 Next;
__le16 NameOffset;
__le16 NameLength;
__le16 Reserved;
__le16 DataOffset;
__le32 DataLength;
/* New members must be added within the struct_group() macro below. */
__struct_group(create_context_hdr, hdr, __packed,
__le32 Next;
__le16 NameOffset;
__le16 NameLength;
__le16 Reserved;
__le16 DataOffset;
__le32 DataLength;
);
__u8 Buffer[];
} __packed;

Expand Down Expand Up @@ -1222,15 +1225,15 @@ struct smb2_create_rsp {
} __packed;

struct create_posix {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[16];
__le32 Mode;
__u32 Reserved;
} __packed;

/* See MS-SMB2 2.2.13.2.3 and MS-SMB2 2.2.13.2.4 */
struct create_durable {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
union {
__u8 Reserved[16];
Expand All @@ -1243,14 +1246,14 @@ struct create_durable {

/* See MS-SMB2 2.2.13.2.5 */
struct create_mxac_req {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
__le64 Timestamp;
} __packed;

/* See MS-SMB2 2.2.14.2.5 */
struct create_mxac_rsp {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
__le32 QueryStatus;
__le32 MaximalAccess;
Expand Down Expand Up @@ -1286,21 +1289,21 @@ struct lease_context_v2 {
} __packed;

struct create_lease {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct lease_context lcontext;
} __packed;

struct create_lease_v2 {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct lease_context_v2 lcontext;
__u8 Pad[4];
} __packed;

/* See MS-SMB2 2.2.14.2.9 */
struct create_disk_id_rsp {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
__le64 DiskFileId;
__le64 VolumeId;
Expand All @@ -1309,7 +1312,7 @@ struct create_disk_id_rsp {

/* See MS-SMB2 2.2.13.2.13 */
struct create_app_inst_id {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[16];
__le32 StructureSize; /* Must be 20 */
__u16 Reserved;
Expand All @@ -1318,7 +1321,7 @@ struct create_app_inst_id {

/* See MS-SMB2 2.2.13.2.15 */
struct create_app_inst_id_vers {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[16];
__le32 StructureSize; /* Must be 24 */
__u16 Reserved;
Expand Down
18 changes: 9 additions & 9 deletions fs/smb/server/smb2pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct preauth_integrity_info {
#define SMB2_SESSION_TIMEOUT (10 * HZ)

struct create_durable_req_v2 {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
__le32 Timeout;
__le32 Flags;
Expand All @@ -73,7 +73,7 @@ struct create_durable_req_v2 {
} __packed;

struct create_durable_reconn_req {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
union {
__u8 Reserved[16];
Expand All @@ -85,7 +85,7 @@ struct create_durable_reconn_req {
} __packed;

struct create_durable_reconn_v2_req {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct {
__u64 PersistentFileId;
Expand All @@ -96,13 +96,13 @@ struct create_durable_reconn_v2_req {
} __packed;

struct create_alloc_size_req {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
__le64 AllocationSize;
} __packed;

struct create_durable_rsp {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
union {
__u8 Reserved[8];
Expand All @@ -114,15 +114,15 @@ struct create_durable_rsp {
/* Flags */
#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
struct create_durable_v2_rsp {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
__le32 Timeout;
__le32 Flags;
} __packed;

/* equivalent of the contents of SMB3.1.1 POSIX open context response */
struct create_posix_rsp {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[16];
__le32 nlink;
__le32 reparse_tag;
Expand Down Expand Up @@ -381,13 +381,13 @@ struct smb2_ea_info {
} __packed; /* level 15 Query */

struct create_ea_buf_req {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct smb2_ea_info ea;
} __packed;

struct create_sd_buf_req {
struct create_context ccontext;
struct create_context_hdr ccontext;
__u8 Name[8];
struct smb_ntsd ntsd;
} __packed;
Expand Down

0 comments on commit c29e09c

Please sign in to comment.