[PATCH 6.1 162/232] scsi: smartpqi: Replace one-element arrays with flexible-array members

Sasha Levin
2026-02-28T18:13:45Z

From: "Gustavo A. R. Silva" <gustavoars@kernel.org>

[ Upstream commit 6f0a92fd7db1507b203111ee53632eeeba2daca5 ]

One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element arrays with flexible-array
members in a couple of structures, and refactor the rest of the code,
accordingly.

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

This results in no differences in binary output.

Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/204
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/ZJNdKDkuRbFZpASS@work
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Stable-dep-of: 41b37312bd97 ("scsi: smartpqi: Fix memory leak in pqi_report_phys_luns()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/scsi/smartpqi/smartpqi.h | 4 ++--
drivers/scsi/smartpqi/smartpqi_init.c | 5 ++---
2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi.h b/drivers/scsi/smartpqi/smartpqi.h
index 5b40e7ad5e02d..7a5c51cf58005 100644
--- a/drivers/scsi/smartpqi/smartpqi.h
+++ b/drivers/scsi/smartpqi/smartpqi.h
@@ -982,12 +982,12 @@ struct report_phys_lun_16byte_wwid {

struct report_phys_lun_8byte_wwid_list {
struct report_lun_header header;
- struct report_phys_lun_8byte_wwid lun_entries[1];
+ struct report_phys_lun_8byte_wwid lun_entries[];
};

struct report_phys_lun_16byte_wwid_list {
struct report_lun_header header;
- struct report_phys_lun_16byte_wwid lun_entries[1];
+ struct report_phys_lun_16byte_wwid lun_entries[];
};

struct raid_map_disk_data {
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index a9f504959dd56..5c0f23dd808c4 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -1194,7 +1194,6 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b
unsigned int i;
u8 rpl_response_format;
u32 num_physicals;
- size_t rpl_16byte_wwid_list_length;
void *rpl_list;
struct report_lun_header *rpl_header;
struct report_phys_lun_8byte_wwid_list *rpl_8byte_wwid_list;
@@ -1223,9 +1222,9 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b

rpl_8byte_wwid_list = rpl_list;
num_physicals = get_unaligned_be32(&rpl_8byte_wwid_list->header.list_length) / sizeof(rpl_8byte_wwid_list->lun_entries[0]);
- rpl_16byte_wwid_list_length = sizeof(struct report_lun_header) + (num_physicals * sizeof(struct report_phys_lun_16byte_wwid));

- rpl_16byte_wwid_list = kmalloc(rpl_16byte_wwid_list_length, GFP_KERNEL);
+ rpl_16byte_wwid_list = kmalloc(struct_size(rpl_16byte_wwid_list, lun_entries,
+ num_physicals), GFP_KERNEL);
if (!rpl_16byte_wwid_list)
return -ENOMEM;

--
2.51.0