diff mbox series

scsi: mpt3sas: fix compilation warnings

Message ID 20220609023830.442213-1-damien.lemoal@opensource.wdc.com
State New
Headers show
Series scsi: mpt3sas: fix compilation warnings | expand

Commit Message

Damien Le Moal June 9, 2022, 2:38 a.m. UTC
Using an allocated memory area with a size smaller than the data
structure it is cast to generates warnings with gcc12:

In function ‘_base_assign_fw_reported_qd’,
    inlined from ‘_base_static_config_pages’ at
    drivers/scsi/mpt3sas/mpt3sas_base.c:5495:7,
    inlined from ‘_base_make_ioc_operational’ at
    drivers/scsi/mpt3sas/mpt3sas_base.c:8109:6:
drivers/scsi/mpt3sas/mpt3sas_base.c:5397:40: warning: array subscript
‘Mpi2SasIOUnitPage1_t {aka struct _MPI2_CONFIG_PAGE_SASIOUNIT_1}[0]’ is
partly outside array bounds of ‘unsigned char[20]’ [-Warray-bounds]
 5397 |           (le16_to_cpu(sas_iounit_pg1->SASWideMaxQueueDepth)) ?
...

Fix this by allocating sas_iounit_pg1 with a size equal to its structure
type (Mpi2SasIOUnitPage1_t). This increases slightly the amount of
memory allocated, but this is acceptable as this is not the hot path and
the memory area is temporary (used only within
_base_assign_fw_reported_qd()).

Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 37d46ae5c61d..3b30d2c26f2a 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -5380,7 +5380,7 @@  static int _base_assign_fw_reported_qd(struct MPT3SAS_ADAPTER *ioc)
 		goto out;
 	/* sas iounit page 1 */
 	sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData);
-	sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
+	sas_iounit_pg1 = kzalloc(sizeof(Mpi2SasIOUnitPage1_t), GFP_KERNEL);
 	if (!sas_iounit_pg1) {
 		pr_err("%s: failure at %s:%d/%s()!\n",
 		    ioc->name, __FILE__, __LINE__, __func__);