[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <201203282320.55385.rjw@sisk.pl>
Date: Wed, 28 Mar 2012 23:20:55 +0200
From: "Rafael J. Wysocki" <rjw@...k.pl>
To: linux-kernel@...r.kernel.org
Cc: Stephen Boyd <sboyd@...eaurora.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Saravana Kannan <skannan@...eaurora.org>,
Kay Sievers <kay.sievers@...y.org>,
Greg KH <gregkh@...uxfoundation.org>,
Christian Lamparter <chunkeey@...glemail.com>,
"Srivatsa S. Bhat" <srivatsa.bhat@...ux.vnet.ibm.com>,
alan@...rguk.ukuu.org.uk,
Linux PM mailing list <linux-pm@...r.kernel.org>
Subject: [PATCH v2 1/8] firmware_class: Rework usermodehelper check
From: Rafael J. Wysocki <rjw@...k.pl>
Instead of two functions, read_lock_usermodehelper() and
usermodehelper_is_disabled(), used in combination, introduce
usermodehelper_read_trylock() that will only return with umhelper_sem
held if usermodehelper_disabled is unset (and will return -EAGAIN
otherwise) and make _request_firmware() use it.
Rename read_unlock_usermodehelper() to
usermodehelper_read_unlock() to follow the naming convention of the
new function.
Signed-off-by: Rafael J. Wysocki <rjw@...k.pl>
Acked-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
drivers/base/firmware_class.c | 11 +++++------
include/linux/kmod.h | 5 ++---
kernel/kmod.c | 24 +++++++++++-------------
3 files changed, 18 insertions(+), 22 deletions(-)
Index: linux/include/linux/kmod.h
===================================================================
--- linux.orig/include/linux/kmod.h
+++ linux/include/linux/kmod.h
@@ -114,8 +114,7 @@ extern void usermodehelper_init(void);
extern int usermodehelper_disable(void);
extern void usermodehelper_enable(void);
-extern bool usermodehelper_is_disabled(void);
-extern void read_lock_usermodehelper(void);
-extern void read_unlock_usermodehelper(void);
+extern int usermodehelper_read_trylock(void);
+extern void usermodehelper_read_unlock(void);
#endif /* __LINUX_KMOD_H__ */
Index: linux/kernel/kmod.c
===================================================================
--- linux.orig/kernel/kmod.c
+++ linux/kernel/kmod.c
@@ -339,17 +339,24 @@ static DECLARE_WAIT_QUEUE_HEAD(running_h
*/
#define RUNNING_HELPERS_TIMEOUT (5 * HZ)
-void read_lock_usermodehelper(void)
+int usermodehelper_read_trylock(void)
{
+ int ret = 0;
+
down_read(&umhelper_sem);
+ if (usermodehelper_disabled) {
+ up_read(&umhelper_sem);
+ ret = -EAGAIN;
+ }
+ return ret;
}
-EXPORT_SYMBOL_GPL(read_lock_usermodehelper);
+EXPORT_SYMBOL_GPL(usermodehelper_read_trylock);
-void read_unlock_usermodehelper(void)
+void usermodehelper_read_unlock(void)
{
up_read(&umhelper_sem);
}
-EXPORT_SYMBOL_GPL(read_unlock_usermodehelper);
+EXPORT_SYMBOL_GPL(usermodehelper_read_unlock);
/**
* usermodehelper_disable - prevent new helpers from being started
@@ -390,15 +397,6 @@ void usermodehelper_enable(void)
up_write(&umhelper_sem);
}
-/**
- * usermodehelper_is_disabled - check if new helpers are allowed to be started
- */
-bool usermodehelper_is_disabled(void)
-{
- return usermodehelper_disabled;
-}
-EXPORT_SYMBOL_GPL(usermodehelper_is_disabled);
-
static void helper_lock(void)
{
atomic_inc(&running_helpers);
Index: linux/drivers/base/firmware_class.c
===================================================================
--- linux.orig/drivers/base/firmware_class.c
+++ linux/drivers/base/firmware_class.c
@@ -533,12 +533,10 @@ static int _request_firmware(const struc
return 0;
}
- read_lock_usermodehelper();
-
- if (WARN_ON(usermodehelper_is_disabled())) {
+ retval = usermodehelper_read_trylock();
+ if (WARN_ON(retval)) {
dev_err(device, "firmware: %s will not be loaded\n", name);
- retval = -EBUSY;
- goto out;
+ goto out_nolock;
}
if (uevent)
@@ -573,8 +571,9 @@ static int _request_firmware(const struc
fw_destroy_instance(fw_priv);
out:
- read_unlock_usermodehelper();
+ usermodehelper_read_unlock();
+out_nolock:
if (retval) {
release_firmware(firmware);
*firmware_p = NULL;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists