Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: lpfc: Use struct_size() helper

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
Co-developed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20230531223319.24328-1-justintee8345@gmail.com
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Justin Tee and committed by
Martin K. Petersen
bb26224e 9c24f90f

+2 -4
+2 -4
drivers/scsi/lpfc/lpfc_ct.c
··· 3748 3748 rap->obj[0].entity_id_len = vmid->vmid_len; 3749 3749 memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len); 3750 3750 size = RAPP_IDENT_OFFSET + 3751 - sizeof(struct lpfc_vmid_rapp_ident_list) + 3752 - sizeof(struct entity_id_object); 3751 + struct_size(rap, obj, be32_to_cpu(rap->no_of_objects)); 3753 3752 retry = 1; 3754 3753 break; 3755 3754 ··· 3767 3768 dap->obj[0].entity_id_len = vmid->vmid_len; 3768 3769 memcpy(dap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len); 3769 3770 size = DAPP_IDENT_OFFSET + 3770 - sizeof(struct lpfc_vmid_dapp_ident_list) + 3771 - sizeof(struct entity_id_object); 3771 + struct_size(dap, obj, be32_to_cpu(dap->no_of_objects)); 3772 3772 write_lock(&vport->vmid_lock); 3773 3773 vmid->flag &= ~LPFC_VMID_REGISTERED; 3774 3774 write_unlock(&vport->vmid_lock);