Skip to content

Commit 11c63e5

Browse files
lynxeye-devvinodkoul
authored andcommitted
firmware: add nowarn variant of request_firmware_nowait()
Device drivers with optional firmware may still want to use the asynchronous firmware loading interface. To avoid printing a warning into the kernel log when the optional firmware is absent, add a nowarn variant of this interface. Signed-off-by: Lucas Stach <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 45a24e4 commit 11c63e5

File tree

2 files changed

+75
-27
lines changed

2 files changed

+75
-27
lines changed

drivers/base/firmware_loader/main.c

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,34 +1172,11 @@ static void request_firmware_work_func(struct work_struct *work)
11721172
kfree(fw_work);
11731173
}
11741174

1175-
/**
1176-
* request_firmware_nowait() - asynchronous version of request_firmware
1177-
* @module: module requesting the firmware
1178-
* @uevent: sends uevent to copy the firmware image if this flag
1179-
* is non-zero else the firmware copy must be done manually.
1180-
* @name: name of firmware file
1181-
* @device: device for which firmware is being loaded
1182-
* @gfp: allocation flags
1183-
* @context: will be passed over to @cont, and
1184-
* @fw may be %NULL if firmware request fails.
1185-
* @cont: function will be called asynchronously when the firmware
1186-
* request is over.
1187-
*
1188-
* Caller must hold the reference count of @device.
1189-
*
1190-
* Asynchronous variant of request_firmware() for user contexts:
1191-
* - sleep for as small periods as possible since it may
1192-
* increase kernel boot time of built-in device drivers
1193-
* requesting firmware in their ->probe() methods, if
1194-
* @gfp is GFP_KERNEL.
1195-
*
1196-
* - can't sleep at all if @gfp is GFP_ATOMIC.
1197-
**/
1198-
int
1199-
request_firmware_nowait(
1175+
1176+
static int _request_firmware_nowait(
12001177
struct module *module, bool uevent,
12011178
const char *name, struct device *device, gfp_t gfp, void *context,
1202-
void (*cont)(const struct firmware *fw, void *context))
1179+
void (*cont)(const struct firmware *fw, void *context), bool nowarn)
12031180
{
12041181
struct firmware_work *fw_work;
12051182

@@ -1217,7 +1194,8 @@ request_firmware_nowait(
12171194
fw_work->context = context;
12181195
fw_work->cont = cont;
12191196
fw_work->opt_flags = FW_OPT_NOWAIT |
1220-
(uevent ? FW_OPT_UEVENT : FW_OPT_USERHELPER);
1197+
(uevent ? FW_OPT_UEVENT : FW_OPT_USERHELPER) |
1198+
(nowarn ? FW_OPT_NO_WARN : 0);
12211199

12221200
if (!uevent && fw_cache_is_setup(device, name)) {
12231201
kfree_const(fw_work->name);
@@ -1236,8 +1214,66 @@ request_firmware_nowait(
12361214
schedule_work(&fw_work->work);
12371215
return 0;
12381216
}
1217+
1218+
/**
1219+
* request_firmware_nowait() - asynchronous version of request_firmware
1220+
* @module: module requesting the firmware
1221+
* @uevent: sends uevent to copy the firmware image if this flag
1222+
* is non-zero else the firmware copy must be done manually.
1223+
* @name: name of firmware file
1224+
* @device: device for which firmware is being loaded
1225+
* @gfp: allocation flags
1226+
* @context: will be passed over to @cont, and
1227+
* @fw may be %NULL if firmware request fails.
1228+
* @cont: function will be called asynchronously when the firmware
1229+
* request is over.
1230+
*
1231+
* Caller must hold the reference count of @device.
1232+
*
1233+
* Asynchronous variant of request_firmware() for user contexts:
1234+
* - sleep for as small periods as possible since it may
1235+
* increase kernel boot time of built-in device drivers
1236+
* requesting firmware in their ->probe() methods, if
1237+
* @gfp is GFP_KERNEL.
1238+
*
1239+
* - can't sleep at all if @gfp is GFP_ATOMIC.
1240+
**/
1241+
int request_firmware_nowait(
1242+
struct module *module, bool uevent,
1243+
const char *name, struct device *device, gfp_t gfp, void *context,
1244+
void (*cont)(const struct firmware *fw, void *context))
1245+
{
1246+
return _request_firmware_nowait(module, uevent, name, device, gfp,
1247+
context, cont, false);
1248+
1249+
}
12391250
EXPORT_SYMBOL(request_firmware_nowait);
12401251

1252+
/**
1253+
* firmware_request_nowait_nowarn() - async version of request_firmware_nowarn
1254+
* @module: module requesting the firmware
1255+
* @name: name of firmware file
1256+
* @device: device for which firmware is being loaded
1257+
* @gfp: allocation flags
1258+
* @context: will be passed over to @cont, and
1259+
* @fw may be %NULL if firmware request fails.
1260+
* @cont: function will be called asynchronously when the firmware
1261+
* request is over.
1262+
*
1263+
* Similar in function to request_firmware_nowait(), but doesn't print a warning
1264+
* when the firmware file could not be found and always sends a uevent to copy
1265+
* the firmware image.
1266+
*/
1267+
int firmware_request_nowait_nowarn(
1268+
struct module *module, const char *name,
1269+
struct device *device, gfp_t gfp, void *context,
1270+
void (*cont)(const struct firmware *fw, void *context))
1271+
{
1272+
return _request_firmware_nowait(module, FW_ACTION_UEVENT, name, device,
1273+
gfp, context, cont, true);
1274+
}
1275+
EXPORT_SYMBOL_GPL(firmware_request_nowait_nowarn);
1276+
12411277
#ifdef CONFIG_FW_CACHE
12421278
static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain);
12431279

include/linux/firmware.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ static inline bool firmware_request_builtin(struct firmware *fw,
9898
#if IS_REACHABLE(CONFIG_FW_LOADER)
9999
int request_firmware(const struct firmware **fw, const char *name,
100100
struct device *device);
101+
int firmware_request_nowait_nowarn(
102+
struct module *module, const char *name,
103+
struct device *device, gfp_t gfp, void *context,
104+
void (*cont)(const struct firmware *fw, void *context));
101105
int firmware_request_nowarn(const struct firmware **fw, const char *name,
102106
struct device *device);
103107
int firmware_request_platform(const struct firmware **fw, const char *name,
@@ -123,6 +127,14 @@ static inline int request_firmware(const struct firmware **fw,
123127
return -EINVAL;
124128
}
125129

130+
static inline int firmware_request_nowait_nowarn(
131+
struct module *module, const char *name,
132+
struct device *device, gfp_t gfp, void *context,
133+
void (*cont)(const struct firmware *fw, void *context))
134+
{
135+
return -EINVAL;
136+
}
137+
126138
static inline int firmware_request_nowarn(const struct firmware **fw,
127139
const char *name,
128140
struct device *device)

0 commit comments

Comments
 (0)