Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: add firmware_request_nowarn() - load firmware without warnings

Currently the firmware loader only exposes one silent path for querying
optional firmware, and that is firmware_request_direct(). This function
also disables the sysfs fallback mechanism, which might not always be the
desired behaviour [0].

This patch introduces a variations of request_firmware() that enable the
caller to disable the undesired warning messages but enables the sysfs
fallback mechanism. This is equivalent to adding FW_OPT_NO_WARN to the
old behaviour.

[0]: https://git.kernel.org/linus/c0cc00f250e1

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Luis R. Rodriguez <mcgrof@kernel.org>
[mcgrof: used the old API calls as the full rename is not done yet, and
add the caller for when FW_LOADER is disabled, enhance documentation ]
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andres Rodriguez and committed by
Greg Kroah-Hartman
7dcc0134 27d5d7dc

+42
+5
Documentation/driver-api/firmware/request_firmware.rst
··· 20 20 .. kernel-doc:: drivers/base/firmware_loader/main.c 21 21 :functions: request_firmware 22 22 23 + firmware_request_nowarn 24 + ----------------------- 25 + .. kernel-doc:: drivers/base/firmware_loader/main.c 26 + :functions: firmware_request_nowarn 27 + 23 28 request_firmware_direct 24 29 ----------------------- 25 30 .. kernel-doc:: drivers/base/firmware_loader/main.c
+27
drivers/base/firmware_loader/main.c
··· 632 632 EXPORT_SYMBOL(request_firmware); 633 633 634 634 /** 635 + * firmware_request_nowarn() - request for an optional fw module 636 + * @firmware: pointer to firmware image 637 + * @name: name of firmware file 638 + * @device: device for which firmware is being loaded 639 + * 640 + * This function is similar in behaviour to request_firmware(), except 641 + * it doesn't produce warning messages when the file is not found. 642 + * The sysfs fallback mechanism is enabled if direct filesystem lookup fails, 643 + * however, however failures to find the firmware file with it are still 644 + * suppressed. It is therefore up to the driver to check for the return value 645 + * of this call and to decide when to inform the users of errors. 646 + **/ 647 + int firmware_request_nowarn(const struct firmware **firmware, const char *name, 648 + struct device *device) 649 + { 650 + int ret; 651 + 652 + /* Need to pin this module until return */ 653 + __module_get(THIS_MODULE); 654 + ret = _request_firmware(firmware, name, device, NULL, 0, 655 + FW_OPT_UEVENT | FW_OPT_NO_WARN); 656 + module_put(THIS_MODULE); 657 + return ret; 658 + } 659 + EXPORT_SYMBOL_GPL(firmware_request_nowarn); 660 + 661 + /** 635 662 * request_firmware_direct() - load firmware directly without usermode helper 636 663 * @firmware_p: pointer to firmware image 637 664 * @name: name of firmware file
+10
include/linux/firmware.h
··· 42 42 #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE)) 43 43 int request_firmware(const struct firmware **fw, const char *name, 44 44 struct device *device); 45 + int firmware_request_nowarn(const struct firmware **fw, const char *name, 46 + struct device *device); 45 47 int request_firmware_nowait( 46 48 struct module *module, bool uevent, 47 49 const char *name, struct device *device, gfp_t gfp, void *context, ··· 61 59 { 62 60 return -EINVAL; 63 61 } 62 + 63 + static inline int firmware_request_nowarn(const struct firmware **fw, 64 + const char *name, 65 + struct device *device) 66 + { 67 + return -EINVAL; 68 + } 69 + 64 70 static inline int request_firmware_nowait( 65 71 struct module *module, bool uevent, 66 72 const char *name, struct device *device, gfp_t gfp, void *context,