Skip to content

Commit 9ebfbd4

Browse files
jmberggregkh
authored andcommitted
firmware_class: make request_firmware_nowait more useful
Unfortunately, one cannot hold on to the struct firmware that request_firmware_nowait() hands off, which is needed in some cases. Allow this by requiring the callback to free it (via release_firmware). Additionally, give it a gfp_t parameter -- all the current users call it from a GFP_KERNEL context so the GFP_ATOMIC isn't necessary. This also marks an API break which is useful in a sense, although that is obviously not the primary purpose of this change. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Marcel Holtmann <marcel@holtmann.org> Cc: Ming Lei <tom.leiming@gmail.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: David Woodhouse <David.Woodhouse@intel.com> Cc: Pavel Roskin <proski@gnu.org> Cc: Abhay Salunke <abhay_salunke@dell.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 03d673e commit 9ebfbd4

7 files changed

Lines changed: 33 additions & 20 deletions

File tree

‎drivers/base/firmware_class.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,9 @@ request_firmware_work_func(void *arg)
601601
}
602602
ret = _request_firmware(&fw, fw_work->name, fw_work->device,
603603
fw_work->uevent);
604-
if (ret < 0)
605-
fw_work->cont(NULL, fw_work->context);
606-
else {
607-
fw_work->cont(fw, fw_work->context);
608-
release_firmware(fw);
609-
}
604+
605+
fw_work->cont(fw, fw_work->context);
606+
610607
module_put(fw_work->module);
611608
kfree(fw_work);
612609
return ret;
@@ -619,6 +616,7 @@ request_firmware_work_func(void *arg)
619616
* is non-zero else the firmware copy must be done manually.
620617
* @name: name of firmware file
621618
* @device: device for which firmware is being loaded
619+
* @gfp: allocation flags
622620
* @context: will be passed over to @cont, and
623621
* @fw may be %NULL if firmware request fails.
624622
* @cont: function will be called asynchronously when the firmware
@@ -631,12 +629,12 @@ request_firmware_work_func(void *arg)
631629
int
632630
request_firmware_nowait(
633631
struct module *module, int uevent,
634-
const char *name, struct device *device, void *context,
632+
const char *name, struct device *device, gfp_t gfp, void *context,
635633
void (*cont)(const struct firmware *fw, void *context))
636634
{
637635
struct task_struct *task;
638636
struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work),
639-
GFP_ATOMIC);
637+
gfp);
640638

641639
if (!fw_work)
642640
return -ENOMEM;

‎drivers/firmware/dell_rbu.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,12 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
544544
{
545545
rbu_data.entry_created = 0;
546546

547-
if (!fw || !fw->size)
547+
if (!fw)
548548
return;
549549

550+
if (!fw->size)
551+
goto out;
552+
550553
spin_lock(&rbu_data.lock);
551554
if (!strcmp(image_type, "mono")) {
552555
if (!img_update_realloc(fw->size))
@@ -568,6 +571,8 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
568571
} else
569572
pr_debug("invalid image type specified.\n");
570573
spin_unlock(&rbu_data.lock);
574+
out:
575+
release_firmware(fw);
571576
}
572577

