Commit d5db139ab3764640e0882a1746e7b9fdee33fd87

Authored by Rusty Russell
1 parent c749637909

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>

Showing 3 changed files with 15 additions and 6 deletions Side-by-side Diff

include/linux/module.h
... ... @@ -444,7 +444,7 @@
444 444 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code)
445 445  
446 446 #ifdef CONFIG_MODULE_UNLOAD
447   -unsigned long module_refcount(struct module *mod);
  447 +int module_refcount(struct module *mod);
448 448 void __symbol_put(const char *symbol);
449 449 #define symbol_put(x) __symbol_put(VMLINUX_SYMBOL_STR(x))
450 450 void symbol_put_addr(void *addr);
kernel/debug/kdb/kdb_main.c
... ... @@ -1979,7 +1979,7 @@
1979 1979 kdb_printf("%-20s%8u 0x%p ", mod->name,
1980 1980 mod->core_size, (void *)mod);
1981 1981 #ifdef CONFIG_MODULE_UNLOAD
1982   - kdb_printf("%4ld ", module_refcount(mod));
  1982 + kdb_printf("%4d ", module_refcount(mod));
1983 1983 #endif
1984 1984 if (mod->state == MODULE_STATE_GOING)
1985 1985 kdb_printf(" (Unloading)");
... ... @@ -772,9 +772,18 @@
772 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 788 EXPORT_SYMBOL(module_refcount);
780 789  
... ... @@ -856,7 +865,7 @@
856 865 struct module_use *use;
857 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 871 * Always include a trailing , so userspace can differentiate
... ... @@ -908,7 +917,7 @@
908 917 static ssize_t show_refcnt(struct module_attribute *mattr,
909 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 923 static struct module_attribute modinfo_refcnt =