Skip to content

Commit dc4515e

Browse files
committed
scsi: always increment reference count
James reported: > After e513cc1 module: Remove stop_machine from module unloading, > module_refcount() is returning (unsigned long)-1 when called from within > a routine that runs in module_exit. This is confusing the scsi device > put code which is coded to detect a module_refcount() of zero for > running within a module exit routine and not try to do another > module_put. The fix is to restore the original behaviour of > module_refcount() and return zero if we're running inside an exit > routine. The correct fix is to turn try_module_get() into __module_get(), and always do the module_put(). Acked-by: James Bottomley <[email protected]> Signed-off-by: Rusty Russell <[email protected]>
1 parent d5db139 commit dc4515e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

drivers/scsi/scsi.c

+3-10
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,9 @@ int scsi_device_get(struct scsi_device *sdev)
986986
return -ENXIO;
987987
if (!get_device(&sdev->sdev_gendev))
988988
return -ENXIO;
989-
/* We can fail this if we're doing SCSI operations
989+
/* We can fail try_module_get if we're doing SCSI operations
990990
* from module exit (like cache flush) */
991-
try_module_get(sdev->host->hostt->module);
991+
__module_get(sdev->host->hostt->module);
992992

993993
return 0;
994994
}
@@ -1004,14 +1004,7 @@ EXPORT_SYMBOL(scsi_device_get);
10041004
*/
10051005
void scsi_device_put(struct scsi_device *sdev)
10061006
{
1007-
#ifdef CONFIG_MODULE_UNLOAD
1008-
struct module *module = sdev->host->hostt->module;
1009-
1010-
/* The module refcount will be zero if scsi_device_get()
1011-
* was called from a module removal routine */
1012-
if (module && module_refcount(module) != 0)
1013-
module_put(module);
1014-
#endif
1007+
module_put(sdev->host->hostt->module);
10151008
put_device(&sdev->sdev_gendev);
10161009
}
10171010
EXPORT_SYMBOL(scsi_device_put);

0 commit comments

Comments
 (0)