module_name macro
Subsystems (4)
PATCH 1/1 module_name macro
Nice abstraction to remove some #ifdef CONFIG_MODULEs.
Linus, please apply.
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: Module Fixes II: module_name
Author: Rusty Russell
Status: Trivial
Depends: Module/module.patch.gz
D: Fixes crypto so it compiles with !CONFIG_MODULES, and cleans up two
D: other cases which did #ifdef CONFIG_MODULES.
crypto/api.c +1 -2
@@ -263,8 +263,7 @@ static int c_show(struct seq_file *m, vostruct 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 ) {
include/linux/module.h +9 -0
@@ -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 */
kernel/exec_domain.c +2 -7
@@ -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); }
net/ipv4/netfilter/ip_nat_helper.c +3 -7
@@ -361,8 +361,6 @@ helper_cmp(const struct ip_nat_helper *hreturn 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);