diff mbox series

[v3,3/3] scsi: core: Rework the code for dropping the LLD module reference

Message ID 20220908233600.3043271-4-bvanassche@acm.org
State Superseded
Headers show
Series Prepare for constifying SCSI host templates | expand

Commit Message

Bart Van Assche Sept. 8, 2022, 11:36 p.m. UTC
Instead of clearing the host template module pointer if the LLD kernel
module is being unloaded, set the 'drop_module_ref' SCSI device member.
This patch prepares for constifying the SCSI host template.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: John Garry <john.garry@huawei.com>
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_sysfs.c  | 7 +++----
 include/scsi/scsi_device.h | 1 +
 2 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 5d61f58399dc..822ae60a64b9 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -454,7 +454,7 @@  static void scsi_device_dev_release_usercontext(struct work_struct *work)
 
 	sdev = container_of(work, struct scsi_device, ew.work);
 
-	mod = sdev->host->hostt->module;
+	mod = sdev->drop_module_ref ? sdev->host->hostt->module : NULL;
 
 	scsi_dh_release_device(sdev);
 
@@ -525,9 +525,8 @@  static void scsi_device_dev_release(struct device *dev)
 {
 	struct scsi_device *sdp = to_scsi_device(dev);
 
-	/* Set module pointer as NULL in case of module unloading */
-	if (!try_module_get(sdp->host->hostt->module))
-		sdp->host->hostt->module = NULL;
+	if (try_module_get(sdp->host->hostt->module))
+		sdp->drop_module_ref = true;
 
 	execute_in_process_context(scsi_device_dev_release_usercontext,
 				   &sdp->ew);
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 2493bd65351a..b03176b69056 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -214,6 +214,7 @@  struct scsi_device {
 					 * creation time */
 	unsigned ignore_media_change:1; /* Ignore MEDIA CHANGE on resume */
 	unsigned silence_suspend:1;	/* Do not print runtime PM related messages */
+	unsigned drop_module_ref:1;
 
 	unsigned int queue_stopped;	/* request queue is quiesced */
 	bool offline_already;		/* Device offline message logged */