diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2015-01-21 19:43:14 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2015-01-21 19:45:54 -0500 |
commit | d5db139ab3764640e0882a1746e7b9fdee33fd87 (patch) | |
tree | 62f806a29a43c749c84354fbef3bdaa21dc3ce6f | |
parent | c749637909eea5d4090c6f50b89c2c20b534a280 (diff) |
module: make module_refcount() a signed integer.
James Bottomley points out that it will be -1 during unload. It's
only used for diagnostics, so let's not hide that as it could be a
clue as to what's gone wrong.
Cc: Jason Wessel <jason.wessel@windriver.com>
Acked-and-documention-added-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Reviewed-by: Masami Hiramatsu <maasami.hiramatsu.pt@hitachi.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r-- | include/linux/module.h | 2 | ||||
-rw-r--r-- | kernel/debug/kdb/kdb_main.c | 2 | ||||
-rw-r--r-- | kernel/module.c | 17 |
3 files changed, 15 insertions, 6 deletions
diff --git a/include/linux/module.h b/include/linux/module.h index ebfb0e153c6a..b653d7c0a05a 100644 --- a/include/linux/module.h +++ b/include/linux/module.h | |||
@@ -444,7 +444,7 @@ extern void __module_put_and_exit(struct module *mod, long code) | |||
444 | #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code) | 444 | #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code) |
445 | 445 | ||
446 | #ifdef CONFIG_MODULE_UNLOAD | 446 | #ifdef CONFIG_MODULE_UNLOAD |
447 | unsigned long module_refcount(struct module *mod); | 447 | int module_refcount(struct module *mod); |
448 | void __symbol_put(const char *symbol); | 448 | void __symbol_put(const char *symbol); |
449 | #define symbol_put(x) __symbol_put(VMLINUX_SYMBOL_STR(x)) | 449 | #define symbol_put(x) __symbol_put(VMLINUX_SYMBOL_STR(x)) |
450 | void symbol_put_addr(void *addr); | 450 | void symbol_put_addr(void *addr); |
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 379650b984f8..2934889f2cce 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c | |||
@@ -1979,7 +1979,7 @@ static int kdb_lsmod(int argc, const char **argv) | |||
1979 | kdb_printf("%-20s%8u 0x%p ", mod->name, | 1979 | kdb_printf("%-20s%8u 0x%p ", mod->name, |
1980 | mod->core_size, (void *)mod); | 1980 | mod->core_size, (void *)mod); |
1981 | #ifdef CONFIG_MODULE_UNLOAD | 1981 | #ifdef CONFIG_MODULE_UNLOAD |
1982 | kdb_printf("%4ld ", module_refcount(mod)); | 1982 | kdb_printf("%4d ", module_refcount(mod)); |
1983 | #endif | 1983 | #endif |
1984 | if (mod->state == MODULE_STATE_GOING) | 1984 | if (mod->state == MODULE_STATE_GOING) |
1985 | kdb_printf(" (Unloading)"); | 1985 | kdb_printf(" (Unloading)"); |
diff --git a/kernel/module.c b/kernel/module.c index ed4ec9c30bd2..d856e96a3cce 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -772,9 +772,18 @@ static int try_stop_module(struct module *mod, int flags, int *forced) | |||
772 | return 0; | 772 | return 0; |
773 | } | 773 | } |
774 | 774 | ||
775 | unsigned long module_refcount(struct module *mod) | 775 | /** |
776 | * module_refcount - return the refcount or -1 if unloading | ||
777 | * | ||
778 | * @mod: the module we're checking | ||
779 | * | ||
780 | * Returns: | ||
781 | * -1 if the module is in the process of unloading | ||
782 | * otherwise the number of references in the kernel to the module | ||
783 | */ | ||
784 | int module_refcount(struct module *mod) | ||
776 | { | 785 | { |
777 | return (unsigned long)atomic_read(&mod->refcnt) - MODULE_REF_BASE; | 786 | return atomic_read(&mod->refcnt) - MODULE_REF_BASE; |
778 | } | 787 | } |
779 | EXPORT_SYMBOL(module_refcount); | 788 | EXPORT_SYMBOL(module_refcount); |
780 | 789 | ||
@@ -856,7 +865,7 @@ static inline void print_unload_info(struct seq_file *m, struct module *mod) | |||
856 | struct module_use *use; | 865 | struct module_use *use; |
857 | int printed_something = 0; | 866 | int printed_something = 0; |
858 | 867 | ||
859 | seq_printf(m, " %lu ", module_refcount(mod)); | 868 | seq_printf(m, " %i ", module_refcount(mod)); |
860 | 869 | ||
861 | /* | 870 | /* |
862 | * Always include a trailing , so userspace can differentiate | 871 | * Always include a trailing , so userspace can differentiate |
@@ -908,7 +917,7 @@ EXPORT_SYMBOL_GPL(symbol_put_addr); | |||
908 | static ssize_t show_refcnt(struct module_attribute *mattr, | 917 | static ssize_t show_refcnt(struct module_attribute *mattr, |
909 | struct module_kobject *mk, char *buffer) | 918 | struct module_kobject *mk, char *buffer) |
910 | { | 919 | { |
911 | return sprintf(buffer, "%lu\n", module_refcount(mk->mod)); | 920 | return sprintf(buffer, "%i\n", module_refcount(mk->mod)); |
912 | } | 921 | } |
913 | 922 | ||
914 | static struct module_attribute modinfo_refcnt = | 923 | static struct module_attribute modinfo_refcnt = |