scsi: mpt3sas: Make MPI2_CONFIG_PAGE_RAID_VOL_0::PhysDisk[] a flexible array
authorJames Seo <james@equiv.tech>
Sun, 6 Aug 2023 17:05:55 +0000 (10:05 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 15 Nov 2023 13:52:02 +0000 (08:52 -0500)
This terminal 1-length variable array can be directly converted into a C99
flexible array member.

As all users of MPI2_CONFIG_PAGE_RAID_VOL_0 (Mpi2RaidVolPage0_t) either
calculate its size without depending on its sizeof() or do not use
PhysDisk[], no further source changes are required:

 - mpt3sas_config.c:mpt3sas_config_get_number_pds() fetches a
   Mpi2RaidVolPage0_t for itself, but does not use PhysDisk[].

 - mpt3sas_config.c:mpt3sas_config_get_raid_volume_pg0() fetches a
   Mpi2RaidVolPage0_t into a caller-provided buffer, and may fetch and
   write PhysDisk[] into that buffer depending on its sz argument.  Its
   callers:

   - mpt3sas_scsih.c:scsih_get_resync(),
     mpt3sas_scsih.c:scsih_get_state(),
     mpt3sas_scsih.c:_scsih_search_responding_raid_devices(), and
     mpt3sas_scsih.c:_scsih_scan_for_devices_after_reset() all pass
     sizeof(Mpi2RaidVolPage0_t) as sz, but do not use PhysDisk[].

   - mpt3sas_scsih.c:_scsih_get_volume_capabilities() and
     mpt3sas_warpdrive.c:mpt3sas_init_warpdrive_properties()
     both calculate sz independently of sizeof(Mpi2RaidVolPage0_t)
     and allocate a suitable buffer before calling
     mpt3sas_config_get_raid_volume_pg0() and using PhysDisk[].

Signed-off-by: James Seo <james@equiv.tech>
Link: https://lore.kernel.org/r/20230806170604.16143-4-james@equiv.tech
Tested-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h

index 12b656bd883d0b3957e61f3054e5f119cb8acdb2..55abfc00301e3e8aa5597328a38f78c19084e71d 100644 (file)
@@ -1801,12 +1801,9 @@ typedef struct _MPI2_RAIDVOL0_SETTINGS {
 #define MPI2_RAIDVOL0_SETTING_ENABLE_WRITE_CACHING      (0x0002)
 
 /*
- *Host code (drivers, BIOS, utilities, etc.) should leave this define set to
- *one and check the value returned for NumPhysDisks at runtime.
+ *Host code (drivers, BIOS, utilities, etc.) should check the value returned
+ *for NumPhysDisks at runtime before using PhysDisk[].
  */
-#ifndef MPI2_RAID_VOL_PAGE_0_PHYSDISK_MAX
-#define MPI2_RAID_VOL_PAGE_0_PHYSDISK_MAX       (1)
-#endif
 
 typedef struct _MPI2_CONFIG_PAGE_RAID_VOL_0 {
        MPI2_CONFIG_PAGE_HEADER Header;            /*0x00 */
@@ -1826,8 +1823,7 @@ typedef struct _MPI2_CONFIG_PAGE_RAID_VOL_0 {
        U8                      Reserved2;         /*0x25 */
        U8                      Reserved3;         /*0x26 */
        U8                      InactiveStatus;    /*0x27 */
-       MPI2_RAIDVOL0_PHYS_DISK
-       PhysDisk[MPI2_RAID_VOL_PAGE_0_PHYSDISK_MAX]; /*0x28 */
+       MPI2_RAIDVOL0_PHYS_DISK PhysDisk[];        /*0x28 */
 } MPI2_CONFIG_PAGE_RAID_VOL_0,
        *PTR_MPI2_CONFIG_PAGE_RAID_VOL_0,
        Mpi2RaidVolPage0_t, *pMpi2RaidVolPage0_t;