Skip to contentSkip to conversation

scsi: smartpqi: Replace one-element array with flexible-array member

PATCH Superseded Gustavo A. R. Silva 1 participant 1 message Feb 7, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: smartpqi: Replace one-element array with flexible-array member

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 report_log_lun_list.

This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy().

---
Changes in v2:
In v1 we thought that the original code was allocating one too-many entries for the list. However, Don Brance commented that the allocation was actually intentional[1]. So, I added a code comment with his feedback.

v1:

 drivers/scsi/smartpqi/smartpqi.h      | 2 +-
 drivers/scsi/smartpqi/smartpqi_init.c | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi.h +1 -1
index af27bb0f3133..228838eb3686 100644
@@ -954,7 +954,7 @@ struct report_log_lun {
 
 struct report_log_lun_list {
 	struct report_lun_header header;
-	struct report_log_lun lun_entries[1];
+	struct report_log_lun lun_entries[];
 };
 
 struct report_phys_lun_8byte_wwid {
drivers/scsi/smartpqi/smartpqi_init.c +4 -0
index d0446d4d4465..af8f1a8e9f8f 100644
@@ -1277,6 +1277,10 @@ static int pqi_get_device_lists(struct pqi_ctrl_info *ctrl_info,
 	logdev_data_length = sizeof(struct report_lun_header) +
 		logdev_list_length;
 
+	/*
+	 * Notice that we take on an extra list entry (struct report_log_lun)
+	 * that is all zeros for the controller itself.
+	 */
 	internal_logdev_list = kmalloc(logdev_data_length +
 		sizeof(struct report_log_lun), GFP_KERNEL);
 	if (!internal_logdev_list) {
Signature · 1 line
2.34.1