[PATCH] scsi: mpt3sas: fix compilation warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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__);
-- 
2.36.1





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux