Skip to content

Commit ba05959

Browse files
committed
Merge tag 'ata-6.4-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata
Pull ata fix from Damien Le Moal: - Fix ata_find_dev() use of the device number to find a struct ata_device for a port. This addresses issues with some passthrough commands with libsas managed devices. * tag 'ata-6.4-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata: ata: libata-scsi: Use correct device no in ata_find_dev()
2 parents 8828003 + 7f87585 commit ba05959

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

drivers/ata/libata-scsi.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,18 +2694,36 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc)
26942694
return 0;
26952695
}
26962696

2697-
static struct ata_device *ata_find_dev(struct ata_port *ap, int devno)
2697+
static struct ata_device *ata_find_dev(struct ata_port *ap, unsigned int devno)
26982698
{
2699-
if (!sata_pmp_attached(ap)) {
2700-
if (likely(devno >= 0 &&
2701-
devno < ata_link_max_devices(&ap->link)))
2699+
/*
2700+
* For the non-PMP case, ata_link_max_devices() returns 1 (SATA case),
2701+
* or 2 (IDE master + slave case). However, the former case includes
2702+
* libsas hosted devices which are numbered per scsi host, leading
2703+
* to devno potentially being larger than 0 but with each struct
2704+
* ata_device having its own struct ata_port and struct ata_link.
2705+
* To accommodate these, ignore devno and always use device number 0.
2706+
*/
2707+
if (likely(!sata_pmp_attached(ap))) {
2708+
int link_max_devices = ata_link_max_devices(&ap->link);
2709+
2710+
if (link_max_devices == 1)
2711+
return &ap->link.device[0];
2712+
2713+
if (devno < link_max_devices)
27022714
return &ap->link.device[devno];
2703-
} else {
2704-
if (likely(devno >= 0 &&
2705-
devno < ap->nr_pmp_links))
2706-
return &ap->pmp_link[devno].device[0];
2715+
2716+
return NULL;
27072717
}
27082718

2719+
/*
2720+
* For PMP-attached devices, the device number corresponds to C
2721+
* (channel) of SCSI [H:C:I:L], indicating the port pmp link
2722+
* for the device.
2723+
*/
2724+
if (devno < ap->nr_pmp_links)
2725+
return &ap->pmp_link[devno].device[0];
2726+
27092727
return NULL;
27102728
}
27112729

0 commit comments

Comments
 (0)