Skip to contentSkip to conversation

scsi: hisi_sas: Fix some issues related to asd_sas_port->phy_list

bug report Dan Carpenter 2 participants 2 messages Jan 10, 2022 SCSI

lore
Share & tools
lore
#0 lore raw

Hello Xiang Chen,

The patch 29e2bac87421: "scsi: hisi_sas: Fix some issues related to asd_sas_port->phy_list" from Dec 20, 2021, leads to the following Smatch static checker warning:

	drivers/scsi/hisi_sas/hisi_sas_main.c:1536 hisi_sas_send_ata_reset_each_phy()
	error: potentially dereferencing uninitialized 'sas_phy'.

drivers/scsi/hisi_sas/hisi_sas_main.c

    1519 static void hisi_sas_send_ata_reset_each_phy(struct hisi_hba *hisi_hba,
    1520                                              struct asd_sas_port *sas_port,
    1521                                              struct domain_device *device)
    1522 {
    1523         struct hisi_sas_tmf_task tmf_task = { .force_phy = 1 };
    1524         struct ata_port *ap = device->sata_dev.ap;
    1525         struct device *dev = hisi_hba->dev;
    1526         int s = sizeof(struct host_to_dev_fis);
    1527         int rc = TMF_RESP_FUNC_FAILED;
    1528         struct asd_sas_phy *sas_phy;
    1529         struct ata_link *link;
    1530         u8 fis[20] = {0};
    1531         u32 state;
    1532         int i;
    1533 
    1534         state = hisi_hba->hw->get_phys_state(hisi_hba);
    1535         for (i = 0; i < hisi_hba->n_phy; i++) {
--> 1536                 if (!(state & BIT(sas_phy->id)))
                                           ^^^^^^^

This is no longer initialized anywhere.

    1537                         continue;
    1538                 if (!(sas_port->phy_mask & BIT(i)))
    1539                         continue;
    1540 
    1541                 ata_for_each_link(link, ap, EDGE) {
    1542                         int pmp = sata_srst_pmp(link);
    1543 
    1544                         tmf_task.phy_id = i;
    1545                         hisi_sas_fill_ata_reset_cmd(link->device, 1, pmp, fis);
    1546                         rc = hisi_sas_exec_internal_tmf_task(device, fis, s,
    1547                                                              &tmf_task);
    1548                         if (rc != TMF_RESP_FUNC_COMPLETE) {
    1549                                 dev_err(dev, "phy%d ata reset failed rc=%d\n",
    1550                                         i, rc);
    1551                                 break;
    1552                         }
    1553                 }
    1554         }
    1555 }

regards,
dan carpenter

#1 lore raw
Quoted 8 lines · Dan Carpenter

Hello Xiang Chen,

The patch 29e2bac87421: "scsi: hisi_sas: Fix some issues related to asd_sas_port->phy_list" from Dec 20, 2021, leads to the following Smatch static checker warning:

	drivers/scsi/hisi_sas/hisi_sas_main.c:1536 hisi_sas_send_ata_reset_each_phy()
	error: potentially dereferencing uninitialized 'sas_phy'.

Hi Dan,

Thanks for the notice. This should now be fixed on Martin's 5.17 staging branch. https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git/commit/?h=5.17/scsi-staging&id=5d9224fb076e9a2023e0b06d6a164d644612c0c0

Thanks!