Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

smb: smb2pdu.h: Avoid -Wflex-array-member-not-at-end warnings

-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: https://github.com/KSPP/linux/issues/202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>

authored by

Gustavo A. R. Silva and committed by
Steve French
9f9bef9b f4e8d802

+33 -30
+6 -6
fs/smb/client/smb2pdu.h
··· 145 145 } __packed; 146 146 147 147 struct create_durable_v2 { 148 - struct create_context ccontext; 148 + struct create_context_hdr ccontext; 149 149 __u8 Name[8]; 150 150 struct durable_context_v2 dcontext; 151 151 } __packed; ··· 167 167 } __packed; 168 168 169 169 struct create_durable_handle_reconnect_v2 { 170 - struct create_context ccontext; 170 + struct create_context_hdr ccontext; 171 171 __u8 Name[8]; 172 172 struct durable_reconnect_context_v2 dcontext; 173 173 __u8 Pad[4]; ··· 175 175 176 176 /* See MS-SMB2 2.2.13.2.5 */ 177 177 struct crt_twarp_ctxt { 178 - struct create_context ccontext; 178 + struct create_context_hdr ccontext; 179 179 __u8 Name[8]; 180 180 __le64 Timestamp; 181 181 ··· 183 183 184 184 /* See MS-SMB2 2.2.13.2.9 */ 185 185 struct crt_query_id_ctxt { 186 - struct create_context ccontext; 186 + struct create_context_hdr ccontext; 187 187 __u8 Name[8]; 188 188 } __packed; 189 189 190 190 struct crt_sd_ctxt { 191 - struct create_context ccontext; 191 + struct create_context_hdr ccontext; 192 192 __u8 Name[8]; 193 193 struct smb3_sd sd; 194 194 } __packed; ··· 415 415 }; 416 416 417 417 struct smb2_create_ea_ctx { 418 - struct create_context ctx; 418 + struct create_context_hdr ctx; 419 419 __u8 name[8]; 420 420 struct smb2_file_full_ea_info ea; 421 421 } __packed;
+18 -15
fs/smb/common/smb2pdu.h
··· 1171 1171 #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01 1172 1172 1173 1173 struct create_context { 1174 - __le32 Next; 1175 - __le16 NameOffset; 1176 - __le16 NameLength; 1177 - __le16 Reserved; 1178 - __le16 DataOffset; 1179 - __le32 DataLength; 1174 + /* New members must be added within the struct_group() macro below. */ 1175 + __struct_group(create_context_hdr, hdr, __packed, 1176 + __le32 Next; 1177 + __le16 NameOffset; 1178 + __le16 NameLength; 1179 + __le16 Reserved; 1180 + __le16 DataOffset; 1181 + __le32 DataLength; 1182 + ); 1180 1183 __u8 Buffer[]; 1181 1184 } __packed; 1182 1185 ··· 1225 1222 } __packed; 1226 1223 1227 1224 struct create_posix { 1228 - struct create_context ccontext; 1225 + struct create_context_hdr ccontext; 1229 1226 __u8 Name[16]; 1230 1227 __le32 Mode; 1231 1228 __u32 Reserved; ··· 1233 1230 1234 1231 /* See MS-SMB2 2.2.13.2.3 and MS-SMB2 2.2.13.2.4 */ 1235 1232 struct create_durable { 1236 - struct create_context ccontext; 1233 + struct create_context_hdr ccontext; 1237 1234 __u8 Name[8]; 1238 1235 union { 1239 1236 __u8 Reserved[16]; ··· 1246 1243 1247 1244 /* See MS-SMB2 2.2.13.2.5 */ 1248 1245 struct create_mxac_req { 1249 - struct create_context ccontext; 1246 + struct create_context_hdr ccontext; 1250 1247 __u8 Name[8]; 1251 1248 __le64 Timestamp; 1252 1249 } __packed; 1253 1250 1254 1251 /* See MS-SMB2 2.2.14.2.5 */ 1255 1252 struct create_mxac_rsp { 1256 - struct create_context ccontext; 1253 + struct create_context_hdr ccontext; 1257 1254 __u8 Name[8]; 1258 1255 __le32 QueryStatus; 1259 1256 __le32 MaximalAccess; ··· 1289 1286 } __packed; 1290 1287 1291 1288 struct create_lease { 1292 - struct create_context ccontext; 1289 + struct create_context_hdr ccontext; 1293 1290 __u8 Name[8]; 1294 1291 struct lease_context lcontext; 1295 1292 } __packed; 1296 1293 1297 1294 struct create_lease_v2 { 1298 - struct create_context ccontext; 1295 + struct create_context_hdr ccontext; 1299 1296 __u8 Name[8]; 1300 1297 struct lease_context_v2 lcontext; 1301 1298 __u8 Pad[4]; ··· 1303 1300 1304 1301 /* See MS-SMB2 2.2.14.2.9 */ 1305 1302 struct create_disk_id_rsp { 1306 - struct create_context ccontext; 1303 + struct create_context_hdr ccontext; 1307 1304 __u8 Name[8]; 1308 1305 __le64 DiskFileId; 1309 1306 __le64 VolumeId; ··· 1312 1309 1313 1310 /* See MS-SMB2 2.2.13.2.13 */ 1314 1311 struct create_app_inst_id { 1315 - struct create_context ccontext; 1312 + struct create_context_hdr ccontext; 1316 1313 __u8 Name[16]; 1317 1314 __le32 StructureSize; /* Must be 20 */ 1318 1315 __u16 Reserved; ··· 1321 1318 1322 1319 /* See MS-SMB2 2.2.13.2.15 */ 1323 1320 struct create_app_inst_id_vers { 1324 - struct create_context ccontext; 1321 + struct create_context_hdr ccontext; 1325 1322 __u8 Name[16]; 1326 1323 __le32 StructureSize; /* Must be 24 */ 1327 1324 __u16 Reserved;
+9 -9
fs/smb/server/smb2pdu.h
··· 64 64 #define SMB2_SESSION_TIMEOUT (10 * HZ) 65 65 66 66 struct create_durable_req_v2 { 67 - struct create_context ccontext; 67 + struct create_context_hdr ccontext; 68 68 __u8 Name[8]; 69 69 __le32 Timeout; 70 70 __le32 Flags; ··· 73 73 } __packed; 74 74 75 75 struct create_durable_reconn_req { 76 - struct create_context ccontext; 76 + struct create_context_hdr ccontext; 77 77 __u8 Name[8]; 78 78 union { 79 79 __u8 Reserved[16]; ··· 85 85 } __packed; 86 86 87 87 struct create_durable_reconn_v2_req { 88 - struct create_context ccontext; 88 + struct create_context_hdr ccontext; 89 89 __u8 Name[8]; 90 90 struct { 91 91 __u64 PersistentFileId; ··· 96 96 } __packed; 97 97 98 98 struct create_alloc_size_req { 99 - struct create_context ccontext; 99 + struct create_context_hdr ccontext; 100 100 __u8 Name[8]; 101 101 __le64 AllocationSize; 102 102 } __packed; 103 103 104 104 struct create_durable_rsp { 105 - struct create_context ccontext; 105 + struct create_context_hdr ccontext; 106 106 __u8 Name[8]; 107 107 union { 108 108 __u8 Reserved[8]; ··· 114 114 /* Flags */ 115 115 #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002 116 116 struct create_durable_v2_rsp { 117 - struct create_context ccontext; 117 + struct create_context_hdr ccontext; 118 118 __u8 Name[8]; 119 119 __le32 Timeout; 120 120 __le32 Flags; ··· 122 122 123 123 /* equivalent of the contents of SMB3.1.1 POSIX open context response */ 124 124 struct create_posix_rsp { 125 - struct create_context ccontext; 125 + struct create_context_hdr ccontext; 126 126 __u8 Name[16]; 127 127 __le32 nlink; 128 128 __le32 reparse_tag; ··· 381 381 } __packed; /* level 15 Query */ 382 382 383 383 struct create_ea_buf_req { 384 - struct create_context ccontext; 384 + struct create_context_hdr ccontext; 385 385 __u8 Name[8]; 386 386 struct smb2_ea_info ea; 387 387 } __packed; 388 388 389 389 struct create_sd_buf_req { 390 - struct create_context ccontext; 390 + struct create_context_hdr ccontext; 391 391 __u8 Name[8]; 392 392 struct smb_ntsd ntsd; 393 393 } __packed;