summaryrefslogtreecommitdiff
path: root/drivers/base/firmware_loader/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/firmware_loader/main.c')
-rw-r--r--drivers/base/firmware_loader/main.c71
1 files changed, 66 insertions, 5 deletions
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index a11b30dda23b..24213a0ea831 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -1132,6 +1132,7 @@ EXPORT_SYMBOL(release_firmware);
/* Async support */
struct firmware_work {
struct work_struct work;
+ struct list_head list;
struct module *module;
const char *name;
struct device *device;
@@ -1140,6 +1141,17 @@ struct firmware_work {
u32 opt_flags;
};
+static LIST_HEAD(firmware_work_list);
+static DEFINE_SPINLOCK(firmware_work_lock);
+
+static void firmware_work_free(struct firmware_work *fw_work)
+{
+ put_device(fw_work->device); /* taken in request_firmware_nowait() */
+ module_put(fw_work->module);
+ kfree_const(fw_work->name);
+ kfree(fw_work);
+}
+
static void request_firmware_work_func(struct work_struct *work)
{
struct firmware_work *fw_work;
@@ -1150,11 +1162,15 @@ static void request_firmware_work_func(struct work_struct *work)
_request_firmware(&fw, fw_work->name, fw_work->device, NULL, 0, 0,
fw_work->opt_flags);
fw_work->cont(fw, fw_work->context);
- put_device(fw_work->device); /* taken in request_firmware_nowait() */
- module_put(fw_work->module);
- kfree_const(fw_work->name);
- kfree(fw_work);
+ spin_lock_irq(&firmware_work_lock);
+ if (!list_empty(&fw_work->list)) {
+ list_del_init(&fw_work->list);
+ spin_unlock_irq(&firmware_work_lock);
+ firmware_work_free(fw_work);
+ return;
+ }
+ spin_unlock_irq(&firmware_work_lock);
}
@@ -1164,6 +1180,7 @@ static int _request_firmware_nowait(
void (*cont)(const struct firmware *fw, void *context), bool nowarn)
{
struct firmware_work *fw_work;
+ unsigned long flags;
fw_work = kzalloc_obj(struct firmware_work, gfp);
if (!fw_work)
@@ -1196,7 +1213,12 @@ static int _request_firmware_nowait(
get_device(fw_work->device);
INIT_WORK(&fw_work->work, request_firmware_work_func);
+
+ spin_lock_irqsave(&firmware_work_lock, flags);
+ list_add_tail(&fw_work->list, &firmware_work_list);
schedule_work(&fw_work->work);
+ spin_unlock_irqrestore(&firmware_work_lock, flags);
+
return 0;
}
@@ -1259,6 +1281,44 @@ int firmware_request_nowait_nowarn(
}
EXPORT_SYMBOL_GPL(firmware_request_nowait_nowarn);
+/**
+ * request_firmware_nowait_cancel() - cancel an async firmware request
+ * @device: device for which the firmware is being loaded
+ * @context: context passed to request_firmware_nowait()
+ * @cont: callback passed to request_firmware_nowait()
+ *
+ * Cancel a pending request_firmware_nowait() request for @device, @context
+ * and @cont. If the associated work has already started, this function waits
+ * until the callback has returned. If the callback has already completed, this
+ * function does nothing.
+ *
+ * This function may sleep.
+ */
+void request_firmware_nowait_cancel(struct device *device, void *context,
+ void (*cont)(const struct firmware *fw,
+ void *context))
+{
+ struct firmware_work *fw_work = NULL;
+ struct firmware_work *tmp;
+
+ spin_lock_irq(&firmware_work_lock);
+ list_for_each_entry_reverse(tmp, &firmware_work_list, list) {
+ if (tmp->device == device && tmp->context == context &&
+ tmp->cont == cont) {
+ fw_work = tmp;
+ list_del_init(&fw_work->list);
+ break;
+ }
+ }
+ spin_unlock_irq(&firmware_work_lock);
+
+ if (!fw_work)
+ return;
+ cancel_work_sync(&fw_work->work);
+ firmware_work_free(fw_work);
+}
+EXPORT_SYMBOL_GPL(request_firmware_nowait_cancel);
+
#ifdef CONFIG_FW_CACHE
static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain);
@@ -1503,9 +1563,10 @@ static void device_cache_fw_images(void)
mutex_lock(&fw_lock);
fwc->state = FW_LOADER_START_CACHE;
- dpm_for_each_dev(NULL, dev_cache_fw_image);
mutex_unlock(&fw_lock);
+ dpm_for_each_dev(NULL, dev_cache_fw_image);
+
/* wait for completion of caching firmware for all devices */
async_synchronize_full_domain(&fw_cache_domain);