Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: pm80xx: Use pm80xx_get_local_phy_id() to access phy array

While the current code is perfectly fine (because we verify that the
device is directly attached before using attached_phy to index the
pm8001_ha->phy array), let's use the pm80xx_get_local_phy_id() helper
anyway, to reduce the chance that someone will copy paste this pattern
to other parts of the driver.

Note that in this specific case, we still need to keep the check that
the device is not behind an expander, because we do not want to clear
attached_phy of the expander if a device behind the expander disappears
(as that would disable all the other devices behind the expander).

However, if it is the expander itself that disappears, attached_phy will
be cleared, just like it would for any other directly attached device.

Signed-off-by: Niklas Cassel <cassel@kernel.org>
Link: https://lore.kernel.org/r/20250814173215.1765055-22-cassel@kernel.org
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Igor Pylypiv <ipylypiv@google.com>
Acked-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Niklas Cassel and committed by
Martin K. Petersen
03f69351 ad70c6bc

+5 -2
+5 -2
drivers/scsi/pm8001/pm8001_sas.c
··· 780 780 * The phy array only contains local phys. Thus, we cannot clear 781 781 * phy_attached for a device behind an expander. 782 782 */ 783 - if (!dev_parent_is_expander(dev)) 784 - pm8001_ha->phy[pm8001_dev->attached_phy].phy_attached = 0; 783 + if (!dev_parent_is_expander(dev)) { 784 + u32 phy_id = pm80xx_get_local_phy_id(dev); 785 + 786 + pm8001_ha->phy[phy_id].phy_attached = 0; 787 + } 785 788 pm8001_free_dev(pm8001_dev); 786 789 } else { 787 790 pm8001_dbg(pm8001_ha, DISC, "Found dev has gone.\n");