Skip to content

Commit 667298c

Browse files
Don Bracemartinkpetersen
authored andcommitted
scsi: smartpqi: Fix blocks_per_row static checker issue
Dan Carpenter found a possible divide by 0 issue in the smartpqi driver in functions pci_get_aio_common_raid_map_values() and pqi_calc_aio_r5_or_r6(). The variable rmd->blocks_per_row is used as a divisor and could be 0. Using rmd->blocks_per_row as a divisor without checking it for 0 first. Correct these possible divide by 0 conditions by insuring that rmd->blocks_per_row is not zero before usage. The check for non-0 was too late to prevent a divide by 0 condition. Add in a comment to explain why the check for non-zero is necessary. If the member is 0, return PQI_RAID_BYPASS_INELIGIBLE before any division is performed. Link: https://lore.kernel.org/linux-scsi/YG%2F5kWHHAr7w5dU5@mwanda/ Link: https://lore.kernel.org/r/161850492435.7302.392780350442938047.stgit@brunhilda Fixes: 6702d2c ("scsi: smartpqi: Add support for RAID5 and RAID6 writes") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Reported-by: kernel test robot <lkp@intel.com> Reviewed-by: Scott Benesh <scott.benesh@microchip.com> Reviewed-by: Scott Teel <scott.teel@microchip.com> Reviewed-by: Mike McGowen <mike.mcgowen@microchip.com> Reviewed-by: Kevin Barnett <kevin.barnett@microchip.com> Signed-off-by: Don Brace <don.brace@microchip.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 15cfef8 commit 667298c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/scsi/smartpqi/smartpqi_init.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,8 @@ static int pci_get_aio_common_raid_map_values(struct pqi_ctrl_info *ctrl_info,
25102510

25112511
/* Calculate stripe information for the request. */
25122512
rmd->blocks_per_row = rmd->data_disks_per_row * rmd->strip_size;
2513+
if (rmd->blocks_per_row == 0) /* Used as a divisor in many calculations */
2514+
return PQI_RAID_BYPASS_INELIGIBLE;
25132515
#if BITS_PER_LONG == 32
25142516
tmpdiv = rmd->first_block;
25152517
do_div(tmpdiv, rmd->blocks_per_row);
@@ -2559,6 +2561,10 @@ static int pqi_calc_aio_r5_or_r6(struct pqi_scsi_dev_raid_map_data *rmd,
25592561
#if BITS_PER_LONG == 32
25602562
u64 tmpdiv;
25612563
#endif
2564+
2565+
if (rmd->blocks_per_row == 0) /* Used as a divisor in many calculations */
2566+
return PQI_RAID_BYPASS_INELIGIBLE;
2567+
25622568
/* RAID 50/60 */
25632569
/* Verify first and last block are in same RAID group. */
25642570
rmd->stripesize = rmd->blocks_per_row * rmd->layout_map_count;
@@ -2662,8 +2668,6 @@ static int pqi_calc_aio_r5_or_r6(struct pqi_scsi_dev_raid_map_data *rmd,
26622668
rmd->q_parity_it_nexus = raid_map->disk_data[index + 1].aio_handle;
26632669
rmd->xor_mult = raid_map->disk_data[rmd->map_index].xor_mult[1];
26642670
}
2665-
if (rmd->blocks_per_row == 0)
2666-
return PQI_RAID_BYPASS_INELIGIBLE;
26672671
#if BITS_PER_LONG == 32
26682672
tmpdiv = rmd->first_block;
26692673
do_div(tmpdiv, rmd->blocks_per_row);

0 commit comments

Comments
 (0)