diff mbox series

[v6,7/8] scsi: core: Remove the put_device() call from scsi_device_get()

Message ID 20220929224421.587465-8-bvanassche@acm.org (mailing list archive)
State Superseded
Headers show
Series Prepare for constifying SCSI host templates | expand

Commit Message

Bart Van Assche Sept. 29, 2022, 10:44 p.m. UTC
scsi_device_get() may be called from atomic context, e.g. by
shost_for_each_device(). A later patch will allow put_device() to sleep
for SCSI devices. Hence this patch that removes the put_device() call
from scsi_device_get().

According to Rusty Russell's "Module Refcount and Stuff mini-FAQ",
calling module_put() from atomic context is allowed since considerable
time. See also https://lkml.org/lkml/2002/11/18/330.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Mike Christie <michael.christie@oracle.com>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
 drivers/scsi/scsi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series


diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 086ec5b5862d..87bddd697fc6 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -563,14 +563,14 @@  int scsi_device_get(struct scsi_device *sdev)
 	if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL)
 		goto fail;
-	if (!get_device(&sdev->sdev_gendev))
-		goto fail;
 	if (!try_module_get(sdev->host->hostt->module))
-		goto fail_put_device;
+		goto fail;
+	if (!get_device(&sdev->sdev_gendev))
+		goto fail_put_module;
 	return 0;
-	put_device(&sdev->sdev_gendev);
+	module_put(sdev->host->hostt->module);
 	return -ENXIO;