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@xxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Ming Lei <ming.lei@xxxxxxxxxx> Cc: Hannes Reinecke <hare@xxxxxxx> Cc: John Garry <john.garry@xxxxxxxxxx> Cc: Mike Christie <michael.christie@xxxxxxxxxx> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxx> Cc: Luis Chamberlain <mcgrof@xxxxxxxxxx> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx> --- 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);