ASoC: Intel: Fix MCLK leaks in
Subsystems (3)
v4 cover ASoC: Intel: Fix MCLK leaks in
From: Aravind Anilraj <[email protected]>
In three Intel ASoC board drivers, the EVENT_ON path in platform_clock_control() enables MCLK via clk_prepare_enable() but fails to call clk_disable_unprepare() on subsequent error paths, leaking the clock reference.
v4: Split dev_err formatting fix into a separate patch 4 as suggested by Mark Brown. Add return code to the error message for better diagnostics.
v3: Restored missing clk_disable_unprepare() guard in patch 2 that was accidently dropped during v2 rebase.
v2: Guard clk_disable_unprepare() with SND_SOC_DAPM_EVENT_ON() to avoid calling it in the EVENT_OFF error path where MCLK was never enabled.
Fix this across all three affected drivers.
Aravind Anilraj (4):
ASoC: Intel: bytcr_rt5640: Fix MCLK leak on platform_clock_control
error
ASoC: Intel: bytcr_rt5651: Fix MCLK leak on platform_clock_control
error
ASoC: Intel: cht_bsw_rt5672: Fix MCLK leak in platform_clock_control
ASoC: Intel: boards: Log error code in MCLK configuration failure
sound/soc/intel/boards/bytcr_rt5640.c | 4 +++- sound/soc/intel/boards/bytcr_rt5651.c | 4 +++- sound/soc/intel/boards/cht_bsw_rt5672.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
PATCH v4 1/4 ASoC: Intel: bytcr_rt5640: Fix MCLK leak on platform_clock_control error
From: Aravind Anilraj <[email protected]>
If byt_rt5640_prepare_and_enable_pll1() fails, the function returns without calling clk_disable_unprepare() on priv->mclk, which was already enabled earlier in the same code path. Add the missing clk_disable_unprepare() call before returning the error.
--- sound/soc/intel/boards/bytcr_rt5640.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/intel/boards/bytcr_rt5640.c +2 -0
@@ -304,6 +304,8 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (ret <0 ) {dev_err (card->dev,"can't set codec sysclk: %d\n" , ret); +if (SND_SOC_DAPM_EVENT_ON (event)) +clk_disable_unprepare (priv->mclk);return ret; }
Signature · 1 line
2.47.3
Cezary Rojewski
maintainerRe: [PATCH v4 1/4] ASoC: Intel: bytcr_rt5640: Fix MCLK leak on platform_clock_control error
Quoted 17 lines · On 2026-03-28 6:25 AM, [email protected] wrote:
From: Aravind Anilraj <[email protected]>
If
byt_rt5640_prepare_and_enable_pll1()fails, the function returns without callingclk_disable_unprepare()onpriv->mclk, which was already enabled earlier in the same code path. Add the missingclk_disable_unprepare()call before returning the error.Signed-off-by Aravind Anilraj <[email protected]>--- sound/soc/intel/boards/bytcr_rt5640.c | 2 ++ 1 file changed, 2 insertions(+)sound/soc/intel/boards/bytcr_rt5640.c +0
-0
sound/soc/intel/boards/bytcr_rt5640.c static int platform_clock_control(struct snd_soc_dapm_widget *w, · line 308
Quoted 5 lines
sound/soc/intel/boards/bytcr_rt5640.c +2
-0@@ -304,6 +304,8 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (ret <0 ) {dev_err (card->dev,"can't set codec sysclk: %d\n" , ret); +if (SND_SOC_DAPM_EVENT_ON (event)) +clk_disable_unprepare (priv->mclk);
This if-statement complicates the situation unnecessarily. Please do the check in scope of "if (SND_SOC_DAPM_EVENT_ON(event))" found earlier in this function.
Quoted 3 lines
sound/soc/intel/boards/bytcr_rt5640.c +0
-0return ret; }
PATCH v4 2/4 ASoC: Intel: bytcr_rt5651: Fix MCLK leak on platform_clock_control error
In reply to [email protected]From: Aravind Anilraj <[email protected]>
If byt_rt5651_prepare_and_enable_pll1() fails, the function returns without calling clk_disable_unprepare() on priv->mclk, which was already enabled earlier in the same code path. Add the missing clk_disable_unprepare() call before returning the error.
--- sound/soc/intel/boards/bytcr_rt5651.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/intel/boards/bytcr_rt5651.c +3 -1
@@ -205,7 +205,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (SND_SOC_DAPM_EVENT_ON (event)) { ret =clk_prepare_enable (priv->mclk);if (ret <0 ) { -dev_err (card->dev,"could not configure MCLK state" ); +dev_err (card->dev,"could not configure MCLK state\n" );return ret; } ret =byt_rt5651_prepare_and_enable_pll1 (codec_dai,48000 ,50 );
@@ -224,6 +224,8 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (ret <0 ) {dev_err (card->dev,"can't set codec sysclk: %d\n" , ret); +if (SND_SOC_DAPM_EVENT_ON (event)) +clk_disable_unprepare (priv->mclk);return ret; }
Signature · 1 line
2.47.3
Cezary Rojewski
maintainerRe: [PATCH v4 2/4] ASoC: Intel: bytcr_rt5651: Fix MCLK leak on platform_clock_control error
Quoted 26 lines · On 2026-03-28 6:25 AM, [email protected] wrote:
From: Aravind Anilraj <[email protected]>
If
byt_rt5651_prepare_and_enable_pll1()fails, the function returns without callingclk_disable_unprepare()onpriv->mclk, which was already enabled earlier in the same code path. Add the missingclk_disable_unprepare()call before returning the error.Signed-off-by Aravind Anilraj <[email protected]>--- sound/soc/intel/boards/bytcr_rt5651.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)sound/soc/intel/boards/bytcr_rt5651.c +1
-1@@ -205,7 +205,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (SND_SOC_DAPM_EVENT_ON (event)) { ret =clk_prepare_enable (priv->mclk);if (ret <0 ) { -dev_err (card->dev,"could not configure MCLK state" ); +dev_err (card->dev,"could not configure MCLK state\n" );return ret; } ret =byt_rt5651_prepare_and_enable_pll1 (codec_dai,48000 ,50 );
sound/soc/intel/boards/bytcr_rt5651.c static int platform_clock_control(struct snd_soc_dapm_widget *w, · line 228
Quoted 5 lines
sound/soc/intel/boards/bytcr_rt5651.c +2
-0@@ -224,6 +224,8 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (ret <0 ) {dev_err (card->dev,"can't set codec sysclk: %d\n" , ret); +if (SND_SOC_DAPM_EVENT_ON (event)) +clk_disable_unprepare (priv->mclk);
Same as for bytcr_rt5640:
This if-statement complicates the situation unnecessarily. Please do the check in scope of "if (SND_SOC_DAPM_EVENT_ON(event))" found earlier in this function.
Quoted 3 lines
sound/soc/intel/boards/bytcr_rt5651.c +0
-0return ret; }
Mark Brown
maintainerRe: [PATCH v4 2/4] ASoC: Intel: bytcr_rt5651: Fix MCLK leak on platform_clock_control error
In reply to [email protected]sound/soc/intel/boards/bytcr_rt5651.c static int platform_clock_control(struct snd_soc_dapm_widget *w, · line 211
Quoted 13 lines · On Sat, Mar 28, 2026 at 01:25:53AM -0400, [email protected] wrote:
If
byt_rt5651_prepare_and_enable_pll1()fails, the function returns without callingclk_disable_unprepare()onpriv->mclk, which was already enabled earlier in the same code path. Add the missingclk_disable_unprepare()call before returning the error.sound/soc/intel/boards/bytcr_rt5651.c +1
-1if (SND_SOC_DAPM_EVENT_ON (event)) { ret =clk_prepare_enable (priv->mclk);if (ret <0 ) { -dev_err (card->dev,"could not configure MCLK state" ); +dev_err (card->dev,"could not configure MCLK state\n" );return ret; } ret =byt_rt5651_prepare_and_enable_pll1 (codec_dai,48000 ,50 );
As I said on prior versions this has an unrelated change in this print.
Please don't ignore review comments, people are generally making them for a reason and are likely to have the same concerns if issues remain unaddressed. Having to repeat the same comments can get repetitive and make people question the value of time spent reviewing. If you disagree with the review comments that's fine but you need to reply and discuss your concerns so that the reviewer can understand your decisions.
PATCH v4 3/4 ASoC: Intel: cht_bsw_rt5672: Fix MCLK leak in platform_clock_control
In reply to [email protected]From: Aravind Anilraj <[email protected]>
If snd_soc_dai_set_pll() or snd_soc_dai_set_sysclk() fail inside the EVENT_ON path, the function returns without calling clk_disable_unprepare() on ctx->mclk, which was already enabled earlier in the same code path. Add the missing clk_disable_unprepare() calls before returning the error.
--- sound/soc/intel/boards/cht_bsw_rt5672.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/intel/boards/cht_bsw_rt5672.c +3 -1
@@ -67,7 +67,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, ret =clk_prepare_enable (ctx->mclk);if (ret <0 ) {dev_err (card->dev, -"could not configure MCLK state" ); +"could not configure MCLK state\n" );return ret; } }
@@ -77,6 +77,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, CHT_PLAT_CLK_3_HZ, 48000 * 512);if (ret <0 ) {dev_err (card->dev,"can't set codec pll: %d\n" , ret); +clk_disable_unprepare (ctx->mclk);return ret; }
@@ -85,6 +86,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, 48000 * 512, SND_SOC_CLOCK_IN);if (ret <0 ) {dev_err (card->dev,"can't set codec sysclk: %d\n" , ret); +clk_disable_unprepare (ctx->mclk);return ret; } }else {
Signature · 1 line
2.47.3
Re: [PATCH v4 3/4] ASoC: Intel: cht_bsw_rt5672: Fix MCLK leak in platform_clock_control
Quoted 9 lines · On 2026-03-28 6:25 AM, [email protected] wrote:
From: Aravind Anilraj <[email protected]>
If
snd_soc_dai_set_pll()orsnd_soc_dai_set_sysclk()fail inside theEVENT_ONpath, the function returns without callingclk_disable_unprepare()onctx->mclk, which was already enabled earlier in the same code path. Add the missingclk_disable_unprepare()calls before returning the error.Signed-off-by Aravind Anilraj <[email protected]>
Thank you for the fix.
Quoted 33 lines
--- sound/soc/intel/boards/cht_bsw_rt5672.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)sound/soc/intel/boards/cht_bsw_rt5672.c +3
-1@@ -67,7 +67,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, ret =clk_prepare_enable (ctx->mclk);if (ret <0 ) {dev_err (card->dev, -"could not configure MCLK state" ); +"could not configure MCLK state\n" );return ret; } }@@ -77,6 +77,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, CHT_PLAT_CLK_3_HZ, 48000 * 512);if (ret <0 ) {dev_err (card->dev,"can't set codec pll: %d\n" , ret); +clk_disable_unprepare (ctx->mclk);return ret; }@@ -85,6 +86,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, 48000 * 512, SND_SOC_CLOCK_IN);if (ret <0 ) {dev_err (card->dev,"can't set codec sysclk: %d\n" , ret); +clk_disable_unprepare (ctx->mclk);return ret; } }else {
Cezary Rojewski
maintainerRe: [PATCH v4 3/4] ASoC: Intel: cht_bsw_rt5672: Fix MCLK leak in platform_clock_control
Quoted 19 lines · Cezary Rojewski
Quoted 9 lines · On 2026-03-28 6:25 AM, [email protected] wrote:
From: Aravind Anilraj <[email protected]>
If
snd_soc_dai_set_pll()orsnd_soc_dai_set_sysclk()fail inside theEVENT_ONpath, the function returns without callingclk_disable_unprepare()onctx->mclk, which was already enabled earlier in the same code path. Add the missingclk_disable_unprepare()calls before returning the error.Signed-off-by Aravind Anilraj <[email protected]>Thank you for the fix.
Reviewed-by Cezary Rojewski <[email protected]>Quoted 4 lines
---
sound/soc/intel/boards/cht_bsw_rt5672.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 11 lines
sound/soc/intel/boards/cht_bsw_rt5672.c static int platform_clock_control(struct · line 71
Quoted 11 lines
sound/soc/intel/boards/cht_bsw_rt5672.c +1
-1@@ -67,7 +67,7 @@ static int platform_clock_control(structsnd_soc_dapm_widget *w, ret = clk_prepare_enable(ctx->mclk); if (ret < 0) { dev_err(card->dev, - "could not configure MCLK state"); + "could not configure MCLK state\n");
I've overlooked the string changes. For all three leading patches, please ensure only clk_disable_unprepare() is part of them. The updates to the dev_err() make the patches non-atomic and you already have a dedicated patch for dev_err() - the fourth patch. Do those changes there.
Quoted 3 lines
Quoted 3 lines
sound/soc/intel/boards/cht_bsw_rt5672.c +0
-0return ret; }}
PATCH v4 4/4 ASoC: Intel: boards: Log error code in MCLK configuration failure
In reply to [email protected]From: Aravind Anilraj <[email protected]>
The dev_err() calls in platform_clock_control() for the three Intel ASoC board drivers do not log the return code when clk_prepare_enable() fails, making it harder to diagonse failures. Add the error code to the log message.
--- sound/soc/intel/boards/bytcr_rt5640.c | 2 +- sound/soc/intel/boards/bytcr_rt5651.c | 2 +- sound/soc/intel/boards/cht_bsw_rt5672.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
sound/soc/intel/boards/bytcr_rt5640.c +1 -1
@@ -285,7 +285,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (SND_SOC_DAPM_EVENT_ON (event)) { ret =clk_prepare_enable (priv->mclk);if (ret <0 ) { -dev_err (card->dev,"could not configure MCLK state\n" ); +dev_err (card->dev,"could not configure MCLK state: %d\n" , ret);return ret; } ret =byt_rt5640_prepare_and_enable_pll1 (codec_dai,48000 );
sound/soc/intel/boards/bytcr_rt5651.c +1 -1
@@ -205,7 +205,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,if (SND_SOC_DAPM_EVENT_ON (event)) { ret =clk_prepare_enable (priv->mclk);if (ret <0 ) { -dev_err (card->dev,"could not configure MCLK state\n" ); +dev_err (card->dev,"could not configure MCLK state: %d\n" , ret);return ret; } ret =byt_rt5651_prepare_and_enable_pll1 (codec_dai,48000 ,50 );
sound/soc/intel/boards/cht_bsw_rt5672.c +1 -1
@@ -67,7 +67,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w, ret =clk_prepare_enable (ctx->mclk);if (ret <0 ) {dev_err (card->dev, -"could not configure MCLK state\n" ); +"could not configure MCLK state: %d\n" , ret);return ret; } }
Signature · 1 line
2.47.3