[SCSI] Skip deleted devices in __scsi_device_lookup_by_target()

__scsi_device_lookup_by_target() will always return
the first sdev with a matching LUN, regardless of
the state. However, when this sdev is in SDEV_DEL
scsi_device_lookup_by_target() will ignore this
device and so any valid device on the list after
the deleted device will never be found.
So we have to modify __scsi_device_lookup_by_target()
to skip any device in SDEV_DEL.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>

authored by Hannes Reinecke and committed by James Bottomley 32aeef60 debf4777

+4 -1
+4 -1
drivers/scsi/scsi.c
··· 1095 * Description: Looks up the scsi_device with the specified @lun for a given 1096 * @starget. The returned scsi_device does not have an additional 1097 * reference. You must hold the host's host_lock over this call and 1098 - * any access to the returned scsi_device. 1099 * 1100 * Note: The only reason why drivers should use this is because 1101 * they need to access the device list in irq context. Otherwise you ··· 1108 struct scsi_device *sdev; 1109 1110 list_for_each_entry(sdev, &starget->devices, same_target_siblings) { 1111 if (sdev->lun ==lun) 1112 return sdev; 1113 }
··· 1095 * Description: Looks up the scsi_device with the specified @lun for a given 1096 * @starget. The returned scsi_device does not have an additional 1097 * reference. You must hold the host's host_lock over this call and 1098 + * any access to the returned scsi_device. A scsi_device in state 1099 + * SDEV_DEL is skipped. 1100 * 1101 * Note: The only reason why drivers should use this is because 1102 * they need to access the device list in irq context. Otherwise you ··· 1107 struct scsi_device *sdev; 1108 1109 list_for_each_entry(sdev, &starget->devices, same_target_siblings) { 1110 + if (sdev->sdev_state == SDEV_DEL) 1111 + continue; 1112 if (sdev->lun ==lun) 1113 return sdev; 1114 }