* [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues
@ 2026-09-14 1:56 Neo Chang
2026-09-14 1:56 ` [PATCH v5 1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails Neo Chang
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Neo Chang @ 2026-09-14 1:56 UTC (permalink / raw)
To: broonie
Cc: error27, lgirdwood, perex, robh, krzk+dt, linux-sound, devicetree,
alsa-devel, neo.chang70, kchsu0, sjlin0, Neo Chang
This patch series addresses two issues in the nau8360 codec driver
regarding the DAC mux control:
1. An invalid hardware routing state that occurs when the DSP firmware
fails to load but the userspace attempts to switch to the DSP path.
2. A pre-existing AB-BA deadlock triggered during concurrent stream
startups or ALSA mixer updates.
---
Changes in v5:
- Patch 1/2: Changed the return value to -EBUSY in the playback check
condition (bias_level > STANDBY). (Reported by Dan Carpenter)
- Rebased onto the latest for-next branch and resolved a merge conflict
in nau8360_dac_mux_put_enum().
Changes in v4:
- Patch 1/2: Changed the return value to -EBUSY instead of 0 to properly
reject the invalid request and prevent ALSA state desync.
- Patch 1/2: Used dev_warn_ratelimited() instead of dev_warn().
- Patch 2/2: Added a fix for the AB-BA deadlock in nau8360_dac_mux_put_enum().
(Reported by Sashiko AI)
Changes in v3:
- Block the DSP path selection if the firmware fails to load to prevent
invalid routing states.
Changes in v2:
- Use snd_soc_component_update_bits() to prevent register overwriting.
(Reported by Sashiko AI)
- Fix missing bit shift for default PEQ band. (Reported by Sashiko AI)
Neo Chang (2):
ASoC: codecs: nau8360: Block DSP path selection when firmware load
fails
ASoC: codecs: nau8360: Fix AB-BA deadlock in mux update
sound/soc/codecs/nau8360.c | 21 ++++++++++++++-------
sound/soc/codecs/nau8360.h | 6 ++++++
2 files changed, 20 insertions(+), 7 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails
2026-09-14 1:56 [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Neo Chang
@ 2026-09-14 1:56 ` Neo Chang
2026-09-14 2:11 ` sashiko-bot
2026-09-14 1:56 ` [PATCH v5 2/2] ASoC: codecs: nau8360: Fix AB-BA deadlock in mux update Neo Chang
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Neo Chang @ 2026-09-14 1:56 UTC (permalink / raw)
To: broonie
Cc: error27, lgirdwood, perex, robh, krzk+dt, linux-sound, devicetree,
alsa-devel, neo.chang70, kchsu0, sjlin0, Neo Chang
Block the DSP path selection if the firmware fails to load to prevent
invalid routing states.
If the firmware is not ready, nau8360_dac_mux_put_enum() will print
a rate-limited warning and return -EBUSY. This rejects the invalid
userspace request and maintains the original hardware state without
causing audio wrong status.
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/linux-sound/aqK_oOpMAXVhxkHJ@stanley.mountain/
Suggested-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Neo Chang <YLCHANG2@nuvoton.com>
---
sound/soc/codecs/nau8360.c | 9 +++++++--
sound/soc/codecs/nau8360.h | 6 ++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/nau8360.c b/sound/soc/codecs/nau8360.c
index 89b8ee80d6c8..f5dee12127cd 100644
--- a/sound/soc/codecs/nau8360.c
+++ b/sound/soc/codecs/nau8360.c
@@ -715,8 +715,13 @@ static int nau8360_dac_mux_put_enum(struct snd_kcontrol *kcontrol,
int ret = 0;
if (snd_soc_dapm_get_bias_level(dapm) > SND_SOC_BIAS_STANDBY) {
- dev_warn(nau8360->dev, "changing path is not allowed during playback");
- return ret;
+ dev_warn_ratelimited(nau8360->dev, "changing path is not allowed during playback");
+ return -EBUSY;
+ }
+
+ if (item[0] == NAU8360_DAC_SRC_DSP && !nau8360->load_fw_done) {
+ dev_warn_ratelimited(nau8360->dev, "Cannot enable DSP: Firmware not ready or disabled\n");
+ return -EBUSY;
}
mutex_lock(&nau8360->lock);
diff --git a/sound/soc/codecs/nau8360.h b/sound/soc/codecs/nau8360.h
index cc640ba8c838..71396747c0fa 100644
--- a/sound/soc/codecs/nau8360.h
+++ b/sound/soc/codecs/nau8360.h
@@ -870,6 +870,12 @@ enum {
NAU8360_TDM_TXN,
};
+/* DAC Source Path*/
+enum {
+ NAU8360_DAC_SRC_HW1 = 0,
+ NAU8360_DAC_SRC_DSP,
+};
+
/* PLL Source */
enum {
NAU8360_PLL_MCLK,
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 2/2] ASoC: codecs: nau8360: Fix AB-BA deadlock in mux update
2026-09-14 1:56 [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Neo Chang
2026-09-14 1:56 ` [PATCH v5 1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails Neo Chang
@ 2026-09-14 1:56 ` Neo Chang
2026-09-14 11:03 ` [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Mark Brown
2026-09-17 11:47 ` Mark Brown
3 siblings, 0 replies; 6+ messages in thread
From: Neo Chang @ 2026-09-14 1:56 UTC (permalink / raw)
To: broonie
Cc: error27, lgirdwood, perex, robh, krzk+dt, linux-sound, devicetree,
alsa-devel, neo.chang70, kchsu0, sjlin0, Neo Chang, Sashiko AI
nau8360_dac_mux_put_enum() acquires nau8360->lock before the DAPM mutex,
causing an AB-BA lock inversion. This deadlocks with concurrent stream
startups or mixer updates, which acquire locks in the reverse order.
Fix this by replacing nau8360->lock with the DAPM mutex to protect
pre-checks, releasing it before calling snd_soc_dapm_put_enum_double().
Reported-by: Sashiko AI <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20260908030342.222655-1-YLCHANG2@nuvoton.com?part=1
Signed-off-by: Neo Chang <YLCHANG2@nuvoton.com>
---
sound/soc/codecs/nau8360.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/nau8360.c b/sound/soc/codecs/nau8360.c
index f5dee12127cd..f0942739d7ab 100644
--- a/sound/soc/codecs/nau8360.c
+++ b/sound/soc/codecs/nau8360.c
@@ -689,6 +689,8 @@ static void nau8360_dsp_switch(struct snd_soc_component *component, bool enable)
struct regmap *regmap = nau8360->regmap;
int value = NAU8360_PEQ_BAND_8;
+ mutex_lock(&nau8360->lock);
+
/* If DSP is enabled, unstall HW3 engine and DSP, loading DSP firmware,
* and configure PEQ after dsp reset.
*/
@@ -702,6 +704,7 @@ static void nau8360_dsp_switch(struct snd_soc_component *component, bool enable)
regmap_update_bits(regmap, NAU8360_R9D_PEQ_CTL, NAU8360_PEQ_BAND_MASK,
value << NAU8360_PEQ_BAND_SFT);
+ mutex_unlock(&nau8360->lock);
}
static int nau8360_dac_mux_put_enum(struct snd_kcontrol *kcontrol,
@@ -714,27 +717,26 @@ static int nau8360_dac_mux_put_enum(struct snd_kcontrol *kcontrol,
unsigned int *item = ucontrol->value.enumerated.item;
int ret = 0;
+ snd_soc_dapm_mutex_lock(dapm);
if (snd_soc_dapm_get_bias_level(dapm) > SND_SOC_BIAS_STANDBY) {
dev_warn_ratelimited(nau8360->dev, "changing path is not allowed during playback");
+ snd_soc_dapm_mutex_unlock(dapm);
return -EBUSY;
}
if (item[0] == NAU8360_DAC_SRC_DSP && !nau8360->load_fw_done) {
dev_warn_ratelimited(nau8360->dev, "Cannot enable DSP: Firmware not ready or disabled\n");
+ snd_soc_dapm_mutex_unlock(dapm);
return -EBUSY;
}
-
- mutex_lock(&nau8360->lock);
+ snd_soc_dapm_mutex_unlock(dapm);
ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
if (ret <= 0)
- goto unlock;
+ return ret;
nau8360_dsp_switch(component, snd_soc_enum_item_to_val(e, item[0]));
-unlock:
- mutex_unlock(&nau8360->lock);
-
return ret;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails
2026-09-14 1:56 ` [PATCH v5 1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails Neo Chang
@ 2026-09-14 2:11 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-09-14 2:11 UTC (permalink / raw)
To: Neo Chang; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing `flush_work()` causes `alsactl` state restoration to sporadically fail on boot.
--
commit f48ac064e0d2cdb72be2043789666477aed5f727
Author: Neo Chang <YLCHANG2@nuvoton.com>
ASoC: codecs: nau8360: Block DSP path selection when firmware load fails
Block the DSP path selection if the firmware fails to load to prevent
invalid routing states.
If the firmware is not ready, nau8360_dac_mux_put_enum() will print
a rate-limited warning and return -EBUSY. This rejects the invalid
userspace request and maintains the original hardware state without
causing audio wrong status.
Closes: https://lore.kernel.org/linux-sound/aqK_oOpMAXVhxkHJ@stanley.mountain/
> diff --git a/sound/soc/codecs/nau8360.c b/sound/soc/codecs/nau8360.c
> index 89b8ee80d6c86..f5dee12127cd0 100644
> --- a/sound/soc/codecs/nau8360.c
> +++ b/sound/soc/codecs/nau8360.c
> @@ -715,8 +715,13 @@ static int nau8360_dac_mux_put_enum(struct snd_kcontrol *kcontrol,
> int ret = 0;
>
> if (snd_soc_dapm_get_bias_level(dapm) > SND_SOC_BIAS_STANDBY) {
> - dev_warn(nau8360->dev, "changing path is not allowed during playback");
> - return ret;
> + dev_warn_ratelimited(nau8360->dev, "changing path is not allowed during playback");
> + return -EBUSY;
> + }
> +
> + if (item[0] == NAU8360_DAC_SRC_DSP && !nau8360->load_fw_done) {
> + dev_warn_ratelimited(nau8360->dev, "Cannot enable DSP: Firmware not ready or disabled\n");
> + return -EBUSY;
[Severity: Medium]
Will this cause boot-time ALSA state restoration to fail if the asynchronous
firmware loader is still running?
Userspace initialization tools like alsactl restore write to ALSA controls
immediately after card registration during boot. Because nau8360_load_fw_work
is scheduled asynchronously, nau8360->load_fw_done might still be false when
alsactl attempts to restore the DSP path.
Without a flush_work() call to synchronize with the firmware loader, does this
mean valid DSP routing configurations saved by the user will be sporadically
rejected during boot, causing the audio state to fall back to the default HW1
path?
> }
>
> mutex_lock(&nau8360->lock);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914015648.311986-1-YLCHANG2@nuvoton.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues
2026-09-14 1:56 [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Neo Chang
2026-09-14 1:56 ` [PATCH v5 1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails Neo Chang
2026-09-14 1:56 ` [PATCH v5 2/2] ASoC: codecs: nau8360: Fix AB-BA deadlock in mux update Neo Chang
@ 2026-09-14 11:03 ` Mark Brown
2026-09-17 11:47 ` Mark Brown
3 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2026-09-14 11:03 UTC (permalink / raw)
To: Neo Chang
Cc: error27, lgirdwood, perex, robh, krzk+dt, linux-sound, devicetree,
alsa-devel, neo.chang70, kchsu0, sjlin0
On Mon, 14 Sep 2026 09:56:46 +0800, Neo Chang wrote:
> ASoC: codecs: nau8360: Fix DSP routing and deadlock issues
>
> This patch series addresses two issues in the nau8360 codec driver
> regarding the DAC mux control:
>
> 1. An invalid hardware routing state that occurs when the DSP firmware
> fails to load but the userspace attempts to switch to the DSP path.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.3
Thanks!
[1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails
https://git.kernel.org/broonie/sound/c/9231c12286ab
[2/2] ASoC: codecs: nau8360: Fix AB-BA deadlock in mux update
https://git.kernel.org/broonie/sound/c/9b4647233ef5
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues
2026-09-14 1:56 [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Neo Chang
` (2 preceding siblings ...)
2026-09-14 11:03 ` [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Mark Brown
@ 2026-09-17 11:47 ` Mark Brown
3 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2026-09-17 11:47 UTC (permalink / raw)
To: Neo Chang
Cc: error27, lgirdwood, perex, robh, krzk+dt, linux-sound, devicetree,
alsa-devel, neo.chang70, kchsu0, sjlin0
On Mon, 14 Sep 2026 09:56:46 +0800, Neo Chang wrote:
> ASoC: codecs: nau8360: Fix DSP routing and deadlock issues
>
> This patch series addresses two issues in the nau8360 codec driver
> regarding the DAC mux control:
>
> 1. An invalid hardware routing state that occurs when the DSP firmware
> fails to load but the userspace attempts to switch to the DSP path.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4
Thanks!
[1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails
https://git.kernel.org/broonie/sound/c/eeff736ebf5d
[2/2] ASoC: codecs: nau8360: Fix AB-BA deadlock in mux update
https://git.kernel.org/broonie/sound/c/4862e73eaf08
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-09-17 11:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-14 1:56 [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Neo Chang
2026-09-14 1:56 ` [PATCH v5 1/2] ASoC: codecs: nau8360: Block DSP path selection when firmware load fails Neo Chang
2026-09-14 2:11 ` sashiko-bot
2026-09-14 1:56 ` [PATCH v5 2/2] ASoC: codecs: nau8360: Fix AB-BA deadlock in mux update Neo Chang
2026-09-14 11:03 ` [PATCH v5 0/2] ASoC: codecs: nau8360: Fix DSP routing and deadlock issues Mark Brown
2026-09-17 11:47 ` Mark Brown
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.