Skip to content

Commit a144c6a

Browse files
committed
PM: Print a warning if firmware is requested when tasks are frozen
Some drivers erroneously use request_firmware() from their ->resume() (or ->thaw(), or ->restore()) callbacks, which is not going to work unless the firmware has been built in. This causes system resume to stall until the firmware-loading timeout expires, which makes users think that the resume has failed and reboot their machines unnecessarily. For this reason, make _request_firmware() print a warning and return immediately with error code if it has been called when tasks are frozen and it's impossible to start any new usermode helpers. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Reviewed-by: Valdis Kletnieks <valdis.kletnieks@vt.edu>
1 parent e1866b3 commit a144c6a

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎drivers/base/firmware_class.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ static int _request_firmware(const struct firmware **firmware_p,
521521
if (!firmware_p)
522522
return -EINVAL;
523523

524+
if (WARN_ON(usermodehelper_is_disabled())) {
525+
dev_err(device, "firmware: %s will not be loaded\n", name);
526+
return -EBUSY;
527+
}
528+
524529
*firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
525530
if (!firmware) {
526531
dev_err(device, "%s: kmalloc(struct firmware) failed\n",

‎include/linux/kmod.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
111111

112112
extern void usermodehelper_init(void);
113113

114+
#ifdef CONFIG_PM_SLEEP
114115
extern int usermodehelper_disable(void);
115116
extern void usermodehelper_enable(void);
117+
extern bool usermodehelper_is_disabled(void);
118+
#else
119+
static inline bool usermodehelper_is_disabled(void) { return false; }
120+
#endif
116121

117122
#endif /* __LINUX_KMOD_H__ */

‎kernel/kmod.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ void usermodehelper_enable(void)
301301
usermodehelper_disabled = 0;
302302
}
303303

304+
/**
305+
* usermodehelper_is_disabled - check if new helpers are allowed to be started
306+
*/
307+
bool usermodehelper_is_disabled(void)
308+
{
309+
return usermodehelper_disabled;
310+
}
311+
EXPORT_SYMBOL_GPL(usermodehelper_is_disabled);
312+
304313
static void helper_lock(void)
305314
{
306315
atomic_inc(&running_helpers);

0 commit comments

Comments
 (0)