Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753142AbbFXSbl (ORCPT ); Wed, 24 Jun 2015 14:31:41 -0400 Received: from mail-ig0-f174.google.com ([209.85.213.174]:36587 "EHLO mail-ig0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752536AbbFXSbe (ORCPT ); Wed, 24 Jun 2015 14:31:34 -0400 From: Dan Streetman To: Rusty Russell Cc: Stephen Rothwell , linux-next@vger.kernel.org, linux-kernel , Dan Streetman Subject: [PATCH] modules: only use mod->param_lock if CONFIG_MODULES Date: Wed, 24 Jun 2015 14:31:17 -0400 Message-Id: <1435170677-16492-1-git-send-email-ddstreet@ieee.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2464 Lines: 76 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 --- 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 : ¶m_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 : ¶m_lock; +#else + return ¶m_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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/