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

firmware: Store opt_flags in fw_priv

Instead of passing opt_flags around so much, store it in the private
structure so it can be examined by internals without needing to add more
arguments to functions.

Co-developed-by: Scott Branden <scott.branden@broadcom.com>
Signed-off-by: Scott Branden <scott.branden@broadcom.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20201002173828.2099543-15-keescook@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kees Cook and committed by
Greg Kroah-Hartman
89287c16 0fa8e084

+25 -23
+4 -7
drivers/base/firmware_loader/fallback.c
··· 490 490 /** 491 491 * fw_load_sysfs_fallback() - load a firmware via the sysfs fallback mechanism 492 492 * @fw_sysfs: firmware sysfs information for the firmware to load 493 - * @opt_flags: flags of options, FW_OPT_* 494 493 * @timeout: timeout to wait for the load 495 494 * 496 495 * In charge of constructing a sysfs fallback interface for firmware loading. 497 496 **/ 498 - static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, 499 - u32 opt_flags, long timeout) 497 + static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, long timeout) 500 498 { 501 499 int retval = 0; 502 500 struct device *f_dev = &fw_sysfs->dev; ··· 516 518 list_add(&fw_priv->pending_list, &pending_fw_head); 517 519 mutex_unlock(&fw_lock); 518 520 519 - if (opt_flags & FW_OPT_UEVENT) { 521 + if (fw_priv->opt_flags & FW_OPT_UEVENT) { 520 522 fw_priv->need_uevent = true; 521 523 dev_set_uevent_suppress(f_dev, false); 522 524 dev_dbg(f_dev, "firmware: requesting %s\n", fw_priv->fw_name); ··· 578 580 } 579 581 580 582 fw_sysfs->fw_priv = firmware->priv; 581 - ret = fw_load_sysfs_fallback(fw_sysfs, opt_flags, timeout); 583 + ret = fw_load_sysfs_fallback(fw_sysfs, timeout); 582 584 583 585 if (!ret) 584 - ret = assign_fw(firmware, device, opt_flags); 586 + ret = assign_fw(firmware, device); 585 587 586 588 out_unlock: 587 589 usermodehelper_read_unlock(); ··· 623 625 * @fw: pointer to firmware image 624 626 * @name: name of firmware file to look for 625 627 * @device: device for which firmware is being loaded 626 - * @opt_flags: options to control firmware loading behaviour 627 628 * @ret: return value from direct lookup which triggered the fallback mechanism 628 629 * 629 630 * This function is called if direct lookup for the firmware failed, it enables
+2 -3
drivers/base/firmware_loader/fallback.h
··· 67 67 #endif /* CONFIG_FW_LOADER_USER_HELPER */ 68 68 69 69 #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE 70 - int firmware_fallback_platform(struct fw_priv *fw_priv, u32 opt_flags); 70 + int firmware_fallback_platform(struct fw_priv *fw_priv); 71 71 #else 72 - static inline int firmware_fallback_platform(struct fw_priv *fw_priv, 73 - u32 opt_flags) 72 + static inline int firmware_fallback_platform(struct fw_priv *fw_priv) 74 73 { 75 74 return -ENOENT; 76 75 }
+2 -2
drivers/base/firmware_loader/fallback_platform.c
··· 8 8 #include "fallback.h" 9 9 #include "firmware.h" 10 10 11 - int firmware_fallback_platform(struct fw_priv *fw_priv, u32 opt_flags) 11 + int firmware_fallback_platform(struct fw_priv *fw_priv) 12 12 { 13 13 const u8 *data; 14 14 size_t size; 15 15 int rc; 16 16 17 - if (!(opt_flags & FW_OPT_FALLBACK_PLATFORM)) 17 + if (!(fw_priv->opt_flags & FW_OPT_FALLBACK_PLATFORM)) 18 18 return -ENOENT; 19 19 20 20 rc = security_kernel_load_data(LOADING_FIRMWARE, true);
+2 -1
drivers/base/firmware_loader/firmware.h
··· 68 68 void *data; 69 69 size_t size; 70 70 size_t allocated_size; 71 + u32 opt_flags; 71 72 #ifdef CONFIG_FW_LOADER_PAGED_BUF 72 73 bool is_paged_buf; 73 74 struct page **pages; ··· 137 136 __fw_state_set(fw_priv, FW_STATUS_DONE); 138 137 } 139 138 140 - int assign_fw(struct firmware *fw, struct device *device, u32 opt_flags); 139 + int assign_fw(struct firmware *fw, struct device *device); 141 140 142 141 #ifdef CONFIG_FW_LOADER_PAGED_BUF 143 142 void fw_free_paged_buf(struct fw_priv *fw_priv);
+15 -10
drivers/base/firmware_loader/main.c
··· 168 168 169 169 static struct fw_priv *__allocate_fw_priv(const char *fw_name, 170 170 struct firmware_cache *fwc, 171 - void *dbuf, size_t size) 171 + void *dbuf, 172 + size_t size, 173 + u32 opt_flags) 172 174 { 173 175 struct fw_priv *fw_priv; 174 176 ··· 188 186 fw_priv->fwc = fwc; 189 187 fw_priv->data = dbuf; 190 188 fw_priv->allocated_size = size; 189 + fw_priv->opt_flags = opt_flags; 191 190 fw_state_init(fw_priv); 192 191 #ifdef CONFIG_FW_LOADER_USER_HELPER 193 192 INIT_LIST_HEAD(&fw_priv->pending_list); ··· 213 210 /* Returns 1 for batching firmware requests with the same name */ 214 211 static int alloc_lookup_fw_priv(const char *fw_name, 215 212 struct firmware_cache *fwc, 216 - struct fw_priv **fw_priv, void *dbuf, 217 - size_t size, u32 opt_flags) 213 + struct fw_priv **fw_priv, 214 + void *dbuf, 215 + size_t size, 216 + u32 opt_flags) 218 217 { 219 218 struct fw_priv *tmp; 220 219 ··· 232 227 } 233 228 } 234 229 235 - tmp = __allocate_fw_priv(fw_name, fwc, dbuf, size); 230 + tmp = __allocate_fw_priv(fw_name, fwc, dbuf, size, opt_flags); 236 231 if (tmp) { 237 232 INIT_LIST_HEAD(&tmp->list); 238 233 if (!(opt_flags & FW_OPT_NOCACHE)) ··· 645 640 } 646 641 #endif 647 642 648 - int assign_fw(struct firmware *fw, struct device *device, u32 opt_flags) 643 + int assign_fw(struct firmware *fw, struct device *device) 649 644 { 650 645 struct fw_priv *fw_priv = fw->priv; 651 646 int ret; ··· 664 659 * should be fixed in devres or driver core. 665 660 */ 666 661 /* don't cache firmware handled without uevent */ 667 - if (device && (opt_flags & FW_OPT_UEVENT) && 668 - !(opt_flags & FW_OPT_NOCACHE)) { 662 + if (device && (fw_priv->opt_flags & FW_OPT_UEVENT) && 663 + !(fw_priv->opt_flags & FW_OPT_NOCACHE)) { 669 664 ret = fw_add_devm_name(device, fw_priv->fw_name); 670 665 if (ret) { 671 666 mutex_unlock(&fw_lock); ··· 677 672 * After caching firmware image is started, let it piggyback 678 673 * on request firmware. 679 674 */ 680 - if (!(opt_flags & FW_OPT_NOCACHE) && 675 + if (!(fw_priv->opt_flags & FW_OPT_NOCACHE) && 681 676 fw_priv->fwc->state == FW_LOADER_START_CACHE) { 682 677 if (fw_cache_piggyback_on_request(fw_priv->fw_name)) 683 678 kref_get(&fw_priv->ref); ··· 788 783 #endif 789 784 790 785 if (ret == -ENOENT) 791 - ret = firmware_fallback_platform(fw->priv, opt_flags); 786 + ret = firmware_fallback_platform(fw->priv); 792 787 793 788 if (ret) { 794 789 if (!(opt_flags & FW_OPT_NO_WARN)) ··· 797 792 name, ret); 798 793 ret = firmware_fallback_sysfs(fw, name, device, opt_flags, ret); 799 794 } else 800 - ret = assign_fw(fw, device, opt_flags); 795 + ret = assign_fw(fw, device); 801 796 802 797 out: 803 798 if (ret < 0) {