Re: [PATCH 2/2][next] scsi: lpfc: Use struct_size() helper
From: Kees Cook
Date: Wed May 17 2023 - 19:01:55 EST
On Wed, May 17, 2023 at 03:23:01PM -0600, Gustavo A. R. Silva wrote:
> 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.
>
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx>
> ---
> drivers/scsi/lpfc/lpfc_ct.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
> index e880d127d7f5..3b95c56023bf 100644
> --- a/drivers/scsi/lpfc/lpfc_ct.c
> +++ b/drivers/scsi/lpfc/lpfc_ct.c
> @@ -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...
--
Kees Cook