]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
firmware_class: Rework usermodehelper check
authorRafael J. Wysocki <rjw@sisk.pl>
Wed, 28 Mar 2012 21:29:45 +0000 (23:29 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Apr 2012 16:13:53 +0000 (09:13 -0700)
commit fe2e39d8782d885755139304d8dba0b3e5bfa878 upstream.

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@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/firmware_class.c
include/linux/kmod.h
kernel/kmod.c

index 6c9387d646ecccc0d9c8fa62f6f8ce54593894a9..deee871e509c137e142c3bd712e01a908274fe98 100644 (file)
@@ -533,12 +533,10 @@ static int _request_firmware(const struct firmware **firmware_p,
                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 struct firmware **firmware_p,
        fw_destroy_instance(fw_priv);
 
 out:
-       read_unlock_usermodehelper();
+       usermodehelper_read_unlock();
 
+out_nolock:
        if (retval) {
                release_firmware(firmware);
                *firmware_p = NULL;
index 722f477c4ef78d1d8144ac60118d1827f897cc7b..b25e2b80c05959022360961f997280730af8ea56 100644 (file)
@@ -116,8 +116,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 a0a88543934ec44a2218c8a654f378501d754336..3973cde0cabf077aa823e8806e4959940198f6d5 100644 (file)
@@ -296,17 +296,24 @@ static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);
  */
 #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
@@ -347,15 +354,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);