573578
static ssize_t read_rbu_image_type(struct kobject *kobj,
@@ -615,7 +620,7 @@ static ssize_t write_rbu_image_type(struct kobject *kobj,
615620
spin_unlock(&rbu_data.lock);
616621
req_firm_rc = request_firmware_nowait(THIS_MODULE,
617622
FW_ACTION_NOHOTPLUG, "dell_rbu",
618-
&rbu_device->dev, &context,
623+
&rbu_device->dev, GFP_KERNEL, &context,
619624
callbackfn_rbu);
620625
if (req_firm_rc) {
621626
printk(KERN_ERR

‎drivers/serial/ucc_uart.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,16 +1179,18 @@ static void uart_firmware_cont(const struct firmware *fw, void *context)
11791179

11801180
if (firmware->header.length != fw->size) {
11811181
dev_err(dev, "invalid firmware\n");
1182-
return;
1182+
goto out;
11831183
}
11841184

11851185
ret = qe_upload_firmware(firmware);
11861186
if (ret) {
11871187
dev_err(dev, "could not load firmware\n");
1188-
return;
1188+
goto out;
11891189
}
11901190

11911191
firmware_loaded = 1;
1192+
out:
1193+
release_firmware(fw);
11921194
}
11931195

11941196
static int ucc_uart_probe(struct of_device *ofdev,
@@ -1247,7 +1249,7 @@ static int ucc_uart_probe(struct of_device *ofdev,
12471249
*/
12481250
ret = request_firmware_nowait(THIS_MODULE,
12491251
FW_ACTION_HOTPLUG, filename, &ofdev->dev,
1250-
&ofdev->dev, uart_firmware_cont);
1252+
GFP_KERNEL, &ofdev->dev, uart_firmware_cont);
12511253
if (ret) {
12521254
dev_err(&ofdev->dev,
12531255
"could not load firmware %s\n",

‎drivers/staging/comedi/drivers/usbdux.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2327,9 +2327,11 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
23272327
if (ret) {
23282328
dev_err(&usbdev->dev,
23292329
"Could not upload firmware (err=%d)\n", ret);
2330-
return;
2330+
goto out;
23312331
}
23322332
comedi_usb_auto_config(usbdev, BOARDNAME);
2333+
out:
2334+
release_firmware(fw);
23332335
}
23342336

23352337
/* allocate memory for the urbs and initialise them */
@@ -2580,6 +2582,7 @@ static int usbduxsub_probe(struct usb_interface *uinterf,
25802582
FW_ACTION_HOTPLUG,
25812583
"usbdux_firmware.bin",
25822584
&udev->dev,
2585+
GFP_KERNEL,
25832586
usbduxsub + index,
25842587
usbdux_firmware_request_complete_handler);
25852588

‎drivers/staging/comedi/drivers/usbduxfast.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,10 +1451,12 @@ static void usbduxfast_firmware_request_complete_handler(const struct firmware
14511451
if (ret) {
14521452
dev_err(&usbdev->dev,
14531453
"Could not upload firmware (err=%d)\n", ret);
1454-
return;
1454+
goto out;
14551455
}
14561456

14571457
comedi_usb_auto_config(usbdev, BOARDNAME);
1458+
out:
1459+
release_firmware(fw);
14581460
}
14591461

14601462
/*
@@ -1569,6 +1571,7 @@ static int usbduxfastsub_probe(struct usb_interface *uinterf,
15691571
FW_ACTION_HOTPLUG,
15701572
"usbduxfast_firmware.bin",
15711573
&udev->dev,
1574+
GFP_KERNEL,
15721575
usbduxfastsub + index,
15731576
usbduxfast_firmware_request_complete_handler);
15741577

‎drivers/usb/atm/ueagle-atm.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,12 @@ static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *conte
667667
else
668668
uea_info(usb, "firmware uploaded\n");
669669

670-
uea_leaves(usb);
671-
return;
670+
goto err;
672671

673672
err_fw_corrupted:
674673
uea_err(usb, "firmware is corrupted\n");
675674
err:
675+
release_firmware(fw_entry);
676676
uea_leaves(usb);
677677
}
678678

@@ -705,7 +705,8 @@ static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
705705
break;
706706
}
707707

708-
ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
708+
ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
709+
GFP_KERNEL, usb, uea_upload_pre_firmware);
709710
if (ret)
710711
uea_err(usb, "firmware %s is not available\n", fw_name);
711712
else

‎include/linux/firmware.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/module.h>
55
#include <linux/types.h>
66
#include <linux/compiler.h>
7+
#include <linux/gfp.h>
78

89
#define FW_ACTION_NOHOTPLUG 0
910
#define FW_ACTION_HOTPLUG 1
@@ -38,7 +39,7 @@ int request_firmware(const struct firmware **fw, const char *name,
3839
struct device *device);
3940
int request_firmware_nowait(
4041
struct module *module, int uevent,
41-
const char *name, struct device *device, void *context,
42+
const char *name, struct device *device, gfp_t gfp, void *context,
4243
void (*cont)(const struct firmware *fw, void *context));
4344

4445
void release_firmware(const struct firmware *fw);
@@ -51,7 +52,7 @@ static inline int request_firmware(const struct firmware **fw,
5152
}
5253
static inline int request_firmware_nowait(
5354
struct module *module, int uevent,
54-
const char *name, struct device *device, void *context,
55+
const char *name, struct device *device, gfp_t gfp, void *context,
5556
void (*cont)(const struct firmware *fw, void *context))
5657
{
5758
return -EINVAL;

0 commit comments

Comments
 (0)