scsi/scsi_bus: switch search direction in scsi_device_find
authorMaxim Levitsky <mlevitsk@redhat.com>
Tue, 6 Oct 2020 12:38:57 +0000 (14:38 +0200)
committerwanchao-xu <wanchao.xu@samsung.com>
Tue, 9 Jan 2024 11:49:25 +0000 (19:49 +0800)
Git-commit: 7a8202c521a5d1ac9e289d5c2b5125a9310af178
References: bsc#1184574

This change will allow us to convert the bus children list to RCU,
while not changing the logic of this function

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20200913160259.32145-2-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Lin Ma <lma@suse.com>
hw/scsi/scsi-bus.c

index ad0e7f6d8895690fefbaa420781635cf47dc1a41..4f277985f64be532c8151a0ac09b00288089d211 100644 (file)
@@ -1584,7 +1584,7 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
     BusChild *kid;
     SCSIDevice *target_dev = NULL;
 
-    QTAILQ_FOREACH_REVERSE(kid, &bus->qbus.children, sibling) {
+    QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
         DeviceState *qdev = kid->child;
         SCSIDevice *dev = SCSI_DEVICE(qdev);
 
@@ -1592,7 +1592,15 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
             if (dev->lun == lun) {
                 return dev;
             }
-            target_dev = dev;
+
+            /*
+             * If we don't find exact match (channel/bus/lun),
+             * we will return the first device which matches channel/bus
+             */
+
+            if (!target_dev) {
+                target_dev = dev;
+            }
         }
     }
     return target_dev;