diff mbox series

[v2,04/12] scsi: mpt3sas: Make MPI2_CONFIG_PAGE_SASIOUNIT_0::PhyData[] a flexible array

Message ID 20230806170604.16143-5-james@equiv.tech
State New
Headers show
Series scsi: mpt3sas: Use flexible arrays and do a few cleanups | expand

Commit Message

James Seo Aug. 6, 2023, 5:05 p.m. UTC
This terminal 1-length variable array can be directly converted into
a C99 flexible array member.

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

- mpt3sas_config.c:mpt3sas_config_get_number_hba_phys() fetches a
  Mpi2SasIOUnitPage0_t for itself, but does not use PhyData[].

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

  - mpt3sas_scsih.c:_scsih_update_vphys_after_reset(),
    mpt3sas_scsih.c:_scsih_get_port_table_after_reset(),
    mpt3sas_scsih.c:_scsih_sas_host_refresh(),
    mpt3sas_scsih.c:_scsih_sas_host_add(), and
    mpt3sas_transport.c:_transport_phy_enable() all calculate sz
    independently of sizeof(Mpi2SasIOUnitPage0_t) and allocate a
    suitable buffer before calling mpt3sas_config_get_sas_iounit_pg0()
    and using PhyData[].

Signed-off-by: James Seo <james@equiv.tech>
---
 drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h b/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h
index 55abfc00301e..07a8d7646b6d 100644
--- a/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h
+++ b/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h
@@ -2178,12 +2178,9 @@  typedef struct _MPI2_SAS_IO_UNIT0_PHY_DATA {
 	*pMpi2SasIOUnit0PhyData_t;
 
 /*
- *Host code (drivers, BIOS, utilities, etc.) should leave this define set to
- *one and check the value returned for NumPhys at runtime.
+ *Host code (drivers, BIOS, utilities, etc.) should check the value returned
+ *for NumPhys at runtime before using PhyData[].
  */
-#ifndef MPI2_SAS_IOUNIT0_PHY_MAX
-#define MPI2_SAS_IOUNIT0_PHY_MAX        (1)
-#endif
 
 typedef struct _MPI2_CONFIG_PAGE_SASIOUNIT_0 {
 	MPI2_CONFIG_EXTENDED_PAGE_HEADER    Header;   /*0x00 */
@@ -2191,8 +2188,7 @@  typedef struct _MPI2_CONFIG_PAGE_SASIOUNIT_0 {
 	U8                                  NumPhys;  /*0x0C */
 	U8                                  Reserved2;/*0x0D */
 	U16                                 Reserved3;/*0x0E */
-	MPI2_SAS_IO_UNIT0_PHY_DATA
-		PhyData[MPI2_SAS_IOUNIT0_PHY_MAX];    /*0x10 */
+	MPI2_SAS_IO_UNIT0_PHY_DATA          PhyData[];/*0x10 */
 } MPI2_CONFIG_PAGE_SASIOUNIT_0,
 	*PTR_MPI2_CONFIG_PAGE_SASIOUNIT_0,
 	Mpi2SasIOUnitPage0_t, *pMpi2SasIOUnitPage0_t;