* [PATCH] ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU
@ 2026-11-04 8:02 Tang Bin
2026-11-04 8:12 ` sashiko-bot
2026-11-04 11:04 ` Charles Keepax
0 siblings, 2 replies; 4+ messages in thread
From: Tang Bin @ 2026-11-04 8:02 UTC (permalink / raw)
To: david.rhodes, rf, lgirdwood, broonie, perex, tiwai
Cc: linux-sound, patches, linux-kernel, tangbin, stable
cs42l43_pll_ev() PRE_PMU arm enables mclk (when refclk_src is MCLK) then
calls cs42l43_enable_pll(). If PLL enable fails, ret is negative and DAPM
does not power up the widget, so POST_PMD never runs and the matching
clk_disable_unprepare(mclk) at line 1621 is skipped - mclk refcount leaked.
Roll back the mclk enable on PLL failure.
Fixes: fc918cbe874e ("ASoC: cs42l43: Add support for the cs42l43")
Cc: stable@vger.kernel.org
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
sound/soc/codecs/cs42l43.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/soc/codecs/cs42l43.c b/sound/soc/codecs/cs42l43.c
index 1b817e1a6..0ac9e2361 100644
--- a/sound/soc/codecs/cs42l43.c
+++ b/sound/soc/codecs/cs42l43.c
@@ -1613,6 +1613,8 @@ static int cs42l43_pll_ev(struct snd_soc_dapm_widget *w,
}
ret = cs42l43_enable_pll(priv);
+ if (ret && priv->refclk_src == CS42L43_SYSCLK_MCLK)
+ clk_disable_unprepare(priv->mclk);
break;
case SND_SOC_DAPM_POST_PMD:
ret = cs42l43_disable_pll(priv);
--
2.52.0.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU
2026-11-04 8:02 [PATCH] ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU Tang Bin
@ 2026-11-04 8:12 ` sashiko-bot
2026-11-04 11:04 ` Charles Keepax
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-04 8:12 UTC (permalink / raw)
To: Tang Bin; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ASoC: cs42l43: double clk_disable_unprepare() in cs42l43_pll_ev()
--
commit 22be724b77049d9bdd49902edcd96899ee4749da
Author: Tang Bin <tangbin@cmss.chinamobile.com>
ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU
This commit disables and unprepares MCLK in cs42l43_pll_ev() if
cs42l43_enable_pll() fails during SND_SOC_DAPM_PRE_PMU.
> diff --git a/sound/soc/codecs/cs42l43.c b/sound/soc/codecs/cs42l43.c
> index b6238f89c789c..6f308ea227fb6 100644
> --- a/sound/soc/codecs/cs42l43.c
> +++ b/sound/soc/codecs/cs42l43.c
> @@ -1625,6 +1625,8 @@ static int cs42l43_pll_ev(struct snd_soc_dapm_widget *w,
> }
>
> ret = cs42l43_enable_pll(priv);
> + if (ret && priv->refclk_src == CS42L43_SYSCLK_MCLK)
> + clk_disable_unprepare(priv->mclk);
[Severity: High]
Does this cause a double clk_disable_unprepare(priv->mclk) when the widget
later powers down?
In sound/soc/soc-dapm.c, dapm_seq_run_coalesced() sets w->power before
running SND_SOC_DAPM_PRE_PMU:
sound/soc/soc-dapm.c:dapm_seq_run_coalesced() {
list_for_each_entry(w, pending, power_list) {
WARN_ON(reg != w->reg || dapm != w->dapm);
w->power = w->new_power;
...
/* Check for events */
dapm_seq_check_event(card, w, SND_SOC_DAPM_PRE_PMU);
And dapm_seq_check_event() only logs an error when w->event() returns a
negative value, without rolling back w->power:
sound/soc/soc-dapm.c:dapm_seq_check_event() {
ret = w->event(w, NULL, event);
trace_snd_soc_dapm_widget_event_done(w, event);
if (ret < 0)
dev_err(dev, "ASoC: %s: %s event failed: %d\n",
ev_name, w->name, ret);
Because w->power remains 1 even when cs42l43_enable_pll() fails, DAPM will
still run the SND_SOC_DAPM_POST_PMD event when the audio path powers down:
sound/soc/codecs/cs42l43.c:cs42l43_pll_ev() {
case SND_SOC_DAPM_POST_PMD:
ret = cs42l43_disable_pll(priv);
if (priv->refclk_src == CS42L43_SYSCLK_MCLK)
clk_disable_unprepare(priv->mclk);
break;
Wouldn't disabling priv->mclk in the SND_SOC_DAPM_PRE_PMU error path cause
SND_SOC_DAPM_POST_PMD to call clk_disable_unprepare(priv->mclk) a second
time and underflow the clock enable and prepare reference counts?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104080257.1144-1-tangbin@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU
2026-11-04 8:02 [PATCH] ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU Tang Bin
2026-11-04 8:12 ` sashiko-bot
@ 2026-11-04 11:04 ` Charles Keepax
2026-11-06 1:01 ` Tang Bin
1 sibling, 1 reply; 4+ messages in thread
From: Charles Keepax @ 2026-11-04 11:04 UTC (permalink / raw)
To: Tang Bin
Cc: david.rhodes, rf, lgirdwood, broonie, perex, tiwai, linux-sound,
patches, linux-kernel, stable
On Wed, Nov 04, 2026 at 04:02:57PM +0800, Tang Bin wrote:
> cs42l43_pll_ev() PRE_PMU arm enables mclk (when refclk_src is MCLK) then
> calls cs42l43_enable_pll(). If PLL enable fails, ret is negative and DAPM
> does not power up the widget, so POST_PMD never runs and the matching
> clk_disable_unprepare(mclk) at line 1621 is skipped - mclk refcount leaked.
> Roll back the mclk enable on PLL failure.
Could you point to the relevant bits of the core code here? My
understanding is that DAPM mostly just carrys on in the case of
an error from an event handler, so I would not expect the
sequence to play out as you describe.
Thanks,
Charles
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU
2026-11-04 11:04 ` Charles Keepax
@ 2026-11-06 1:01 ` Tang Bin
0 siblings, 0 replies; 4+ messages in thread
From: Tang Bin @ 2026-11-06 1:01 UTC (permalink / raw)
To: Charles Keepax
Cc: david.rhodes, rf, lgirdwood, broonie, perex, tiwai, linux-sound,
patches, linux-kernel, stable, Tang Bin
Hi Charles,
Thanks for the review and pointing this out.
On Wed, Nov 04, 2026 at 11:04:26AM +0000, Charles Keepax wrote:
> Could you point to the relevant bits of the core code here? My
> understanding is that DAPM mostly just carrys on in the case of
> an error from an event handler, so I would not expect the
> sequence to play out as you describe.
You are absolutely right. I dug into dapm_seq_check_event() in soc-dapm.c.
As you noted, if the event handler returns an error, DAPM only logs it
(via dev_err) but continues the power-up sequence.
Therefore, the widget is still marked as powered, and the matching POST_PMD
will indeed run and execute clk_disable_unprepare(mclk) as expected. There
is no reference count leak here.
My initial premise was incorrect. Please drop this patch.
Best regards,
Tang Bin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-06 1:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 8:02 [PATCH] ASoC: cs42l43: leak MCLK when PLL enable fails on PRE_PMU Tang Bin
2026-11-04 8:12 ` sashiko-bot
2026-11-04 11:04 ` Charles Keepax
2026-11-06 1:01 ` Tang Bin
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.