FAILED: patch "[PATCH] ALSA: hda/tas2781: Cancel async firmware request at unbind" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 5367e2ad14f0ae9350a7aaf2e77c87de39a43ae9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071331-spooky-nuzzle-36ff@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 5367e2ad14f0ae9350a7aaf2e77c87de39a43ae9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A1ssio=20Gabriel?= <[email protected]>
Date: Tue, 5 May 2026 08:18:17 -0300
Subject: [PATCH] ALSA: hda/tas2781: Cancel async firmware request at unbind
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
TAS2781 HDA I2C and SPI queue RCA firmware loading from component bind with request_firmware_nowait(). The firmware loader keeps the callback module pinned and holds a device reference, but the callback still uses driver-private HDA state.
Component unbind removes controls and DSP state immediately. Later device removal tears down the TAS2781 private data, including codec_lock. If the async firmware callback runs after unbind has started, it can operate on state that is being torn down.
Cancel or synchronize the async firmware request before removing controls and DSP state. A queued callback is cancelled, and an already-running callback is allowed to finish before unbind continues.
sound/hda/codecs/side-codecs/tas2781_hda_i2c.c +3 -0
@@ -588,6 +588,9 @@ static void tas2781_hda_unbind(struct device *dev, comp->playback_hook =NULL ; } +request_firmware_nowait_cancel (tas_hda->priv->dev, tas_hda->priv, + tasdev_fw_ready); +tas2781_hda_remove_controls (tas_hda);tasdevice_config_info_remove (tas_hda->priv);
sound/hda/codecs/side-codecs/tas2781_hda_spi.c +3 -0
@@ -742,6 +742,9 @@ static void tas2781_hda_unbind(struct device *dev, struct device *master, comp->playback_hook =NULL ; } +request_firmware_nowait_cancel (tas_priv->dev, tas_priv, + tasdev_fw_ready); +tas2781_hda_remove_controls (tas_hda);tasdevice_config_info_remove (tas_priv);
Sasha Levin
maintainerPATCH 1/2 firmware_loader: Add cancel helper for async requests
From: Cássio Gabriel <[email protected]>
[ Upstream commit b9bdd68b8b979c7e9de58b2e7d21e1d7d932c755 ]
request_firmware_nowait() keeps the callback module pinned and holds a device reference until the firmware work completes.
Callers still have no way to cancel or synchronize the queued callback before tearing down their driver-private state.
Track scheduled async firmware work in an internal list and add request_firmware_nowait_cancel(). The helper cancels work matching the device, callback context and callback function. It cancels work that has not started yet and waits for an already-running callback to return. If the request has already completed, it is a no-op.
Keep the existing request_firmware_nowait() lifetime model manual. A devres-managed variant can be layered on top separately if needed.
Stable-dep-of: 5367e2ad14f0 ("ALSA: hda/tas2781: Cancel async firmware request at unbind")
--- drivers/base/firmware_loader/main.c | 68 +++++++++++++++++++++++++++-- include/linux/firmware.h | 10 +++++ 2 files changed, 74 insertions(+), 4 deletions(-)
drivers/base/firmware_loader/main.c +64 -4
@@ -1141,6 +1141,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;
@@ -1149,6 +1150,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;
@@ -1159,11 +1171,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); }
@@ -1173,6 +1189,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 (sizeof (struct firmware_work ), gfp);if (!fw_work)
@@ -1205,7 +1222,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 ; }
@@ -1268,6 +1290,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);
include/linux/firmware.h +10 -0
@@ -110,6 +110,9 @@ 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, +void (*cont)(const struct firmware *fw, +void *context));int request_firmware_direct (const struct firmware **fw,const char *name,struct device *device); int request_firmware_into_buf(const struct firmware **firmware_p,
@@ -157,6 +160,13 @@ static inline int request_firmware_nowait(return -EINVAL ; } +static inline void request_firmware_nowait_cancel (struct device *device, +void *context, +void (*cont)(const struct firmware *fw, +void *context)) +{ +} +static inline void release_firmware (const struct firmware *fw) { }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 ALSA: hda/tas2781: Cancel async firmware request at unbind
From: Cássio Gabriel <[email protected]>
[ Upstream commit 5367e2ad14f0ae9350a7aaf2e77c87de39a43ae9 ]
TAS2781 HDA I2C and SPI queue RCA firmware loading from component bind with request_firmware_nowait(). The firmware loader keeps the callback module pinned and holds a device reference, but the callback still uses driver-private HDA state.
Component unbind removes controls and DSP state immediately. Later device removal tears down the TAS2781 private data, including codec_lock. If the async firmware callback runs after unbind has started, it can operate on state that is being torn down.
Cancel or synchronize the async firmware request before removing controls and DSP state. A queued callback is cancelled, and an already-running callback is allowed to finish before unbind continues.
--- sound/hda/codecs/side-codecs/tas2781_hda_i2c.c | 3 +++ sound/hda/codecs/side-codecs/tas2781_hda_spi.c | 3 +++ 2 files changed, 6 insertions(+)
sound/hda/codecs/side-codecs/tas2781_hda_i2c.c +3 -0
@@ -616,6 +616,9 @@ static void tas2781_hda_unbind(struct device *dev, comp->playback_hook =NULL ; } +request_firmware_nowait_cancel (tas_hda->priv->dev, tas_hda->priv, + tasdev_fw_ready); +tas2781_hda_remove_controls (tas_hda);tasdevice_config_info_remove (tas_hda->priv);
sound/hda/codecs/side-codecs/tas2781_hda_spi.c +3 -0
@@ -753,6 +753,9 @@ static void tas2781_hda_unbind(struct device *dev, struct device *master, comp->playback_hook =NULL ; } +request_firmware_nowait_cancel (tas_priv->dev, tas_priv, + tasdev_fw_ready); +tas2781_hda_remove_controls (tas_hda);tasdevice_config_info_remove (tas_priv);
Signature · 1 line
2.53.0