From 5a1379e8748a5cfa3eb068f812d61bde849ef76c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 4 Jun 2014 17:48:15 +0200 Subject: firmware loader: allow disabling of udev as firmware loader [The patch was originally proposed by Tom Gundersen, and rewritten afterwards by me; most of changelogs below borrowed from Tom's original patch -- tiwai] Currently (at least) the dell-rbu driver selects FW_LOADER_USER_HELPER, which means that distros can't really stop loading firmware through udev without breaking other users (though some have). Ideally we would remove/disable the udev firmware helper in both the kernel and in udev, but if we were to disable it in udev and not the kernel, the result would be (seemingly) hung kernels as no one would be around to cancel firmware requests. This patch allows udev firmware loading to be disabled while still allowing non-udev firmware loading, as done by the dell-rbu driver, to continue working. This is achieved by only using the fallback mechanism when the uevent is suppressed. The patch renames the user-selectable Kconfig from FW_LOADER_USER_HELPER to FW_LOADER_USER_HELPER_FALLBACK, and the former is reverse-selected by the latter or the drivers that need userhelper like dell-rbu. Also, the "default y" is removed together with this change, since it's been deprecated in udev upstream, thus rather better to disable it nowadays. Tested with FW_LOADER_USER_HELPER=n LATTICE_ECP3_CONFIG=y DELL_RBU=y and udev without the firmware loading support, but I don't have the hardware to test the lattice/dell drivers, so additional testing would be appreciated. Reviewed-by: Tom Gundersen Cc: Ming Lei Cc: Abhay Salunke Cc: Stefan Roese Cc: Arnd Bergmann Cc: Kay Sievers Tested-by: Balaji Singh Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- include/linux/firmware.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/linux/firmware.h') diff --git a/include/linux/firmware.h b/include/linux/firmware.h index 59529330efd..67e5b801af0 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -68,7 +68,7 @@ static inline void release_firmware(const struct firmware *fw) #endif -#ifdef CONFIG_FW_LOADER_USER_HELPER +#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK int request_firmware_direct(const struct firmware **fw, const char *name, struct device *device); #else -- cgit v1.2.3-70-g09d2 From c868edf42b4db89907b467c92b7f035c8c1cb0e5 Mon Sep 17 00:00:00 2001 From: "Luis R. Rodriguez" Date: Wed, 2 Jul 2014 09:55:05 -0700 Subject: firmware loader: inform direct failure when udev loader is disabled Now that the udev firmware loader is optional request_firmware() will not provide any information on the kernel ring buffer if direct firmware loading failed and udev firmware loading is disabled. If no information is needed request_firmware_direct() should be used for optional firmware, at which point drivers can take on the onus over informing of any failures, if udev firmware loading is disabled though we should at the very least provide some sort of information as when the udev loader was enabled by default back in the days. With this change with a simple firmware load test module [0]: Example output without FW_LOADER_USER_HELPER_FALLBACK platform fake-dev.0: Direct firmware load for fake.bin failed with error -2 Example with FW_LOADER_USER_HELPER_FALLBACK platform fake-dev.0: Direct firmware load for fake.bin failed with error -2 platform fake-dev.0: Falling back to user helper Without this change without FW_LOADER_USER_HELPER_FALLBACK we get no output logged upon failure. Cc: Tom Gundersen Cc: Ming Lei Cc: Abhay Salunke Cc: Stefan Roese Cc: Arnd Bergmann Cc: Kay Sievers Signed-off-by: Luis R. Rodriguez Reviewed-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 13 +++++++------ include/linux/firmware.h | 15 ++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'include/linux/firmware.h') diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 28bc6db9fbf..124d50ceb11 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -109,6 +109,7 @@ static inline long firmware_loading_timeout(void) #else #define FW_OPT_FALLBACK 0 #endif +#define FW_OPT_NO_WARN (1U << 3) struct firmware_cache { /* firmware_buf instance will be added into the below list */ @@ -1105,10 +1106,11 @@ _request_firmware(const struct firmware **firmware_p, const char *name, ret = fw_get_filesystem_firmware(device, fw->priv); if (ret) { - if (opt_flags & FW_OPT_USERHELPER) { + if (!(opt_flags & FW_OPT_NO_WARN)) dev_warn(device, - "Direct firmware load failed with error %d\n", - ret); + "Direct firmware load for %s failed with error %d\n", + name, ret); + if (opt_flags & FW_OPT_USERHELPER) { dev_warn(device, "Falling back to user helper\n"); ret = fw_load_from_user_helper(fw, name, device, opt_flags, timeout); @@ -1165,7 +1167,6 @@ request_firmware(const struct firmware **firmware_p, const char *name, } EXPORT_SYMBOL(request_firmware); -#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK /** * request_firmware: - load firmware directly without usermode helper * @firmware_p: pointer to firmware image @@ -1182,12 +1183,12 @@ int request_firmware_direct(const struct firmware **firmware_p, { int ret; __module_get(THIS_MODULE); - ret = _request_firmware(firmware_p, name, device, FW_OPT_UEVENT); + ret = _request_firmware(firmware_p, name, device, + FW_OPT_UEVENT | FW_OPT_NO_WARN); module_put(THIS_MODULE); return ret; } EXPORT_SYMBOL_GPL(request_firmware_direct); -#endif /** * release_firmware: - release the resource associated with a firmware image diff --git a/include/linux/firmware.h b/include/linux/firmware.h index 67e5b801af0..5c41c5e75b5 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -45,6 +45,8 @@ int request_firmware_nowait( struct module *module, bool uevent, const char *name, struct device *device, gfp_t gfp, void *context, void (*cont)(const struct firmware *fw, void *context)); +int request_firmware_direct(const struct firmware **fw, const char *name, + struct device *device); void release_firmware(const struct firmware *fw); #else @@ -66,13 +68,12 @@ static inline void release_firmware(const struct firmware *fw) { } -#endif +static inline int request_firmware_direct(const struct firmware **fw, + const char *name, + struct device *device) +{ + return -EINVAL; +} -#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK -int request_firmware_direct(const struct firmware **fw, const char *name, - struct device *device); -#else -#define request_firmware_direct request_firmware #endif - #endif -- cgit v1.2.3-70-g09d2