hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/ata/libata-scsi.c
....@@ -2742,17 +2742,35 @@
27422742 return 0;
27432743 }
27442744
2745
-static struct ata_device *ata_find_dev(struct ata_port *ap, int devno)
2745
+static struct ata_device *ata_find_dev(struct ata_port *ap, unsigned int devno)
27462746 {
2747
- if (!sata_pmp_attached(ap)) {
2748
- if (likely(devno >= 0 &&
2749
- devno < ata_link_max_devices(&ap->link)))
2747
+ /*
2748
+ * For the non-PMP case, ata_link_max_devices() returns 1 (SATA case),
2749
+ * or 2 (IDE master + slave case). However, the former case includes
2750
+ * libsas hosted devices which are numbered per scsi host, leading
2751
+ * to devno potentially being larger than 0 but with each struct
2752
+ * ata_device having its own struct ata_port and struct ata_link.
2753
+ * To accommodate these, ignore devno and always use device number 0.
2754
+ */
2755
+ if (likely(!sata_pmp_attached(ap))) {
2756
+ int link_max_devices = ata_link_max_devices(&ap->link);
2757
+
2758
+ if (link_max_devices == 1)
2759
+ return &ap->link.device[0];
2760
+
2761
+ if (devno < link_max_devices)
27502762 return &ap->link.device[devno];
2751
- } else {
2752
- if (likely(devno >= 0 &&
2753
- devno < ap->nr_pmp_links))
2754
- return &ap->pmp_link[devno].device[0];
2763
+
2764
+ return NULL;
27552765 }
2766
+
2767
+ /*
2768
+ * For PMP-attached devices, the device number corresponds to C
2769
+ * (channel) of SCSI [H:C:I:L], indicating the port pmp link
2770
+ * for the device.
2771
+ */
2772
+ if (devno < ap->nr_pmp_links)
2773
+ return &ap->pmp_link[devno].device[0];
27562774
27572775 return NULL;
27582776 }
....@@ -4241,7 +4259,7 @@
42414259 break;
42424260
42434261 case MAINTENANCE_IN:
4244
- if (scsicmd[1] == MI_REPORT_SUPPORTED_OPERATION_CODES)
4262
+ if ((scsicmd[1] & 0x1f) == MI_REPORT_SUPPORTED_OPERATION_CODES)
42454263 ata_scsi_rbuf_fill(&args, ata_scsiop_maint_in);
42464264 else
42474265 ata_scsi_set_invalid_field(dev, cmd, 1, 0xff);