Dan Carpenter found two static checker issues in Martin Peterson's git repo: tree: ("https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git") 5.13/scsi-queue This patch fixes the two reported static checker warnings. First Warning: 6702d2c40f31: ("scsi: smartpqi: Add support for RAID5 and RAID6 writes") Using rmd->blocks_per_row as a divisor without checking it for 0 first. ("https://marc.info/?l=linux-scsi&m=161795114128376&w=2") Second Warning: ec504b23df9d: ("[304/324] scsi: smartpqi: Add phy ID support for the physical drives") drivers/scsi/smartpqi/smartpqi_sas_transport.c:97 pqi_sas_port_add_rphy() warn: variable dereferenced before check 'pqi_sas_port->device' (see line 95) ("https://www.mail-archive.com/kbuild@xxxxxxxxxxxx/msg06329.html") Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> Reported-by: kernel test robot <lkp@xxxxxxxxx> Reviewed-by: Scott Benesh <scott.benesh@xxxxxxxxxxxxx> Reviewed-by: Scott Teel <scott.teel@xxxxxxxxxxxxx> Reviewed-by: Mike McGowen <mike.mcgowen@xxxxxxxxxxxxx> Reviewed-by: Kevin Barnett <kevin.barnett@xxxxxxxxxxxxx> Signed-off-by: Don Brace <don.brace@xxxxxxxxxxxxx> --- drivers/scsi/smartpqi/smartpqi_init.c | 8 ++++++-- drivers/scsi/smartpqi/smartpqi_sas_transport.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c index 3b0f281daa2b..797ac699b7ff 100644 --- a/drivers/scsi/smartpqi/smartpqi_init.c +++ b/drivers/scsi/smartpqi/smartpqi_init.c @@ -2510,6 +2510,8 @@ static int pci_get_aio_common_raid_map_values(struct pqi_ctrl_info *ctrl_info, /* Calculate stripe information for the request. */ rmd->blocks_per_row = rmd->data_disks_per_row * rmd->strip_size; + if (rmd->blocks_per_row == 0) /* Used as a divisor in many calculations */ + return PQI_RAID_BYPASS_INELIGIBLE; #if BITS_PER_LONG == 32 tmpdiv = rmd->first_block; 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, #if BITS_PER_LONG == 32 u64 tmpdiv; #endif + + if (rmd->blocks_per_row == 0) /* Used as a divisor in many calculations */ + return PQI_RAID_BYPASS_INELIGIBLE; + /* RAID 50/60 */ /* Verify first and last block are in same RAID group. */ 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, rmd->q_parity_it_nexus = raid_map->disk_data[index + 1].aio_handle; rmd->xor_mult = raid_map->disk_data[rmd->map_index].xor_mult[1]; } - if (rmd->blocks_per_row == 0) - return PQI_RAID_BYPASS_INELIGIBLE; #if BITS_PER_LONG == 32 tmpdiv = rmd->first_block; do_div(tmpdiv, rmd->blocks_per_row); diff --git a/drivers/scsi/smartpqi/smartpqi_sas_transport.c b/drivers/scsi/smartpqi/smartpqi_sas_transport.c index dd9b784792ef..dd628cc87f78 100644 --- a/drivers/scsi/smartpqi/smartpqi_sas_transport.c +++ b/drivers/scsi/smartpqi/smartpqi_sas_transport.c @@ -92,12 +92,12 @@ static int pqi_sas_port_add_rphy(struct pqi_sas_port *pqi_sas_port, identify = &rphy->identify; identify->sas_address = pqi_sas_port->sas_address; - identify->phy_identifier = pqi_sas_port->device->phy_id; identify->initiator_port_protocols = SAS_PROTOCOL_ALL; identify->target_port_protocols = SAS_PROTOCOL_STP; if (pqi_sas_port->device) { + identify->phy_identifier = pqi_sas_port->device->phy_id; switch (pqi_sas_port->device->device_type) { case SA_DEVICE_TYPE_SAS: case SA_DEVICE_TYPE_SES: