scsi: mptlan: Replace one-element array with flexible-array member
Subsystems (2)
PATCH 1/1 scsi: mptlan: Replace one-element array with flexible-array member
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Refactor the code according to the use of a flexible-array member in struct _SGE_TRANSACTION32 instead of one-element array.
Also, this helps with the ongoing efforts to enable -Warray-bounds by fixing the following warning:
CC [M] drivers/message/fusion/mptlan.odrivers/message/fusion/mptlan.c: In function ‘mpt_lan_sdu_send’:drivers/message/fusion/mptlan.c:759:28: warning: array subscript 1 is above array bounds of ‘U32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
759 | pTrans->TransactionDetails[1] = cpu_to_le32((mac[2] << 24) |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/message/fusion/lsi/mpi.h | 4 ++-- drivers/message/fusion/mptlan.c | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-)
drivers/message/fusion/lsi/mpi.h +2 -2
@@ -424,8 +424,8 @@ typedef struct _SGE_TRANSACTION32U8 ContextSize;U8 DetailsLength;U8 Flags; -U32 TransactionContext[1 ]; -U32 TransactionDetails[1 ]; +U32 TransactionContext; +U32 TransactionDetails[]; } SGE_TRANSACTION32, MPI_POINTER PTR_SGE_TRANSACTION32, SGETransaction32_t, MPI_POINTER pSGETransaction32_t;
drivers/message/fusion/mptlan.c +3 -6
@@ -72,9 +72,6 @@ MODULE_VERSION(my_VERSION);#define MPT_LAN_RECEIVE_POST_REQUEST_SIZE \ (sizeof(LANReceivePostRequest_t) - sizeof(SGE_MPI_UNION)) -#define MPT_LAN_TRANSACTION32_SIZE \ - (sizeof(SGETransaction32_t) - sizeof(u32)) -/* * Fusion MPT LAN private structures */
@@ -745,7 +742,7 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device *dev) pTrans->ContextSize =sizeof (u32); pTrans->DetailsLength =2 *sizeof (u32); pTrans->Flags =0 ; - pTrans->TransactionContext[0 ] =cpu_to_le32 (ctx); + pTrans->TransactionContext =cpu_to_le32 (ctx);// dioprintk((KERN_INFO MYNAM ": %s/%s: BC = %08x, skb = %p, buff = %p\n", // IOC_AND_NETDEV_NAMES_s_s(dev),
@@ -1159,7 +1156,7 @@ mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv) __func__, buckets, curr)); max = (mpt_dev->req_sz -MPT_LAN_RECEIVE_POST_REQUEST_SIZE ) / - (MPT_LAN_TRANSACTION32_SIZE +sizeof (SGESimple64_t)); + (sizeof (SGETransaction32_t) +sizeof (SGESimple64_t));while (buckets) { mf =mpt_get_msg_frame (LanCtx, mpt_dev);
@@ -1234,7 +1231,7 @@ mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv) pTrans->ContextSize =sizeof (u32); pTrans->DetailsLength =0 ; pTrans->Flags =0 ; - pTrans->TransactionContext[0 ] =cpu_to_le32 (ctx); + pTrans->TransactionContext =cpu_to_le32 (ctx); pSimple = (SGESimple64_t *) pTrans->TransactionDetails;
Signature · 1 line
2.27.0
Martin K. Petersen
AppliedQuoted 9 lines · Gustavo A. R. Silva
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Refactor the code according to the use of a flexible-array member in struct
_SGE_TRANSACTION32instead of one-element array.[...]
Applied to 5.13/scsi-queue, thanks!
[1/1] scsi: mptlan: Replace one-element array with flexible-array member
https://git.kernel.org/mkp/scsi/c/4e2e619f3c9e
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Hi Martin,
Quoted 10 lines · Martin K. Petersen
Quoted 8 lines · Gustavo A. R. Silva
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Refactor the code according to the use of a flexible-array member in struct
_SGE_TRANSACTION32instead of one-element array.
Quoted 7 lines
Quoted 1 line
[...]
Applied to 5.13/scsi-queue, thanks!
[1/1] scsi: mptlan: Replace one-element array with flexible-array member
https://git.kernel.org/mkp/scsi/c/4e2e619f3c9e
Thanks for this.
Could you apply this one, too:
https://lore.kernel.org/lkml/20210304203822.GA102218@embeddedor/
This was my last reply to the thread:
https://lore.kernel.org/lkml/[email protected]/
Thanks!
--
Gustavo