Skip to content

Commit 00c2cae

Browse files
arndbmartinkpetersen
authored andcommitted
scsi: lpfc: Fix lpfc_name struct packing
clang points out that the lpfc_name structure has an 8-byte alignment requirement on most architectures, but is embedded in a number of other structures that are forced to be only 1-byte aligned: drivers/scsi/lpfc/lpfc_hw.h:1516:30: error: field pe within 'struct lpfc_fdmi_reg_port_list' is less aligned than 'struct lpfc_fdmi_port_entry' and is usually due to 'struct lpfc_fdmi_reg_port_list' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] struct lpfc_fdmi_port_entry pe; drivers/scsi/lpfc/lpfc_hw.h:850:19: error: field portName within 'struct _ADISC' is less aligned than 'struct lpfc_name' and is usually due to 'struct _ADISC' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] drivers/scsi/lpfc/lpfc_hw.h:851:19: error: field nodeName within 'struct _ADISC' is less aligned than 'struct lpfc_name' and is usually due to 'struct _ADISC' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] drivers/scsi/lpfc/lpfc_hw.h:922:19: error: field portName within 'struct _RNID' is less aligned than 'struct lpfc_name' and is usually due to 'struct _RNID' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] drivers/scsi/lpfc/lpfc_hw.h:923:19: error: field nodeName within 'struct _RNID' is less aligned than 'struct lpfc_name' and is usually due to 'struct _RNID' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access] From the git history, I can see that all the __packed annotations were done specifically to avoid introducing implicit padding around the lpfc_name instances, though this was probably the wrong approach. To improve this, only annotate the one uint64_t field inside of lpfc_name as packed, with an explicit 4-byte alignment, as is the default already on the 32-bit x86 ABI but not on most others. With this, the other __packed annotations can be removed again, as this avoids the incorrect padding. Two other structures change their layout as a result of this change: - struct _LOGO never gained a __packed annotation even though it has the same alignment problem as the others but is not used anywhere in the driver today. - struct serv_param similarly has this issue, and it is used, my guess is that this is only an internal structure rather than part of a binary interface, so the padding has no negative effect here. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20230616090705.2623408-1-arnd@kernel.org Reviewed-by: Justin Tee <justin.tee@broadcom.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent af92c02 commit 00c2cae

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/scsi/lpfc/lpfc_hw.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ struct lpfc_name {
365365
uint8_t IEEE[6]; /* FC IEEE address */
366366
} s;
367367
uint8_t wwn[8];
368-
uint64_t name;
368+
uint64_t name __packed __aligned(4);
369369
} u;
370370
};
371371

@@ -850,7 +850,7 @@ typedef struct _ADISC { /* Structure is in Big Endian format */
850850
struct lpfc_name portName;
851851
struct lpfc_name nodeName;
852852
uint32_t DID;
853-
} __packed ADISC;
853+
} ADISC;
854854

855855
typedef struct _FARP { /* Structure is in Big Endian format */
856856
uint32_t Mflags:8;
@@ -880,7 +880,7 @@ typedef struct _FAN { /* Structure is in Big Endian format */
880880
uint32_t Fdid;
881881
struct lpfc_name FportName;
882882
struct lpfc_name FnodeName;
883-
} __packed FAN;
883+
} FAN;
884884

885885
typedef struct _SCR { /* Structure is in Big Endian format */
886886
uint8_t resvd1;
@@ -924,7 +924,7 @@ typedef struct _RNID { /* Structure is in Big Endian format */
924924
union {
925925
RNID_TOP_DISC topologyDisc; /* topology disc (0xdf) */
926926
} un;
927-
} __packed RNID;
927+
} RNID;
928928

929929
struct RLS { /* Structure is in Big Endian format */
930930
uint32_t rls;
@@ -1514,7 +1514,7 @@ struct lpfc_fdmi_hba_ident {
15141514
struct lpfc_fdmi_reg_port_list {
15151515
__be32 EntryCnt;
15161516
struct lpfc_fdmi_port_entry pe;
1517-
} __packed;
1517+
};
15181518

15191519
/*
15201520
* Register HBA(RHBA)

0 commit comments

Comments
 (0)