提交 cf2fde7b 编写于 作者: R Rusty Russell

param: fix module param locks when !CONFIG_SYSFS.

As Dan Streetman points out, the entire point of locking for is to
stop sysfs accesses, so they're elided entirely in the !SYSFS case.
Reported-by: NStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
上级 38183b9c
...@@ -240,7 +240,9 @@ struct module { ...@@ -240,7 +240,9 @@ struct module {
unsigned int num_syms; unsigned int num_syms;
/* Kernel parameters. */ /* Kernel parameters. */
#ifdef CONFIG_SYSFS
struct mutex param_lock; struct mutex param_lock;
#endif
struct kernel_param *kp; struct kernel_param *kp;
unsigned int num_kp; unsigned int num_kp;
......
...@@ -1820,6 +1820,10 @@ static void mod_sysfs_fini(struct module *mod) ...@@ -1820,6 +1820,10 @@ static void mod_sysfs_fini(struct module *mod)
mod_kobject_put(mod); mod_kobject_put(mod);
} }
static void init_param_lock(struct module *mod)
{
mutex_init(&mod->param_lock);
}
#else /* !CONFIG_SYSFS */ #else /* !CONFIG_SYSFS */
static int mod_sysfs_setup(struct module *mod, static int mod_sysfs_setup(struct module *mod,
...@@ -1842,6 +1846,9 @@ static void del_usage_links(struct module *mod) ...@@ -1842,6 +1846,9 @@ static void del_usage_links(struct module *mod)
{ {
} }
static void init_param_lock(struct module *mod)
{
}
#endif /* CONFIG_SYSFS */ #endif /* CONFIG_SYSFS */
static void mod_sysfs_teardown(struct module *mod) static void mod_sysfs_teardown(struct module *mod)
...@@ -3442,7 +3449,7 @@ static int load_module(struct load_info *info, const char __user *uargs, ...@@ -3442,7 +3449,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
if (err) if (err)
goto unlink_mod; goto unlink_mod;
mutex_init(&mod->param_lock); init_param_lock(mod);
/* Now we've got everything in the final locations, we can /* Now we've got everything in the final locations, we can
* find optional sections. */ * find optional sections. */
......
...@@ -25,12 +25,22 @@ ...@@ -25,12 +25,22 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#ifdef CONFIG_SYSFS
/* Protects all built-in parameters, modules use their own param_lock */ /* Protects all built-in parameters, modules use their own param_lock */
static DEFINE_MUTEX(param_lock); static DEFINE_MUTEX(param_lock);
/* Use the module's mutex, or if built-in use the built-in mutex */ /* Use the module's mutex, or if built-in use the built-in mutex */
#define KPARAM_MUTEX(mod) ((mod) ? &(mod)->param_lock : &param_lock) #define KPARAM_MUTEX(mod) ((mod) ? &(mod)->param_lock : &param_lock)
#define KPARAM_IS_LOCKED(mod) mutex_is_locked(KPARAM_MUTEX(mod))
static inline void check_kparam_locked(struct module *mod)
{
BUG_ON(!mutex_is_locked(KPARAM_MUTEX(mod)));
}
#else
static inline void check_kparam_locked(struct module *mod)
{
}
#endif /* !CONFIG_SYSFS */
/* This just allows us to keep track of which parameters are kmalloced. */ /* This just allows us to keep track of which parameters are kmalloced. */
struct kmalloced_param { struct kmalloced_param {
...@@ -459,7 +469,7 @@ static int param_array(struct module *mod, ...@@ -459,7 +469,7 @@ static int param_array(struct module *mod,
/* nul-terminate and parse */ /* nul-terminate and parse */
save = val[len]; save = val[len];
((char *)val)[len] = '\0'; ((char *)val)[len] = '\0';
BUG_ON(!KPARAM_IS_LOCKED(mod)); check_kparam_locked(mod);
ret = set(val, &kp); ret = set(val, &kp);
if (ret != 0) if (ret != 0)
...@@ -496,7 +506,7 @@ static int param_array_get(char *buffer, const struct kernel_param *kp) ...@@ -496,7 +506,7 @@ static int param_array_get(char *buffer, const struct kernel_param *kp)
if (i) if (i)
buffer[off++] = ','; buffer[off++] = ',';
p.arg = arr->elem + arr->elemsize * i; p.arg = arr->elem + arr->elemsize * i;
BUG_ON(!KPARAM_IS_LOCKED(p.mod)); check_kparam_locked(p.mod);
ret = arr->ops->get(buffer + off, &p); ret = arr->ops->get(buffer + off, &p);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -616,6 +626,7 @@ static ssize_t param_attr_store(struct module_attribute *mattr, ...@@ -616,6 +626,7 @@ static ssize_t param_attr_store(struct module_attribute *mattr,
#define __modinit __init #define __modinit __init
#endif #endif
#ifdef CONFIG_SYSFS
void kernel_param_lock(struct module *mod) void kernel_param_lock(struct module *mod)
{ {
mutex_lock(KPARAM_MUTEX(mod)); mutex_lock(KPARAM_MUTEX(mod));
...@@ -626,7 +637,6 @@ void kernel_param_unlock(struct module *mod) ...@@ -626,7 +637,6 @@ void kernel_param_unlock(struct module *mod)
mutex_unlock(KPARAM_MUTEX(mod)); mutex_unlock(KPARAM_MUTEX(mod));
} }
#ifdef CONFIG_SYSFS
EXPORT_SYMBOL(kernel_param_lock); EXPORT_SYMBOL(kernel_param_lock);
EXPORT_SYMBOL(kernel_param_unlock); EXPORT_SYMBOL(kernel_param_unlock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册