scsi: lpfc: Replace one-element array with flexible-array member
Subsystems (2)
cover scsi: lpfc: Replace one-element array with flexible-array member
Hi!
This small series aims to replace a one-element array with a flexible-array member in a couple of structures.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Gustavo A. R. Silva (2):
scsi: lpfc: Replace one-element array with flexible-array member
scsi: lpfc: Use struct_size() helper
drivers/scsi/lpfc/lpfc_ct.c | 4 ++-- drivers/scsi/lpfc/lpfc_hw.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 scsi: lpfc: Replace one-element array with flexible-array member
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array members in a couple of structures, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
This results in no differences in binary output.
--- drivers/scsi/lpfc/lpfc_ct.c | 6 ++++-- drivers/scsi/lpfc/lpfc_hw.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/scsi/lpfc/lpfc_ct.c +4 -2
@@ -3748,7 +3748,8 @@ lpfc_vmid_cmd(struct lpfc_vport *vport, rap->obj[0 ].entity_id_len = vmid->vmid_len;memcpy (rap->obj[0 ].entity_id, vmid->host_vmid, vmid->vmid_len); size =RAPP_IDENT_OFFSET + -sizeof (struct lpfc_vmid_rapp_ident_list ); +sizeof (struct lpfc_vmid_rapp_ident_list ) + +sizeof (struct entity_id_object ); retry =1 ;break ;
@@ -3767,7 +3768,8 @@ lpfc_vmid_cmd(struct lpfc_vport *vport, dap->obj[0 ].entity_id_len = vmid->vmid_len;memcpy (dap->obj[0 ].entity_id, vmid->host_vmid, vmid->vmid_len); size =DAPP_IDENT_OFFSET + -sizeof (struct lpfc_vmid_dapp_ident_list ); +sizeof (struct lpfc_vmid_dapp_ident_list ) + +sizeof (struct entity_id_object );write_lock (&vport->vmid_lock); vmid->flag &= ~LPFC_VMID_REGISTERED ;write_unlock (&vport->vmid_lock);
drivers/scsi/lpfc/lpfc_hw.h +2 -2
@@ -1415,12 +1415,12 @@ struct app_id_object {struct lpfc_vmid_rapp_ident_list {uint32_t no_of_objects; -struct entity_id_object obj[1 ]; +struct entity_id_object obj[]; };struct lpfc_vmid_dapp_ident_list {uint32_t no_of_objects; -struct entity_id_object obj[1 ]; +struct entity_id_object obj[]; };#define GALLAPPIA_ID_LAST 0x80
Signature · 1 line
2.34.1
PATCH 2/2 scsi: lpfc: Use struct_size() helper
In reply to Gustavo A. R. SilvaPrefer struct_size() over open-coded versions of idiom:
sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
where count is the max number of items the flexible array is supposed to contain.
--- drivers/scsi/lpfc/lpfc_ct.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/lpfc/lpfc_ct.c +2 -4
@@ -3748,8 +3748,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport, rap->obj[0 ].entity_id_len = vmid->vmid_len;memcpy (rap->obj[0 ].entity_id, vmid->host_vmid, vmid->vmid_len); size =RAPP_IDENT_OFFSET + -sizeof (struct lpfc_vmid_rapp_ident_list ) + -sizeof (struct entity_id_object ); +struct_size (rap, obj, rap->no_of_objects); retry =1 ;break ;
@@ -3768,8 +3767,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport, dap->obj[0 ].entity_id_len = vmid->vmid_len;memcpy (dap->obj[0 ].entity_id, vmid->host_vmid, vmid->vmid_len); size =DAPP_IDENT_OFFSET + -sizeof (struct lpfc_vmid_dapp_ident_list ) + -sizeof (struct entity_id_object ); +struct_size (dap, obj, dap->no_of_objects);write_lock (&vport->vmid_lock); vmid->flag &= ~LPFC_VMID_REGISTERED ;write_unlock (&vport->vmid_lock);
Signature · 1 line
2.34.1
Re: [PATCH 2/2][next] scsi: lpfc: Use struct_size() helper
Quoted 18 lines · Gustavo A. R. Silva
Prefer
struct_size()over open-coded versions of idiom:sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
where count is the max number of items the flexible array is supposed to contain.
--- drivers/scsi/lpfc/lpfc_ct.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/scsi/lpfc/lpfc_ct.c +0
-0
drivers/scsi/lpfc/lpfc_ct.c lpfc_vmid_cmd(struct lpfc_vport *vport, · line 3751
Quoted 6 lines
drivers/scsi/lpfc/lpfc_ct.c +1
-2@@ -3748,8 +3748,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport, rap->obj[0 ].entity_id_len = vmid->vmid_len;memcpy (rap->obj[0 ].entity_id, vmid->host_vmid, vmid->vmid_len); size =RAPP_IDENT_OFFSET + -sizeof (struct lpfc_vmid_rapp_ident_list ) + -sizeof (struct entity_id_object ); +struct_size (rap, obj, rap->no_of_objects);
Has rap->no_of_objects always been "1"? (i.e. there was a prior multiplication here before...
Signature · 1 line
Kees Cook
Quoted 9 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array members in a couple of structures, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Quoted 6 lines
This results in no differences in binary output.
Signature · 1 line
Kees Cook
Martin K. Petersen
AppliedGustavo,
Quoted 10 lines
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array members in a couple of structures, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].This results in no differences in binary output.
Applied to 6.5/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 2 lines · Martin K. Petersen
Applied to 6.5/scsi-staging, thanks!
Thanks, Martin.
--
Gustavo
Re: [PATCH 2/2][next] scsi: lpfc: Use struct_size() helper
In reply to Kees CookQuoted 14 lines · Kees Cook
Quoted 13 lines · Gustavo A. R. Silva
Prefer
struct_size()over open-coded versions of idiom:sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
where count is the max number of items the flexible array is supposed to contain.
--- drivers/scsi/lpfc/lpfc_ct.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Quoted 14 lines
drivers/scsi/lpfc/lpfc_ct.c lpfc_vmid_cmd(struct lpfc_vport *vport, · line 3751
Quoted 11 lines
drivers/scsi/lpfc/lpfc_ct.c +1
-2@@ -3748,8 +3748,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport, rap->obj[0 ].entity_id_len = vmid->vmid_len;memcpy (rap->obj[0 ].entity_id, vmid->host_vmid, vmid->vmid_len); size =RAPP_IDENT_OFFSET + -sizeof (struct lpfc_vmid_rapp_ident_list ) + -sizeof (struct entity_id_object ); +struct_size (rap, obj, rap->no_of_objects);Has
rap->no_of_objectsalways been "1"? (i.e. there was a prior multiplication here before...
Mmh.. not sure what multiplication you are talking about. I based these changes on the fact that rap->no_of_objects is set to cpu_to_be32(1); for both instances. It doesn't show up in the context of the patch, so here you go:
3747 rap->no_of_objects = cpu_to_be32(1); 3748 rap->obj[0].entity_id_len = vmid->vmid_len; 3749 memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len); 3750 size = RAPP_IDENT_OFFSET +
3751 sizeof(struct lpfc_vmid_rapp_ident_list) +
3752 sizeof(struct entity_id_object);
--
Gustavo
Re: [PATCH 2/2][next] scsi: lpfc: Use struct_size() helper
Quoted 30 lines · Gustavo A. R. Silva
Quoted 14 lines · Kees Cook
Quoted 13 lines · Gustavo A. R. Silva
Prefer
struct_size()over open-coded versions of idiom:sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
where count is the max number of items the flexible array is supposed to contain.
--- drivers/scsi/lpfc/lpfc_ct.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)Quoted 14 lines
drivers/scsi/lpfc/lpfc_ct.c lpfc_vmid_cmd(struct lpfc_vport *vport, · line 3751
Quoted 11 lines
drivers/scsi/lpfc/lpfc_ct.c +1
-2@@ -3748,8 +3748,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport, rap->obj[0 ].entity_id_len = vmid->vmid_len;memcpy (rap->obj[0 ].entity_id, vmid->host_vmid, vmid->vmid_len); size =RAPP_IDENT_OFFSET + -sizeof (struct lpfc_vmid_rapp_ident_list ) + -sizeof (struct entity_id_object ); +struct_size (rap, obj, rap->no_of_objects);Has
rap->no_of_objectsalways been "1"? (i.e. there was a prior multiplication here before...
Quoted 6 lines
Mmh.. not sure what multiplication you are talking about. I based these changes on the fact that
rap->no_of_objectsis set tocpu_to_be32(1); for both instances. It doesn't show up in the context of the patch, so here you go:3747
rap->no_of_objects=cpu_to_be32(1);
Ah-ha! So, yeah, this patch is bad then, since no_of_objects will be a big-endian "1".
This change:
+ struct_size(rap, obj, rap->no_of_objects);
needs to explicitly be:
+ struct_size(rap, obj, 1);
Or, alternatively, just drop the patch entirely.
Signature · 1 line
Kees Cook
Quoted 8 lines · Martin K. Petersen
Gustavo,
Quoted 5 lines
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array members in a couple of structures, and refactor the rest of the code, accordingly.
Quoted 7 lines
Quoted 5 lines
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].This results in no differences in binary output.
Applied to 6.5/scsi-staging, thanks!
Martin, I think this patch is not right -- can you drop this from staging for the moment?
Signature · 1 line
Kees Cook
Quoted 13 lines · Kees Cook
Quoted 12 lines · Martin K. Petersen
Gustavo,
Quoted 9 lines
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array members in a couple of structures, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
This results in no differences in binary output.
Applied to 6.5/scsi-staging, thanks!
Martin, I think this patch is not right -- can you drop this from staging for the moment?
Martin just took patch 1/2, which is correct:
--
Gustavo
Quoted 18 lines · Gustavo A. R. Silva
Quoted 15 lines · Kees Cook
Quoted 14 lines · Martin K. Petersen
Gustavo,
Quoted 10 lines
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array members in a couple of structures, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].This results in no differences in binary output.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Applied to 6.5/scsi-staging, thanks!
Martin, I think this patch is not right -- can you drop this from staging for the moment?
Martin just took patch 1/2, which is correct:
Oops, yes, I thought both got pulled. 1/2 is fine. :)
-Kees
Signature · 1 line
Kees Cook
Martin K. Petersen
AppliedQuoted 8 lines · Gustavo A. R. Silva
This small series aims to replace a one-element array with a flexible-array member in a couple of structures.
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].[...]
Applied to 6.5/scsi-queue, thanks!
[1/2] scsi: lpfc: Replace one-element array with flexible-array member
https://git.kernel.org/mkp/scsi/c/e90644b0ce2d
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering