scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_PD_CFG...
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 15 Aug 2022 21:49:38 +0000 (16:49 -0500)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 1 Sep 2022 03:39:59 +0000 (23:39 -0400)
One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible-array
member in struct MR_PD_CFG_SEQ_NUM_SYNC 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 [0].

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/109
Link: https://reviews.llvm.org/D126864
Link: https://lore.kernel.org/r/78e9261591db072b67fcf49f0216d7046a67ca6d.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
drivers/scsi/megaraid/megaraid_sas_fusion.c
drivers/scsi/megaraid/megaraid_sas_fusion.h

index 43b97376f4e13f8b8ab3c38019c0e7fbb6e9e4e6..59703ef8b1adea0c0c7d9545ee40c689f5d6c0a0 100644 (file)
@@ -5793,7 +5793,7 @@ megasas_setup_jbod_map(struct megasas_instance *instance)
        u32 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 - 1));
+               (sizeof(struct MR_PD_CFG_SEQ) * MAX_PHYSICAL_DEVICES);
 
        instance->use_seqnum_jbod_fp =
                instance->support_seqnum_jbod_fp;
@@ -8046,7 +8046,7 @@ skip_firing_dcmds:
                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 - 1));
+                                       MAX_PHYSICAL_DEVICES);
                for (i = 0; i < 2 ; i++) {
                        if (fusion->ld_map[i])
                                dma_free_coherent(&instance->pdev->dev,
index e48d4261d0bcacf3ed63f46b4815d4b8e050c138..f17ec83f7c98e6dbaa5a8030e98a7df0275d87a6 100644 (file)
@@ -1310,7 +1310,7 @@ megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) {
 
        pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)];
        pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)];
-       pd_seq_map_sz = struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES - 1);
+       pd_seq_map_sz = struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES);
 
        cmd = megasas_get_cmd(instance);
        if (!cmd) {
index df92d4369e044a8438390517e297a982c7a27d53..49e9a9048ee7ec18152e1bf4da60c9f48a733815 100644 (file)
@@ -1249,7 +1249,7 @@ struct MR_PD_CFG_SEQ {
 struct MR_PD_CFG_SEQ_NUM_SYNC {
        __le32 size;
        __le32 count;
-       struct MR_PD_CFG_SEQ seq[1];
+       struct MR_PD_CFG_SEQ seq[];
 } __packed;
 
 /* stream detection */