diff mbox series

[3/4,next] scsi: megaraid_sas: Replace one-element array with flexible-array member in MR_DRV_RAID_MAP

Message ID e1ac01250cd344e8f1627357bb445f1d0dedd6ed.1628135423.git.gustavoars@kernel.org (mailing list archive)
State New, archived
Headers show
Series Replace one-element arrays with flexible-array members | expand

Commit Message

Gustavo A. R. Silva Aug. 5, 2021, 4 a.m. UTC
Replace one-element array with a flexible-array member in struct
MR_DRV_RAID_MAP and use the flex_array_size() helper.

This helps with the ongoing efforts to globally enable -Warray-bounds
and get us closer to being able to tighten the FORTIFY_SOURCE routines
on memcpy().

[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/109
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/scsi/megaraid/megaraid_sas_fp.c     | 6 +++---
 drivers/scsi/megaraid/megaraid_sas_fusion.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index da1cad1ee123..9cb36ef96c2c 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -229,8 +229,8 @@  static int MR_PopulateDrvRaidMap(struct megasas_instance *instance, u64 map_id)
 					le32_to_cpu(desc_table->raid_map_desc_offset));
 				memcpy(pDrvRaidMap->ldSpanMap,
 				       fw_map_dyn->ld_span_map,
-				       sizeof(struct MR_LD_SPAN_MAP) *
-				       le32_to_cpu(desc_table->raid_map_desc_elements));
+				       flex_array_size(pDrvRaidMap, ldSpanMap,
+				       le32_to_cpu(desc_table->raid_map_desc_elements)));
 			break;
 			default:
 				dev_dbg(&instance->pdev->dev, "wrong number of desctableElements %d\n",
@@ -254,7 +254,7 @@  static int MR_PopulateDrvRaidMap(struct megasas_instance *instance, u64 map_id)
 			pDrvRaidMap->ldTgtIdToLd[i] =
 				(u16)fw_map_ext->ldTgtIdToLd[i];
 		memcpy(pDrvRaidMap->ldSpanMap, fw_map_ext->ldSpanMap,
-		       sizeof(struct MR_LD_SPAN_MAP) * ld_count);
+		       flex_array_size(pDrvRaidMap, ldSpanMap, ld_count));
 		memcpy(pDrvRaidMap->arMapInfo, fw_map_ext->arMapInfo,
 		       sizeof(struct MR_ARRAY_INFO) * MAX_API_ARRAYS_EXT);
 		memcpy(pDrvRaidMap->devHndlInfo, fw_map_ext->devHndlInfo,
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 8b08445f575e..d60137eb519c 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -1182,7 +1182,7 @@  struct MR_DRV_RAID_MAP {
 		devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES_DYN];
 	u16 ldTgtIdToLd[MAX_LOGICAL_DRIVES_DYN];
 	struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_DYN];
-	struct MR_LD_SPAN_MAP      ldSpanMap[1];
+	struct MR_LD_SPAN_MAP      ldSpanMap[];
 
 };