Skip to content

Commit fe2e39d

Browse files
committed
firmware_class: Rework usermodehelper check
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> Cc: stable@vger.kernel.org
1 parent 9a4768d commit fe2e39d

3 files changed

Lines changed: 18 additions & 22 deletions

File tree

‎drivers/base/firmware_class.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,10 @@ static int _request_firmware(const struct firmware **firmware_p,
533533
return 0;
534534
}
535535

536-
read_lock_usermodehelper();
537-
538-
if (WARN_ON(usermodehelper_is_disabled())) {
536+
retval = usermodehelper_read_trylock();
537+
if (WARN_ON(retval)) {
539538
dev_err(device, "firmware: %s will not be loaded\n", name);
540-
retval = -EBUSY;
541-
goto out;
539+
goto out_nolock;
542540
}
543541

544542
if (uevent)
@@ -573,8 +571,9 @@ static int _request_firmware(const struct firmware **firmware_p,
573571
fw_destroy_instance(fw_priv);
574572

575573
out:
576-
read_unlock_usermodehelper();
574+
usermodehelper_read_unlock();
577575

576+
out_nolock:
578577
if (retval) {
579578
release_firmware(firmware);
580579
*firmware_p = NULL;

‎include/linux/kmod.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ extern void usermodehelper_init(void);
114114

115115
extern int usermodehelper_disable(void);
116116
extern void usermodehelper_enable(void);
117-
extern bool usermodehelper_is_disabled(void);
118-
extern void read_lock_usermodehelper(void);
119-
extern void read_unlock_usermodehelper(void);
117+
extern int usermodehelper_read_trylock(void);
118+
extern void usermodehelper_read_unlock(void);
120119

121120
#endif /* __LINUX_KMOD_H__ */

‎kernel/kmod.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,24 @@ static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);
339339
*/
340340
#define RUNNING_HELPERS_TIMEOUT (5 * HZ)
341341

342-
void read_lock_usermodehelper(void)
342+
int usermodehelper_read_trylock(void)
343343
{
344+
int ret = 0;
345+
344346
down_read(&umhelper_sem);
347+
if (usermodehelper_disabled) {
348+
up_read(&umhelper_sem);
349+
ret = -EAGAIN;
350+
}
351+
return ret;
345352
}
346-
EXPORT_SYMBOL_GPL(read_lock_usermodehelper);
353+
EXPORT_SYMBOL_GPL(usermodehelper_read_trylock);
347354

348-
void read_unlock_usermodehelper(void)
355+
void usermodehelper_read_unlock(void)
349356
{
350357
up_read(&umhelper_sem);
351358
}
352-
EXPORT_SYMBOL_GPL(read_unlock_usermodehelper);
359+
EXPORT_SYMBOL_GPL(usermodehelper_read_unlock);
353360

354361
/**
355362
* usermodehelper_disable - prevent new helpers from being started
@@ -390,15 +397,6 @@ void usermodehelper_enable(void)
390397
up_write(&umhelper_sem);
391398
}
392399

393-
/**
394-
* usermodehelper_is_disabled - check if new helpers are allowed to be started
395-
*/
396-
bool usermodehelper_is_disabled(void)
397-
{
398-
return usermodehelper_disabled;
399-
}
400-
EXPORT_SYMBOL_GPL(usermodehelper_is_disabled);
401-
402400
static void helper_lock(void)
403401
{
404402
atomic_inc(&running_helpers);

0 commit comments

Comments
 (0)