lkml.org 
[lkml]   [2015]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] modules: only use mod->param_lock if CONFIG_MODULES
Date
Simplify params.c by replacing KPARAM_MUTEX() with an inline function
__param_lock(), and replacing KPARAM_IS_LOCKED() with direct calls to
mutex_is_locked(). Inside __param_lock(), only (conditionally) return
mod->param_lock #ifdef CONFIG_MODULES; if there are no modules just
return the built-in param_lock.

Since "struct module" isn't defined if !CONFIG_MODULES, we must leave
out the code that returns mod->param_lock if there are no modules.

Signed-off-by: Dan Streetman <ddstreet@ieee.org>
---
kernel/params.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/kernel/params.c b/kernel/params.c
index 8890d0b..9c955cd 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -29,8 +29,14 @@
static DEFINE_MUTEX(param_lock);

/* 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_IS_LOCKED(mod) mutex_is_locked(KPARAM_MUTEX(mod))
+static inline struct mutex *__param_lock(struct module *mod)
+{
+#ifdef CONFIG_MODULES
+ return mod ? &mod->param_lock : &param_lock;
+#else
+ return &param_lock;
+#endif
+}

/* This just allows us to keep track of which parameters are kmalloced. */
struct kmalloced_param {
@@ -459,7 +465,7 @@ static int param_array(struct module *mod,
/* nul-terminate and parse */
save = val[len];
((char *)val)[len] = '\0';
- BUG_ON(!KPARAM_IS_LOCKED(mod));
+ BUG_ON(!mutex_is_locked(__param_lock(mod)));
ret = set(val, &kp);

if (ret != 0)
@@ -496,7 +502,7 @@ static int param_array_get(char *buffer, const struct kernel_param *kp)
if (i)
buffer[off++] = ',';
p.arg = arr->elem + arr->elemsize * i;
- BUG_ON(!KPARAM_IS_LOCKED(p.mod));
+ BUG_ON(!mutex_is_locked(__param_lock(p.mod)));
ret = arr->ops->get(buffer + off, &p);
if (ret < 0)
return ret;
@@ -618,12 +624,12 @@ static ssize_t param_attr_store(struct module_attribute *mattr,

void kernel_param_lock(struct module *mod)
{
- mutex_lock(KPARAM_MUTEX(mod));
+ mutex_lock(__param_lock(mod));
}

void kernel_param_unlock(struct module *mod)
{
- mutex_unlock(KPARAM_MUTEX(mod));
+ mutex_unlock(__param_lock(mod));
}

#ifdef CONFIG_SYSFS
--
2.1.0


\
 
 \ /
  Last update: 2015-06-24 21:01    [W:0.047 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site