linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] module_name()
@ 2002-11-12 17:32 Rusty Russell
  2002-11-12 20:39 ` Robert Love
  2002-11-12 22:03 ` David S. Miller
  0 siblings, 2 replies; 6+ messages in thread
From: Rusty Russell @ 2002-11-12 17:32 UTC (permalink / raw)
  To: davem; +Cc: linux-kernel

I prefer this: it also has the advantage of ensuring the name of
built-in modules is consistent across the kernel.

Thanks for the report,
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal working-2.5.47-module-alias/crypto/api.c working-2.5.47-modname/crypto/api.c
--- working-2.5.47-module-alias/crypto/api.c	2002-11-11 20:00:55.000000000 +1100
+++ working-2.5.47-modname/crypto/api.c	2002-11-13 04:30:48.000000000 +1100
@@ -263,8 +263,7 @@ static int c_show(struct seq_file *m, vo
 	struct crypto_alg *alg = (struct crypto_alg *)p;
 	
 	seq_printf(m, "name         : %s\n", alg->cra_name);
-	seq_printf(m, "module       : %s\n", alg->cra_module ?
-					alg->cra_module->name : "[static]");
+	seq_printf(m, "module       : %s\n", module_name(alg->cra_module));
 	seq_printf(m, "blocksize    : %u\n", alg->cra_blocksize);
 	
 	switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal working-2.5.47-module-alias/include/linux/module.h working-2.5.47-modname/include/linux/module.h
--- working-2.5.47-module-alias/include/linux/module.h	2002-11-12 22:43:55.000000000 +1100
+++ working-2.5.47-modname/include/linux/module.h	2002-11-13 04:31:16.000000000 +1100
@@ -293,6 +293,13 @@ static inline void module_put(struct mod
 
 #endif /* CONFIG_MODULE_UNLOAD */
 
+static inline char *module_name(struct module *module)
+{
+	if (module)
+		return module->name;
+	return "[built-in]";
+}
+
 #define __unsafe(mod)							     \
 do {									     \
 	if (mod && !(mod)->unsafe) {					     \
@@ -315,6 +322,10 @@ do {									     \
 #define try_module_get(module) 1
 #define module_put(module) do { } while(0)
 
+static inline char *module_name(struct module *module)
+{
+	Return "[built-in]";
+}
 #define __unsafe(mod)
 #endif /* CONFIG_MODULES */
 

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

* Re: [PATCH] module_name()
  2002-11-12 17:32 [PATCH] module_name() Rusty Russell
@ 2002-11-12 20:39 ` Robert Love
  2002-11-12 22:00   ` David S. Miller
  2002-11-12 22:03 ` David S. Miller
  1 sibling, 1 reply; 6+ messages in thread
From: Robert Love @ 2002-11-12 20:39 UTC (permalink / raw)
  To: Rusty Russell; +Cc: davem, linux-kernel

On Tue, 2002-11-12 at 12:32, Rusty Russell wrote:

> +static inline char *module_name(struct module *module)
> +{
> +	Return "[built-in]";
> +}

s/Return/return/ ? ;-)

	Robert Love


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

* Re: [PATCH] module_name()
  2002-11-12 20:39 ` Robert Love
@ 2002-11-12 22:00   ` David S. Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2002-11-12 22:00 UTC (permalink / raw)
  To: rml; +Cc: rusty, linux-kernel

   From: Robert Love <rml@tech9.net>
   Date: 12 Nov 2002 15:39:14 -0500

   On Tue, 2002-11-12 at 12:32, Rusty Russell wrote:
   
   > +static inline char *module_name(struct module *module)
   > +{
   > +	Return "[built-in]";
   > +}
   
   s/Return/return/ ? ;-)
   
I'd rather get a NULL for built-in, honestly.

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

* Re: [PATCH] module_name()
  2002-11-12 17:32 [PATCH] module_name() Rusty Russell
  2002-11-12 20:39 ` Robert Love
@ 2002-11-12 22:03 ` David S. Miller
  2002-11-13 10:04   ` Rusty Russell
  1 sibling, 1 reply; 6+ messages in thread
From: David S. Miller @ 2002-11-12 22:03 UTC (permalink / raw)
  To: rusty; +Cc: linux-kernel

   From: Rusty Russell <rusty@rustcorp.com.au>
   Date: Wed, 13 Nov 2002 04:32:58 +1100

   I prefer this: it also has the advantage of ensuring the name of
   built-in modules is consistent across the kernel.
   
I'd rather get NULL for built-in, this also eliminates
the issue of having umpteen "[built-in]" string copies in
the kernel since this is expanded by an inline.

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

* Re: [PATCH] module_name()
  2002-11-12 22:03 ` David S. Miller
@ 2002-11-13 10:04   ` Rusty Russell
  2002-11-13 10:56     ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Rusty Russell @ 2002-11-13 10:04 UTC (permalink / raw)
  To: David S. Miller; +Cc: linux-kernel

In message <20021112.140357.81690208.davem@redhat.com> you write:
>    From: Rusty Russell <rusty@rustcorp.com.au>
>    Date: Wed, 13 Nov 2002 04:32:58 +1100
> 
>    I prefer this: it also has the advantage of ensuring the name of
>    built-in modules is consistent across the kernel.
>    
> I'd rather get NULL for built-in

I'd rather not.  If you want that check, check for module == NULL.
This makes it trivially consistent across proc output, which is the
main use of module name outside module.c.

> this also eliminates the issue of having umpteen "[built-in]" string
> copies in the kernel since this is expanded by an inline.

Ick, yes.   Turned into macros, and changed to "kernel" since
exec_domain.c already uses that.

Thoughts?
Rusty.

diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/crypto/api.c working-2.5-bk-modname/crypto/api.c
--- linux-2.5-bk/crypto/api.c	2002-11-11 20:00:55.000000000 +1100
+++ working-2.5-bk-modname/crypto/api.c	2002-11-13 20:49:52.000000000 +1100
@@ -263,8 +263,7 @@ static int c_show(struct seq_file *m, vo
 	struct crypto_alg *alg = (struct crypto_alg *)p;
 	
 	seq_printf(m, "name         : %s\n", alg->cra_name);
-	seq_printf(m, "module       : %s\n", alg->cra_module ?
-					alg->cra_module->name : "[static]");
+	seq_printf(m, "module       : %s\n", module_name(alg->cra_module));
 	seq_printf(m, "blocksize    : %u\n", alg->cra_blocksize);
 	
 	switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/include/linux/module.h working-2.5-bk-modname/include/linux/module.h
--- linux-2.5-bk/include/linux/module.h	2002-11-13 18:54:55.000000000 +1100
+++ working-2.5-bk-modname/include/linux/module.h	2002-11-13 20:56:51.000000000 +1100
@@ -242,6 +242,13 @@ static inline void module_put(struct mod
 
 #endif /* CONFIG_MODULE_UNLOAD */
 
+/* This is a #define so the string doesn't get put in every .o file */
+#define module_name(mod)			\
+({						\
+	struct module *__mod = (mod);		\
+	__mod ? __mod->name : "kernel";		\
+})
+
 #define __unsafe(mod)							     \
 do {									     \
 	if (mod && !(mod)->unsafe) {					     \
@@ -265,6 +272,8 @@ do {									     \
 #define try_module_get(module) 1
 #define module_put(module) do { } while(0)
 
+#define module_name(mod) "kernel"
+
 #define __unsafe(mod)
 #endif /* CONFIG_MODULES */
 
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/kernel/exec_domain.c working-2.5-bk-modname/kernel/exec_domain.c
--- linux-2.5-bk/kernel/exec_domain.c	2002-11-13 18:54:56.000000000 +1100
+++ working-2.5-bk-modname/kernel/exec_domain.c	2002-11-13 20:57:19.000000000 +1100
@@ -210,13 +210,8 @@ get_exec_domain_list(char *page)
 	read_lock(&exec_domains_lock);
 	for (ep = exec_domains; ep && len < PAGE_SIZE - 80; ep = ep->next)
 		len += sprintf(page + len, "%d-%d\t%-16s\t[%s]\n",
-			ep->pers_low, ep->pers_high, ep->name,
-#ifdef CONFIG_MODULES
-			ep->module ? ep->module->name : "kernel"
-#else
-			"kernel"
-#endif
-			);
+			       ep->pers_low, ep->pers_high, ep->name,
+			       module_name(ep->module));
 	read_unlock(&exec_domains_lock);
 	return (len);
 }
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/net/ipv4/netfilter/ip_nat_helper.c working-2.5-bk-modname/net/ipv4/netfilter/ip_nat_helper.c
--- linux-2.5-bk/net/ipv4/netfilter/ip_nat_helper.c	2002-11-13 18:54:56.000000000 +1100
+++ working-2.5-bk-modname/net/ipv4/netfilter/ip_nat_helper.c	2002-11-13 20:59:30.000000000 +1100
@@ -361,8 +361,6 @@ helper_cmp(const struct ip_nat_helper *h
 	return ip_ct_tuple_mask_cmp(tuple, &helper->tuple, &helper->mask);
 }
 
-#define MODULE_MAX_NAMELEN		32
-
 int ip_nat_helper_register(struct ip_nat_helper *me)
 {
 	int ret = 0;
@@ -374,14 +372,13 @@ int ip_nat_helper_register(struct ip_nat
 		    && ct_helper->me) {
 			__MOD_INC_USE_COUNT(ct_helper->me);
 		} else {
-#ifdef CONFIG_MODULES
 			/* We are a NAT helper for protocol X.  If we need
 			 * respective conntrack helper for protoccol X, compute
 			 * conntrack helper name and try to load module */
-			char name[MODULE_MAX_NAMELEN];
-			const char *tmp = me->me->name;
+			char name[MODULE_NAME_LEN];
+			const char *tmp = module_name(me->me);
 			
-			if (strlen(tmp) + 6 > MODULE_MAX_NAMELEN) {
+			if (strlen(tmp) + 6 > MODULE_NAME_LEN) {
 				printk("%s: unable to "
 				       "compute conntrack helper name "
 				       "from %s\n", __FUNCTION__, tmp);
@@ -404,7 +401,6 @@ int ip_nat_helper_register(struct ip_nat
 			       "module loader support\n", name);
 			return -EBUSY;
 #endif
-#endif
 		}
 	}
 	WRITE_LOCK(&ip_nat_lock);
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

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

* Re: [PATCH] module_name()
  2002-11-13 10:04   ` Rusty Russell
@ 2002-11-13 10:56     ` David S. Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2002-11-13 10:56 UTC (permalink / raw)
  To: rusty; +Cc: linux-kernel

   From: Rusty Russell <rusty@rustcorp.com.au>
   Date: Wed, 13 Nov 2002 21:04:10 +1100
   
   > this also eliminates the issue of having umpteen "[built-in]" string
   > copies in the kernel since this is expanded by an inline.
   
   Ick, yes.   Turned into macros, and changed to "kernel" since
   exec_domain.c already uses that.
   
   Thoughts?

Ok, since when mod is NULL crypto.h won't even invoke module_name()
anyways :-)

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

end of thread, other threads:[~2002-11-13 10:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-12 17:32 [PATCH] module_name() Rusty Russell
2002-11-12 20:39 ` Robert Love
2002-11-12 22:00   ` David S. Miller
2002-11-12 22:03 ` David S. Miller
2002-11-13 10:04   ` Rusty Russell
2002-11-13 10:56     ` David S. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).