[PATCH v5 7/7] scsi: core: Improve SCSI device removal

Bart Van Assche
2022-09-14T22:57:10Z

Instead of clearing the host template module pointer if the LLD kernel
module is being unloaded, call __module_get() unconditionally. This
patch is a bug fix because it prevents that a SCSI LLD is unloaded after
scsi_device_dev_release() returns and before
scsi_device_dev_release_usercontext() is called.

Suggested-by: Christoph Hellwig <hch@lst.de>
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>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/scsi_sysfs.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index a3aaafdeac1d..661c2bdd4588 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -523,9 +523,7 @@ 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;
+ __module_get(sdp->host->hostt->module);

execute_in_process_context(scsi_device_dev_release_usercontext,
&sdp->ew);