Skip to content

Commit 1a92837

Browse files
Ming Leimartinkpetersen
authored andcommitted
scsi: core: Simplify LLD module reference counting
Swap two statements in scsi_device_put() now that it is guaranteed that SCSI hosts outlive SCSI devices. Remove the reference counting code from scsi_sysfs.c that became superfluous because SCSI hosts now outlive SCSI devices. Link: https://lore.kernel.org/r/[email protected] Cc: Christoph Hellwig <[email protected]> Cc: Ming Lei <[email protected]> Cc: Mike Christie <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: John Garry <[email protected]> Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> [ bvanassche: Extracted this patch from a larger patch ] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 16728aa commit 1a92837

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

drivers/scsi/scsi.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,13 @@ EXPORT_SYMBOL(scsi_device_get);
586586
*/
587587
void scsi_device_put(struct scsi_device *sdev)
588588
{
589-
struct module *mod = sdev->host->hostt->module;
590-
589+
/*
590+
* Decreasing the module reference count before the device reference
591+
* count is safe since scsi_remove_host() only returns after all
592+
* devices have been removed.
593+
*/
594+
module_put(sdev->host->hostt->module);
591595
put_device(&sdev->sdev_gendev);
592-
module_put(mod);
593596
}
594597
EXPORT_SYMBOL(scsi_device_put);
595598

drivers/scsi/scsi_sysfs.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,6 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
452452
struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL;
453453
struct scsi_vpd *vpd_pgb0 = NULL, *vpd_pgb1 = NULL, *vpd_pgb2 = NULL;
454454
unsigned long flags;
455-
struct module *mod;
456-
457-
mod = sdev->host->hostt->module;
458455

459456
scsi_dh_release_device(sdev);
460457

@@ -521,17 +518,11 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
521518

522519
if (parent)
523520
put_device(parent);
524-
module_put(mod);
525521
}
526522

527523
static void scsi_device_dev_release(struct device *dev)
528524
{
529525
struct scsi_device *sdp = to_scsi_device(dev);
530-
531-
/* Set module pointer as NULL in case of module unloading */
532-
if (!try_module_get(sdp->host->hostt->module))
533-
sdp->host->hostt->module = NULL;
534-
535526
execute_in_process_context(scsi_device_dev_release_usercontext,
536527
&sdp->ew);
537528
}

0 commit comments

Comments
 (0)