request_module_fmt(char "fmt, ...)
PATCH 1/1 request_module_fmt(char "fmt, ...)
We do this all over the kernel, badly. Many people use sprintf, others use snprintf but don't seem to have noticed they need to put the trailing zero into the buffer if it truncates, etc.
If we put it in one place, we can get it right.
I didn't just change the prototype of request_module() because that would cause stuff like 'ifconfig eth%s up' to cause oopsen.
Untested -- 2.5 didn't even get to a prompt last time I tried to boot it a week or so ago. Does compile though :)
===== include/linux/kmod.h 1.3 vs edited =====
include/linux/kmod.h +4 -0
@@ -25,8 +25,12 @@#ifdef CONFIG_KMOD extern int request_module (const char * name); +extern int request_module_fmt (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 )));#else static inline int request_module (const char * name) {return -ENOSYS ; } +static inline int request_module_fmt (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 ))) {return -ENOSYS ; }#endif #define try_then_request_module (x, mod) ((x) ?: request_module(mod), (x))
===== kernel/kmod.c 1.25 vs edited =====
kernel/kmod.c +23 -4
@@ -110,6 +110,29 @@atomic_dec (&kmod_concurrent); return ret; } + +int request_module_fmt (const char *fmt, ...) +{ +char name[32 ]; +va_list args; +int ret; + + name[sizeof (name)-1 ] =0 ; + +va_start (args, fmt); + ret =vsnprintf (name,sizeof (name)-1 , fmt, args); +va_end (args); + +if (ret >=sizeof (name)-1 ) { +printk (KERN_WARNING "Module name \"%s\"... too long.\n" , + name); +return -ENAMETOOLONG ; + } +return request_module (name); +} + +EXPORT_SYMBOL (request_module); +EXPORT_SYMBOL (request_module_fmt);#endif /* CONFIG_KMOD */ #ifdef CONFIG_HOTPLUG
@@ -273,8 +296,4 @@ }EXPORT_SYMBOL (call_usermodehelper); - -#ifdef CONFIG_KMOD -EXPORT_SYMBOL (request_module); -#endif
Signature · 1 line
dwmw2