Skip to content

Commit d5db139

Browse files
committed
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 <[email protected]> Acked-and-documention-added-by: James Bottomley <[email protected]> Reviewed-by: Masami Hiramatsu <[email protected]> Signed-off-by: Rusty Russell <[email protected]>
1 parent c749637 commit d5db139

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

include/linux/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ extern void __module_put_and_exit(struct module *mod, long code)
444444
#define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code)
445445

446446
#ifdef CONFIG_MODULE_UNLOAD
447-
unsigned long module_refcount(struct module *mod);
447+
int module_refcount(struct module *mod);
448448
void __symbol_put(const char *symbol);
449449
#define symbol_put(x) __symbol_put(VMLINUX_SYMBOL_STR(x))
450450
void symbol_put_addr(void *addr);

kernel/debug/kdb/kdb_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ static int kdb_lsmod(int argc, const char **argv)
19791979
kdb_printf("%-20s%8u 0x%p ", mod->name,
19801980
mod->core_size, (void *)mod);
19811981
#ifdef CONFIG_MODULE_UNLOAD
1982-
kdb_printf("%4ld ", module_refcount(mod));
1982+
kdb_printf("%4d ", module_refcount(mod));
19831983
#endif
19841984
if (mod->state == MODULE_STATE_GOING)
19851985
kdb_printf(" (Unloading)");

kernel/module.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,18 @@ static int try_stop_module(struct module *mod, int flags, int *forced)
772772
return 0;
773773
}
774774

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)
776785
{
777-
return (unsigned long)atomic_read(&mod->refcnt) - MODULE_REF_BASE;
786+
return atomic_read(&mod->refcnt) - MODULE_REF_BASE;
778787
}
779788
EXPORT_SYMBOL(module_refcount);
780789

@@ -856,7 +865,7 @@ static inline void print_unload_info(struct seq_file *m, struct module *mod)
856865
struct module_use *use;
857866
int printed_something = 0;
858867

859-
seq_printf(m, " %lu ", module_refcount(mod));
868+
seq_printf(m, " %i ", module_refcount(mod));
860869

861870
/*
862871
* Always include a trailing , so userspace can differentiate
@@ -908,7 +917,7 @@ EXPORT_SYMBOL_GPL(symbol_put_addr);
908917
static ssize_t show_refcnt(struct module_attribute *mattr,
909918
struct module_kobject *mk, char *buffer)
910919
{
911-
return sprintf(buffer, "%lu\n", module_refcount(mk->mod));
920+
return sprintf(buffer, "%i\n", module_refcount(mk->mod));
912921
}
913922

914923
static struct module_attribute modinfo_refcnt =

0 commit comments

Comments
 (0)