Skip to content

Commit 89287c1

Browse files
keesgregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Scott Branden <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0fa8e08 commit 89287c1

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

drivers/base/firmware_loader/fallback.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,11 @@ fw_create_instance(struct firmware *firmware, const char *fw_name,
490490
/**
491491
* fw_load_sysfs_fallback() - load a firmware via the sysfs fallback mechanism
492492
* @fw_sysfs: firmware sysfs information for the firmware to load
493-
* @opt_flags: flags of options, FW_OPT_*
494493
* @timeout: timeout to wait for the load
495494
*
496495
* In charge of constructing a sysfs fallback interface for firmware loading.
497496
**/
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)
500498
{
501499
int retval = 0;
502500
struct device *f_dev = &fw_sysfs->dev;
@@ -518,7 +516,7 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs,
518516
list_add(&fw_priv->pending_list, &pending_fw_head);
519517
mutex_unlock(&fw_lock);
520518

521-
if (opt_flags & FW_OPT_UEVENT) {
519+
if (fw_priv->opt_flags & FW_OPT_UEVENT) {
522520
fw_priv->need_uevent = true;
523521
dev_set_uevent_suppress(f_dev, false);
524522
dev_dbg(f_dev, "firmware: requesting %s\n", fw_priv->fw_name);
@@ -580,10 +578,10 @@ static int fw_load_from_user_helper(struct firmware *firmware,
580578
}
581579

582580
fw_sysfs->fw_priv = firmware->priv;
583-
ret = fw_load_sysfs_fallback(fw_sysfs, opt_flags, timeout);
581+
ret = fw_load_sysfs_fallback(fw_sysfs, timeout);
584582

585583
if (!ret)
586-
ret = assign_fw(firmware, device, opt_flags);
584+
ret = assign_fw(firmware, device);
587585

588586
out_unlock:
589587
usermodehelper_read_unlock();
@@ -625,7 +623,6 @@ static bool fw_run_sysfs_fallback(u32 opt_flags)
625623
* @fw: pointer to firmware image
626624
* @name: name of firmware file to look for
627625
* @device: device for which firmware is being loaded
628-
* @opt_flags: options to control firmware loading behaviour
629626
* @ret: return value from direct lookup which triggered the fallback mechanism
630627
*
631628
* This function is called if direct lookup for the firmware failed, it enables

drivers/base/firmware_loader/fallback.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ static inline void unregister_sysfs_loader(void)
6767
#endif /* CONFIG_FW_LOADER_USER_HELPER */
6868

6969
#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);
7171
#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)
7473
{
7574
return -ENOENT;
7675
}

drivers/base/firmware_loader/fallback_platform.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
#include "fallback.h"
99
#include "firmware.h"
1010

11-
int firmware_fallback_platform(struct fw_priv *fw_priv, u32 opt_flags)
11+
int firmware_fallback_platform(struct fw_priv *fw_priv)
1212
{
1313
const u8 *data;
1414
size_t size;
1515
int rc;
1616

17-
if (!(opt_flags & FW_OPT_FALLBACK_PLATFORM))
17+
if (!(fw_priv->opt_flags & FW_OPT_FALLBACK_PLATFORM))
1818
return -ENOENT;
1919

2020
rc = security_kernel_load_data(LOADING_FIRMWARE, true);

drivers/base/firmware_loader/firmware.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct fw_priv {
6868
void *data;
6969
size_t size;
7070
size_t allocated_size;
71+
u32 opt_flags;
7172
#ifdef CONFIG_FW_LOADER_PAGED_BUF
7273
bool is_paged_buf;
7374
struct page **pages;
@@ -136,7 +137,7 @@ static inline void fw_state_done(struct fw_priv *fw_priv)
136137
__fw_state_set(fw_priv, FW_STATUS_DONE);
137138
}
138139

139-
int assign_fw(struct firmware *fw, struct device *device, u32 opt_flags);
140+
int assign_fw(struct firmware *fw, struct device *device);
140141

141142
#ifdef CONFIG_FW_LOADER_PAGED_BUF
142143
void fw_free_paged_buf(struct fw_priv *fw_priv);

drivers/base/firmware_loader/main.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ static int fw_cache_piggyback_on_request(const char *name);
168168

169169
static struct fw_priv *__allocate_fw_priv(const char *fw_name,
170170
struct firmware_cache *fwc,
171-
void *dbuf, size_t size)
171+
void *dbuf,
172+
size_t size,
173+
u32 opt_flags)
172174
{
173175
struct fw_priv *fw_priv;
174176

@@ -186,6 +188,7 @@ static struct fw_priv *__allocate_fw_priv(const char *fw_name,
186188
fw_priv->fwc = fwc;
187189
fw_priv->data = dbuf;
188190
fw_priv->allocated_size = size;
191+
fw_priv->opt_flags = opt_flags;
189192
fw_state_init(fw_priv);
190193
#ifdef CONFIG_FW_LOADER_USER_HELPER
191194
INIT_LIST_HEAD(&fw_priv->pending_list);
@@ -210,8 +213,10 @@ static struct fw_priv *__lookup_fw_priv(const char *fw_name)
210213
/* Returns 1 for batching firmware requests with the same name */
211214
static int alloc_lookup_fw_priv(const char *fw_name,
212215
struct firmware_cache *fwc,
213-
struct fw_priv **fw_priv, void *dbuf,
214-
size_t size, u32 opt_flags)
216+
struct fw_priv **fw_priv,
217+
void *dbuf,
218+
size_t size,
219+
u32 opt_flags)
215220
{
216221
struct fw_priv *tmp;
217222

@@ -227,7 +232,7 @@ static int alloc_lookup_fw_priv(const char *fw_name,
227232
}
228233
}
229234

230-
tmp = __allocate_fw_priv(fw_name, fwc, dbuf, size);
235+
tmp = __allocate_fw_priv(fw_name, fwc, dbuf, size, opt_flags);
231236
if (tmp) {
232237
INIT_LIST_HEAD(&tmp->list);
233238
if (!(opt_flags & FW_OPT_NOCACHE))
@@ -640,7 +645,7 @@ static int fw_add_devm_name(struct device *dev, const char *name)
640645
}
641646
#endif
642647

643-
int assign_fw(struct firmware *fw, struct device *device, u32 opt_flags)
648+
int assign_fw(struct firmware *fw, struct device *device)
644649
{
645650
struct fw_priv *fw_priv = fw->priv;
646651
int ret;
@@ -659,8 +664,8 @@ int assign_fw(struct firmware *fw, struct device *device, u32 opt_flags)
659664
* should be fixed in devres or driver core.
660665
*/
661666
/* don't cache firmware handled without uevent */
662-
if (device && (opt_flags & FW_OPT_UEVENT) &&
663-
!(opt_flags & FW_OPT_NOCACHE)) {
667+
if (device && (fw_priv->opt_flags & FW_OPT_UEVENT) &&
668+
!(fw_priv->opt_flags & FW_OPT_NOCACHE)) {
664669
ret = fw_add_devm_name(device, fw_priv->fw_name);
665670
if (ret) {
666671
mutex_unlock(&fw_lock);
@@ -672,7 +677,7 @@ int assign_fw(struct firmware *fw, struct device *device, u32 opt_flags)
672677
* After caching firmware image is started, let it piggyback
673678
* on request firmware.
674679
*/
675-
if (!(opt_flags & FW_OPT_NOCACHE) &&
680+
if (!(fw_priv->opt_flags & FW_OPT_NOCACHE) &&
676681
fw_priv->fwc->state == FW_LOADER_START_CACHE) {
677682
if (fw_cache_piggyback_on_request(fw_priv->fw_name))
678683
kref_get(&fw_priv->ref);
@@ -783,7 +788,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
783788
#endif
784789

785790
if (ret == -ENOENT)
786-
ret = firmware_fallback_platform(fw->priv, opt_flags);
791+
ret = firmware_fallback_platform(fw->priv);
787792

788793
if (ret) {
789794
if (!(opt_flags & FW_OPT_NO_WARN))
@@ -792,7 +797,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
792797
name, ret);
793798
ret = firmware_fallback_sysfs(fw, name, device, opt_flags, ret);
794799
} else
795-
ret = assign_fw(fw, device, opt_flags);
800+
ret = assign_fw(fw, device);
796801

797802
out:
798803
if (ret < 0) {

0 commit comments

Comments
 (0)