[PATCH] module_refcount for all [Was: Re: [UPDATED PATCH 17-8] fix refcount for non-modular case]

Dominik Brodowski linux at dominikbrodowski.de
Sat Nov 6 08:49:02 EST 2004


On Sat, Nov 06, 2004 at 11:48:37AM +0000, Christoph Hellwig wrote:
> On Wed, Nov 03, 2004 at 04:14:30PM +0100, Dominik Brodowski wrote:
> > -	struct pcmcia_driver *p_dev = container_of(driver, 
> > +	struct pcmcia_driver *p_drv = container_of(driver, 
> >  						   struct pcmcia_driver, drv);
> >  
> > -	*p += sprintf(*p, "%-24.24s 1 %d\n", driver->name, p_dev->use_count);
> > +	*p += sprintf(*p, "%-24.24s 1 %d\n", p_drv->drv.name, 
> > +#ifdef CONFIG_MODULE_UNLOAD
> > +		      (p_drv->owner) ? module_refcount(p_drv->owner) : 1
> > +#else
> > +		      1
> > +#endif
> 
> Might be better to send rusty a patch to make module_refcount useful for
> 
>  a) a NULL argument
>  b) !CONFIG_MODULE_UNLOAD


return "1" in module_refcount if the "module" was built into the kernel or
if it can't be unloaded because CONFIG_MODULE_UNLOAD isn't set.

Signed-off-by: Dominik Brodowski <linux at brodo.de>

--- linux/include/linux/module.h.original	2004-11-06 14:40:50.304885768 +0100
+++ linux/include/linux/module.h	2004-11-06 14:38:59.421742568 +0100
@@ -351,8 +351,9 @@
 	__attribute__((noreturn));
 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
 
-#ifdef CONFIG_MODULE_UNLOAD
 unsigned int module_refcount(struct module *mod);
+
+#ifdef CONFIG_MODULE_UNLOAD
 void __symbol_put(const char *symbol);
 #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x)
 void symbol_put_addr(void *addr);
@@ -530,6 +531,11 @@
 	return 0;
 }
 
+static inline unsigned int module_refcount(const module *mod)
+{
+	return 1;
+}
+
 #define module_put_and_exit(code) do_exit(code)
 
 static inline void print_modules(void)
--- linux/kernel/module.c.original	2004-11-06 14:40:40.900315480 +0100
+++ linux/kernel/module.c	2004-11-06 14:42:11.097603408 +0100
@@ -498,8 +498,11 @@
 {
 	unsigned int i, total = 0;
 
-	for (i = 0; i < NR_CPUS; i++)
-		total += local_read(&mod->ref[i].count);
+	if (mod) {
+		for (i = 0; i < NR_CPUS; i++)
+			total += local_read(&mod->ref[i].count);
+	} else
+		total = 1;
 	return total;
 }
 EXPORT_SYMBOL(module_refcount);
@@ -686,6 +689,12 @@
 	return -ENOSYS;
 }
 
+unsigned int module_refcount(struct module *mod)
+{
+	return 1;
+}
+EXPORT_SYMBOL(module_refcount);
+
 #endif /* CONFIG_MODULE_UNLOAD */
 
 #ifdef CONFIG_OBSOLETE_MODPARM



More information about the linux-pcmcia mailing list