Skip to content

Commit 44b6169

Browse files
GustavoARSilvamartinkpetersen
authored andcommitted
scsi: fc: Avoid -Wflex-array-member-not-at-end warnings
-Wflex-array-member-not-at-end has been introduced 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 create a new tagged 'struct fc_df_desc_fpin_reg_hdr'. This structure groups together all the members of the flexible 'struct fc_df_desc_fpin_reg' except the flexible array. As a result, the array is effectively separated from the rest of the members without modifying the memory layout of the flexible structure. We then change the type of the middle struct members currently causing trouble from 'struct fc_df_desc_fpin_reg' to 'struct fc_df_desc_fpin_reg_hdr'. We also want to ensure that in case new members need to be added to the flexible structure, they are always included within the newly created tagged struct. 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. This approach avoids having to implement 'struct fc_df_desc_fpin_reg_hdr' as a completely separate structure, thus preventing having to maintain two independent but basically identical structures, closing the door to potential bugs in the future. The above is also done for flexible structures 'struct fc_els_rdf' and 'struct fc_els_rdf_resp' So, with these changes, fix the following warnings: drivers/scsi/lpfc/lpfc_hw4.h:4936:41: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/scsi/lpfc/lpfc_hw4.h:4942:41: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/scsi/lpfc/lpfc_hw4.h:4947:41: 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> Link: https://lore.kernel.org/r/aK6hbQLyQlvlySf8@kspp Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Justin Tee <justin.tee@broadcom.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent bee3554 commit 44b6169

3 files changed

Lines changed: 43 additions & 23 deletions

File tree

drivers/scsi/lpfc/lpfc_els.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,7 @@ lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
37623762
memset(prdf, 0, cmdsize);
37633763
prdf->rdf.fpin_cmd = ELS_RDF;
37643764
prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3765-
sizeof(struct fc_els_rdf));
3765+
sizeof(struct fc_els_rdf_hdr));
37663766
prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
37673767
prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
37683768
FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));

