Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: smartpqi: Replace one-element arrays with flexible-array members

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>

authored by

Gustavo A. R. Silva and committed by
Martin K. Petersen
6f0a92fd 4b2e2875

+4 -5
+2 -2
drivers/scsi/smartpqi/smartpqi.h
··· 982 982 983 983 struct report_phys_lun_8byte_wwid_list { 984 984 struct report_lun_header header; 985 - struct report_phys_lun_8byte_wwid lun_entries[1]; 985 + struct report_phys_lun_8byte_wwid lun_entries[]; 986 986 }; 987 987 988 988 struct report_phys_lun_16byte_wwid_list { 989 989 struct report_lun_header header; 990 - struct report_phys_lun_16byte_wwid lun_entries[1]; 990 + struct report_phys_lun_16byte_wwid lun_entries[]; 991 991 }; 992 992 993 993 struct raid_map_disk_data {
+2 -3
drivers/scsi/smartpqi/smartpqi_init.c
··· 1203 1203 unsigned int i; 1204 1204 u8 rpl_response_format; 1205 1205 u32 num_physicals; 1206 - size_t rpl_16byte_wwid_list_length; 1207 1206 void *rpl_list; 1208 1207 struct report_lun_header *rpl_header; 1209 1208 struct report_phys_lun_8byte_wwid_list *rpl_8byte_wwid_list; ··· 1231 1232 1232 1233 rpl_8byte_wwid_list = rpl_list; 1233 1234 num_physicals = get_unaligned_be32(&rpl_8byte_wwid_list->header.list_length) / sizeof(rpl_8byte_wwid_list->lun_entries[0]); 1234 - rpl_16byte_wwid_list_length = sizeof(struct report_lun_header) + (num_physicals * sizeof(struct report_phys_lun_16byte_wwid)); 1235 1235 1236 - rpl_16byte_wwid_list = kmalloc(rpl_16byte_wwid_list_length, GFP_KERNEL); 1236 + rpl_16byte_wwid_list = kmalloc(struct_size(rpl_16byte_wwid_list, lun_entries, 1237 + num_physicals), GFP_KERNEL); 1237 1238 if (!rpl_16byte_wwid_list) 1238 1239 return -ENOMEM; 1239 1240