linux-stable/drivers/scsi/mpt3sas
Helge Deller 120f1d95ef scsi: mpt3sas: Fix out-of-bounds compiler warning
I'm facing this warning when building for the parisc64 architecture:

drivers/scsi/mpt3sas/mpt3sas_base.c: In function ‘_base_make_ioc_operational’:
drivers/scsi/mpt3sas/mpt3sas_base.c:5396: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]
 5396 |             (le16_to_cpu(sas_iounit_pg1->SASWideMaxQueueDepth)) ?
drivers/scsi/mpt3sas/mpt3sas_base.c:5382:26: note: referencing an object of size 20 allocated by ‘kzalloc’
 5382 |         sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
      |                          ^~~~~~~~~~~~~~~~~~~~~~~

The problem is, that only 20 bytes are allocated with kmalloc(), which is
sufficient to hold the bytes which are needed.  Nevertheless, gcc complains
because the whole Mpi2SasIOUnitPage1_t struct is 32 bytes in size and thus
doesn't fit into those 20 bytes.

This patch simply allocates all 32 bytes (instead of 20) and thus avoids
the warning. There is no functional change introduced by this patch.

While touching the code I cleaned up to calculation of max_wideport_qd,
max_narrowport_qd and max_sata_qd to make it easier readable.

Test successfully tested on a HP C8000 PA-RISC workstation with 64-bit
kernel.

Link: https://lore.kernel.org/r/YpZ197iZdDZSCzrT@p100
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2022-06-07 22:01:41 -04:00
..
mpi scsi: mpt3sas: Convert to flexible arrays 2022-02-07 23:16:34 -05:00
Kconfig scsi: mpt3sas: Fix spelling mistake in Kconfig "compatiblity" -> "compatibility" 2021-01-05 23:25:07 -05:00
Makefile
mpt3sas_base.c scsi: mpt3sas: Fix out-of-bounds compiler warning 2022-06-07 22:01:41 -04:00
mpt3sas_base.h scsi: mpt3sas: Update driver version to 42.100.00.00 2022-05-19 20:16:25 -04:00
mpt3sas_config.c scsi: mpt3sas: Fail reset operation if config request timed out 2022-04-06 22:14:09 -04:00
mpt3sas_ctl.c scsi: mpt3sas: Fix _ctl_set_task_mid() TaskMID check 2022-04-25 22:30:04 -04:00
mpt3sas_ctl.h scsi: mpt3sas: Fix out-of-bounds warnings in _ctl_addnl_diag_query 2021-04-13 00:31:05 -04:00
mpt3sas_debug.h
mpt3sas_debugfs.c
mpt3sas_scsih.c scsi: mpt3sas: Use cached ATA Information VPD page 2022-05-02 16:59:10 -04:00
mpt3sas_transport.c scsi: mpt3sas: Fix a couple of misdocumented functions/params 2021-03-15 22:28:57 -04:00
mpt3sas_trigger_diag.c scsi: mpt3sas: Additional diagnostic buffer query interface 2021-02-08 22:02:07 -05:00
mpt3sas_trigger_diag.h
mpt3sas_trigger_pages.h
mpt3sas_warpdrive.c