[PATCH 3/4] firmware_loader: Return status from request_firmware_nowait_cancel

From: Sean Anderson

Date: Mon Sep 21 2026 - 17:18:44 EST


request_firmware_nowait_cancel only cancels the most-recent matching
firmware request. If the callback creates additional requests then there
can be multiple requests in-flight (the original request and the
(pending) additional request). If we try to cancel the request at that
point, the original request may still be running. Add a status return
from request_firmware_nowait_cancel so we can tell if there may still be
additional requests we need to cancel.

Signed-off-by: Sean Anderson <sanderson@xxxxxxxxx>
---

drivers/base/firmware_loader/main.c | 11 ++++++++---
include/linux/firmware.h | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index 24213a0ea8317..ea475aa48a316 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -1290,11 +1290,15 @@ EXPORT_SYMBOL_GPL(firmware_request_nowait_nowarn);
* 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.
+ * function does nothing. This function may need to be called multiple times if
+ * the callback makes additional firmware requests.
*
* This function may sleep.
+ *
+ * Return: %true if a request was canceled, or %false if no requests matched
+ * @device and @context.
*/
-void request_firmware_nowait_cancel(struct device *device, void *context,
+bool request_firmware_nowait_cancel(struct device *device, void *context,
void (*cont)(const struct firmware *fw,
void *context))
{
@@ -1313,9 +1317,10 @@ void request_firmware_nowait_cancel(struct device *device, void *context,
spin_unlock_irq(&firmware_work_lock);

if (!fw_work)
- return;
+ return false;
cancel_work_sync(&fw_work->work);
firmware_work_free(fw_work);
+ return true;
}
EXPORT_SYMBOL_GPL(request_firmware_nowait_cancel);

diff --git a/include/linux/firmware.h b/include/linux/firmware.h
index 0fa3b027f02f1..46c34ad0067e7 100644
--- a/include/linux/firmware.h
+++ b/include/linux/firmware.h
@@ -110,7 +110,7 @@ int request_firmware_nowait(
struct module *module, bool uevent,
const char *name, struct device *device, gfp_t gfp, void *context,
void (*cont)(const struct firmware *fw, void *context));
-void request_firmware_nowait_cancel(struct device *device, void *context,
+bool request_firmware_nowait_cancel(struct device *device, void *context,
void (*cont)(const struct firmware *fw,
void *context));
int request_firmware_direct(const struct firmware **fw, const char *name,
--
2.53.0