scsi: megaraid_sas: Use struct_size() in code related to struct MR_PD_CFG_SEQ_NUM_SYNC
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 15 Aug 2022 21:52:33 +0000 (16:52 -0500)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 1 Sep 2022 03:39:59 +0000 (23:39 -0400)
Prefer struct_size() over open-coded versions of idiom:

        sizeof(struct-with-flex-array) + sizeof(type-of-flex-array) * count

where count is the max number of items the flexible array is supposed to
have.

Link: https://github.com/KSPP/linux/issues/160
Link: https://lore.kernel.org/r/b215f4760f0e8fbe5fc35be20f2487e89924424d.1660592640.git.gustavoars@kernel.org
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/megaraid/megaraid_sas_base.c

index 656b7a7c04d769716b33de4c2796c67b9c3ce645..ae6b9a570fa923831dedb5ec3174d2c2fc7695ef 100644 (file)
@@ -5790,10 +5790,10 @@ megasas_setup_jbod_map(struct megasas_instance *instance)
 {
        int i;
        struct fusion_context *fusion = instance->ctrl_context;
-       u32 pd_seq_map_sz;
+       size_t pd_seq_map_sz;
 
-       pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) +
-               (sizeof(struct MR_PD_CFG_SEQ) * MAX_PHYSICAL_DEVICES);
+       pd_seq_map_sz = struct_size((struct MR_PD_CFG_SEQ_NUM_SYNC *)0, seq,
+                                   MAX_PHYSICAL_DEVICES);
 
        instance->use_seqnum_jbod_fp =
                instance->support_seqnum_jbod_fp;
@@ -7972,7 +7972,7 @@ static void megasas_detach_one(struct pci_dev *pdev)
        struct Scsi_Host *host;
        struct megasas_instance *instance;
        struct fusion_context *fusion;
-       u32 pd_seq_map_sz;
+       size_t pd_seq_map_sz;
 
        instance = pci_get_drvdata(pdev);
 
@@ -8044,9 +8044,9 @@ skip_firing_dcmds:
 
        if (instance->adapter_type != MFI_SERIES) {
                megasas_release_fusion(instance);
-               pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) +
-                               (sizeof(struct MR_PD_CFG_SEQ) *
-                                       MAX_PHYSICAL_DEVICES);
+               pd_seq_map_sz =
+                       struct_size((struct MR_PD_CFG_SEQ_NUM_SYNC *)0,
+                                   seq, MAX_PHYSICAL_DEVICES);
                for (i = 0; i < 2 ; i++) {
                        if (fusion->ld_map[i])
                                dma_free_coherent(&instance->pdev->dev,