All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: check for device state in __scsi_remove_target()
@ 2017-12-13 13:21 Hannes Reinecke
  2017-12-13 22:23 ` Bart Van Assche
  2017-12-19  3:37 ` Martin K. Petersen
  0 siblings, 2 replies; 9+ messages in thread
From: Hannes Reinecke @ 2017-12-13 13:21 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Hannes Reinecke,
	Hannes Reinecke

As it turned out device_get() doesn't use kref_get_unless_zero(),
so we will be always getting a device pointer.
So we need to check for the device state in __scsi_remove_target()
to avoid tripping over deleted objects.

Fixes: fbce4d9 ("scsi: fixup kernel warning during rmmod()")

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/scsi_sysfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index cbc0fe2..a04678b 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -1411,7 +1411,10 @@ static void __scsi_remove_target(struct scsi_target *starget)
 		 * check.
 		 */
 		if (sdev->channel != starget->channel ||
-		    sdev->id != starget->id ||
+		    sdev->id != starget->id)
+			continue;
+		if (sdev->sdev_state == SDEV_DEL ||
+		    sdev->sdev_state == SDEV_CANCEL ||
 		    !get_device(&sdev->sdev_gendev))
 			continue;
 		spin_unlock_irqrestore(shost->host_lock, flags);
-- 
1.8.5.6

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-01-17  4:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-13 13:21 [PATCH] scsi: check for device state in __scsi_remove_target() Hannes Reinecke
2017-12-13 22:23 ` Bart Van Assche
2017-12-14  8:05   ` Jason Yan
2017-12-14  9:02     ` Hannes Reinecke
2017-12-14 22:10       ` Ewan D. Milne
2017-12-18 14:38         ` Ewan D. Milne
2017-12-19  3:37 ` Martin K. Petersen
2018-01-16 16:11   ` Bart Van Assche
2018-01-17  4:39     ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.