drivers/scsi/lpfc/lpfc_hw4.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4909,18 +4909,18 @@ struct send_frame_wqe {
49094909

49104910
#define ELS_RDF_REG_TAG_CNT 4
49114911
struct lpfc_els_rdf_reg_desc {
4912-
struct fc_df_desc_fpin_reg reg_desc; /* descriptor header */
4912+
struct fc_df_desc_fpin_reg_hdr reg_desc; /* descriptor header */
49134913
__be32 desc_tags[ELS_RDF_REG_TAG_CNT];
49144914
/* tags in reg_desc */
49154915
};
49164916

49174917
struct lpfc_els_rdf_req {
4918-
struct fc_els_rdf rdf; /* hdr up to descriptors */
4918+
struct fc_els_rdf_hdr rdf; /* hdr up to descriptors */
49194919
struct lpfc_els_rdf_reg_desc reg_d1; /* 1st descriptor */
49204920
};
49214921

49224922
struct lpfc_els_rdf_rsp {
4923-
struct fc_els_rdf_resp rdf_resp; /* hdr up to descriptors */
4923+
struct fc_els_rdf_resp_hdr rdf_resp; /* hdr up to descriptors */
49244924
struct lpfc_els_rdf_reg_desc reg_d1; /* 1st descriptor */
49254925
};
49264926

include/uapi/scsi/fc/fc_els.h

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include <linux/types.h>
1212
#include <asm/byteorder.h>
1313

14+
#ifdef __KERNEL__
15+
#include <linux/stddef.h> /* for offsetof */
16+
#else
17+
#include <stddef.h> /* for offsetof */
18+
#endif
19+
1420
/*
1521
* Fibre Channel Switch - Enhanced Link Services definitions.
1622
* From T11 FC-LS Rev 1.2 June 7, 2005.
@@ -1109,12 +1115,15 @@ struct fc_els_fpin {
11091115

11101116
/* Diagnostic Function Descriptor - FPIN Registration */
11111117
struct fc_df_desc_fpin_reg {
1112-
__be32 desc_tag; /* FPIN Registration (0x00030001) */
1113-
__be32 desc_len; /* Length of Descriptor (in bytes).
1114-
* Size of descriptor excluding
1115-
* desc_tag and desc_len fields.
1116-
*/
1117-
__be32 count; /* Number of desc_tags elements */
1118+
/* New members MUST be added within the __struct_group() macro below. */
1119+
__struct_group(fc_df_desc_fpin_reg_hdr, __hdr, /* no attrs */,
1120+
__be32 desc_tag; /* FPIN Registration (0x00030001) */
1121+
__be32 desc_len; /* Length of Descriptor (in bytes).
1122+
* Size of descriptor excluding
1123+
* desc_tag and desc_len fields.
1124+
*/
1125+
__be32 count; /* Number of desc_tags elements */
1126+
);
11181127
__be32 desc_tags[]; /* Array of Descriptor Tags.
11191128
* Each tag indicates a function
11201129
* supported by the N_Port (request)
@@ -1124,33 +1133,44 @@ struct fc_df_desc_fpin_reg {
11241133
* See ELS_FN_DTAG_xxx for tag values.
11251134
*/
11261135
};
1136+
_Static_assert(offsetof(struct fc_df_desc_fpin_reg, desc_tags) == sizeof(struct fc_df_desc_fpin_reg_hdr),
1137+
"struct member likely outside of __struct_group()");
11271138

11281139
/*
11291140
* ELS_RDF - Register Diagnostic Functions
11301141
*/
11311142
struct fc_els_rdf {
1132-
__u8 fpin_cmd; /* command (0x19) */
1133-
__u8 fpin_zero[3]; /* specified as zero - part of cmd */
1134-
__be32 desc_len; /* Length of Descriptor List (in bytes).
1135-
* Size of ELS excluding fpin_cmd,
1136-
* fpin_zero and desc_len fields.
1137-
*/
1143+
/* New members MUST be added within the __struct_group() macro below. */
1144+
__struct_group(fc_els_rdf_hdr, __hdr, /* no attrs */,
1145+
__u8 fpin_cmd; /* command (0x19) */
1146+
__u8 fpin_zero[3]; /* specified as zero - part of cmd */
1147+
__be32 desc_len; /* Length of Descriptor List (in bytes).
1148+
* Size of ELS excluding fpin_cmd,
1149+
* fpin_zero and desc_len fields.
1150+
*/
1151+
);
11381152
struct fc_tlv_desc desc[]; /* Descriptor list */
11391153
};
1154+
_Static_assert(offsetof(struct fc_els_rdf, desc) == sizeof(struct fc_els_rdf_hdr),
1155+
"struct member likely outside of __struct_group()");
11401156

11411157
/*
11421158
* ELS RDF LS_ACC Response.
11431159
*/
11441160
struct fc_els_rdf_resp {
1145-
struct fc_els_ls_acc acc_hdr;
1146-
__be32 desc_list_len; /* Length of response (in
1147-
* bytes). Excludes acc_hdr
1148-
* and desc_list_len fields.
1149-
*/
1150-
struct fc_els_lsri_desc lsri;
1161+
/* New members MUST be added within the __struct_group() macro below. */
1162+
__struct_group(fc_els_rdf_resp_hdr, __hdr, /* no attrs */,
1163+
struct fc_els_ls_acc acc_hdr;
1164+
__be32 desc_list_len; /* Length of response (in
1165+
* bytes). Excludes acc_hdr
1166+
* and desc_list_len fields.
1167+
*/
1168+
struct fc_els_lsri_desc lsri;
1169+
);
11511170
struct fc_tlv_desc desc[]; /* Supported Descriptor list */
11521171
};
1153-
1172+
_Static_assert(offsetof(struct fc_els_rdf_resp, desc) == sizeof(struct fc_els_rdf_resp_hdr),
1173+
"struct member likely outside of __struct_group()");
11541174

11551175
/*
11561176
* Diagnostic Capability Descriptors for EDC ELS

0 commit comments

Comments
 (0)