linux/drivers/ata
Damien Le Moal 7f875850f2 ata: libata-scsi: Use correct device no in ata_find_dev()
For devices not attached to a port multiplier and managed directly by
libata, the device number passed to ata_find_dev() must always be lower
than the maximum number of devices returned by ata_link_max_devices().
That is 1 for SATA devices or 2 for an IDE link with master+slave
devices. This device number is the SCSI device ID which matches these
constraints as the IDs are generated per port and so never exceed the
maximum number of devices for the link being used.

However, for libsas managed devices, SCSI device IDs are assigned per
struct scsi_host, leading to device IDs for SATA devices that can be
well in excess of libata per-link maximum number of devices. This
results in ata_find_dev() to always return NULL for libsas managed
devices except for the first device of the target scsi_host with ID
(device number) equal to 0. This issue is visible by executing the
hdparm utility, which fails. E.g.:

hdparm -i /dev/sdX
/dev/sdX:
  HDIO_GET_IDENTITY failed: No message of desired type

Fix this by rewriting ata_find_dev() to ignore the device number for
non-PMP attached devices with a link with at most 1 device, that is SATA
devices. For these, the device number 0 is always used to
return the correct pointer to the struct ata_device of the port link.
This change excludes IDE master/slave setups (maximum number of devices
per link is 2) and port-multiplier attached devices. Also, to be
consistant with the fact that SCSI device IDs and channel numbers used
as device numbers are both unsigned int, change the devno argument of
ata_find_dev() to unsigned int.

Reported-by: Xingui Yang <yangxingui@huawei.com>
Fixes: 41bda9c980 ("libata-link: update hotplug to handle PMP links")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Jason Yan <yanaijie@huawei.com>
2023-05-30 08:08:18 +09:00
..
pata_parport Driver core changes for 6.4-rc1 2023-04-27 11:53:57 -07:00
acard-ahci.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_brcm.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_ceva.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_da850.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_dm816.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_dwc.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_imx.c SCSI misc on 20230426 2023-04-26 15:39:25 -07:00
ahci_mtk.c SCSI misc on 20230426 2023-04-26 15:39:25 -07:00
ahci_mvebu.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_octeon.c ata: octeon: Drop empty platform remove function 2023-01-03 08:39:41 +09:00
ahci_platform.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_qoriq.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_seattle.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_st.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_sunxi.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_tegra.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci_xgene.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ahci.h scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ata_generic.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
ata_piix.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
Kconfig ahci: qoriq: Add platform dependencies 2023-03-23 10:29:26 +09:00
libahci_platform.c SCSI misc on 20230426 2023-04-26 15:39:25 -07:00
libahci.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
libata-acpi.c ata: make use of ata_port_is_frozen() helper 2022-10-18 13:53:27 +09:00
libata-core.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
libata-eh.c ata: scsi: rename flag ATA_QCFLAG_FAILED to ATA_QCFLAG_EH 2023-01-04 13:36:26 +09:00
libata-pata-timings.c ata: separate PATA timings code from libata-core.c 2020-03-26 10:28:19 -06:00
libata-pmp.c ata: libata: add tracepoints for ATA error handling 2022-01-05 19:33:01 +09:00
libata-sata.c ata: libata: read the shared status for successful NCQ commands once 2023-01-04 13:38:14 +09:00
libata-scsi.c ata: libata-scsi: Use correct device no in ata_find_dev() 2023-05-30 08:08:18 +09:00
libata-sff.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
libata-trace.c ata: scsi: rename flag ATA_QCFLAG_FAILED to ATA_QCFLAG_EH 2023-01-04 13:36:26 +09:00
libata-transport.c ata: libata-transport: fix error handling in ata_tdev_add() 2022-11-11 17:26:05 +09:00
libata-transport.h
libata-zpodd.c libata: zpodd: Fix small read overflow in zpodd_get_mech_type() 2019-07-29 16:00:14 -06:00
libata.h scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
Makefile ATA changes for 6.3-rc1 2023-02-22 13:35:51 -08:00
pata_acpi.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ali.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_amd.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_arasan_cf.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_artop.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_atiixp.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_atp867x.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_buddha.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cmd64x.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cmd640.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cs5520.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cs5530.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cs5535.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cs5536.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_cypress.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_efar.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ep93xx.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_falcon.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ftide010.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_gayle.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_hpt3x2n.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_hpt3x3.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_hpt37x.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_hpt366.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_icside.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_imx.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_isapnp.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_it821x.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_it8213.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ixp4xx_cf.c SCSI misc on 20230426 2023-04-26 15:39:25 -07:00
pata_jmicron.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_legacy.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_macio.c SCSI misc on 20230426 2023-04-26 15:39:25 -07:00
pata_marvell.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_mpc52xx.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_mpiix.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_netcell.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ninja32.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ns87410.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_ns87415.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_octeon_cf.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_of_platform.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_oldpiix.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_opti.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_optidma.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_pcmcia.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_pdc202xx_old.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_pdc2027x.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_piccolo.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_platform.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_pxa.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_radisys.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_rb532_cf.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_rdc.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_rz1000.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sc1200.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sch.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_serverworks.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sil680.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sis.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_sl82c105.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_triflex.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pata_via.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
pdc_adma.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_dwc_460ex.c SCSI misc on 20230426 2023-04-26 15:39:25 -07:00
sata_fsl.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_gemini.c ata: sata_gemini: Remove dependency on OF for compile tests 2022-10-18 08:04:46 +09:00
sata_gemini.h
sata_highbank.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_inic162x.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_mv.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_nv.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_promise.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_promise.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
sata_qstor.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_rcar.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_sil24.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_sil.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_sis.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_svw.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_sx4.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_uli.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_via.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sata_vsc.c scsi: ata: Declare SCSI host templates const 2023-03-24 19:19:19 -04:00
sis.h