All of lore.kernel.org
 help / color / mirror / Atom feed
* module: fix module_refcount() return when running in a module exit routine
@ 2015-01-18 16:55 James Bottomley
  2015-01-18 23:37   ` Rusty Russell
  2015-01-19  5:18 ` Masami Hiramatsu
  0 siblings, 2 replies; 22+ messages in thread
From: James Bottomley @ 2015-01-18 16:55 UTC (permalink / raw)
  To: rusty, masami.hiramatsu.pt; +Cc: linux-kernel, linux-scsi

From: James Bottomley <JBottomley@Parallels.com>

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.

Fixes: e513cc1c07e2ab93a4514eec9833e031df3e30bb
Reported-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>

---

diff --git a/kernel/module.c b/kernel/module.c
index 3965511..c33a113 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -774,7 +774,12 @@ static int try_stop_module(struct module *mod, int flags, int *forced)
 
 unsigned long module_refcount(struct module *mod)
 {
-	return (unsigned long)atomic_read(&mod->refcnt) - MODULE_REF_BASE;
+	unsigned long ret = atomic_read(&mod->refcnt);
+
+	if (ret == 0)
+		/* ref is already zero (probably in module exit) */
+		return 0;
+	return ret - MODULE_REF_BASE;
 }
 EXPORT_SYMBOL(module_refcount);
 



^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2015-01-29 12:16 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-18 16:55 module: fix module_refcount() return when running in a module exit routine James Bottomley
2015-01-18 23:37 ` Rusty Russell
2015-01-18 23:37   ` Rusty Russell
2015-01-19  5:18 ` Masami Hiramatsu
2015-01-19  5:51   ` Rusty Russell
2015-01-19  8:28     ` Christoph Hellwig
2015-01-19 16:07       ` James Bottomley
2015-01-19 16:08     ` James Bottomley
2015-01-20  0:45       ` Rusty Russell
2015-01-20  2:17         ` Masami Hiramatsu
2015-01-20 17:23         ` James Bottomley
2015-01-21  5:30           ` Rusty Russell
2015-01-22 16:50           ` Christoph Hellwig
2015-01-22 17:02             ` James Bottomley
2015-01-23  2:54               ` Rusty Russell
2015-01-23 13:17                 ` Christoph Hellwig
2015-01-23 18:42                   ` James Bottomley
2015-01-23 23:35                     ` Rusty Russell
2015-01-26 17:16                     ` Christoph Hellwig
2015-01-28  9:23                     ` Bart Van Assche
2015-01-28 21:45                       ` James Bottomley
2015-01-29 12:16                         ` Bart Van Assche

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.