Skip to contentSkip to conversation

ASoC: Intel: Fix MCLK leaks and clean up error

PATCH In review [email protected] 3 participants 8 messages Apr 1 – Apr 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v6 cover ASoC: Intel: Fix MCLK leaks and clean up error

From: Aravind Anilraj <[email protected]>

This series fixes MCLK resource leaks in the platform_clock_control() implementations for bytcr_rt5640, bytcr_rt5651, and cht_bsw_rt5672.

In the SND_SOC_DAPM_EVENT_ON() path, clk_prepare_enable() is called to enable MCLK, but subsequent failures in codec clock configuration (eg:
*_prepare_and_enable_pll1() or snd_soc_dai_set_sysclk()) return without disabling the clock, leaking a reference.

Patches 1-3 fix this by adding the missing clk_disable_unprepare() calls in the relevant error paths, ensuring proper symmetry between enable and disable operations within the EVENT_ON scope.

Patch 4 moves unrelated logging changes into a separate patch and standardizes error messages.

Changes in v6:
Place cleanup logic within SND_SOC_DAPM_EVENT_ON() scope Avoid redundant condition checks in error paths Split logging changes into a separate patch Address review feedback from Mark Brown and Cezary Rojewski

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 on platform_clock_control
error
ASoC: Intel: Standardize MCLK error logs across RT boards

 sound/soc/intel/boards/bytcr_rt5640.c   | 4 +++-
 sound/soc/intel/boards/bytcr_rt5651.c   | 4 +++-
 sound/soc/intel/boards/cht_bsw_rt5672.c | 6 +++++-
 3 files changed, 11 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v6 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 cleanup call to prevent the clock from leaking.

---
 sound/soc/intel/boards/bytcr_rt5640.c | 2 ++
 1 file changed, 2 insertions(+)
sound/soc/intel/boards/bytcr_rt5640.c +2 -0
index 103e0b445603..e4c21c9c5b38 100644
@@ -289,6 +289,8 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
 			return ret;
 		}
 		ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
+		if (ret < 0)
+			clk_disable_unprepare(priv->mclk);
 	} else {
 		/*
 		 * Set codec clock source to internal clock before
Signature · 1 line
2.47.3
#2 lore raw

PATCH v6 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 cleanup call to prevent the clock from leaking.

---
 sound/soc/intel/boards/bytcr_rt5651.c | 2 ++
 1 file changed, 2 insertions(+)
sound/soc/intel/boards/bytcr_rt5651.c +2 -0
index 68cf463f1d50..8932fc5d6f4f 100644
@@ -209,6 +209,8 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
 			return ret;
 		}
 		ret = byt_rt5651_prepare_and_enable_pll1(codec_dai, 48000, 50);
+		if (ret < 0)
+			clk_disable_unprepare(priv->mclk);
 	} else {
 		/*
 		 * Set codec clock source to internal clock before
Signature · 1 line
2.47.3
#3 lore raw

PATCH v6 3/4 ASoC: Intel: cht_bsw_rt5672: Fix MCLK leak on platform_clock_control error

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, 4 insertions(+)
sound/soc/intel/boards/cht_bsw_rt5672.c +4 -0
index 359723f2700e..57d6997eb12f 100644
@@ -77,6 +77,8 @@ 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);
+			if (ctx->mclk)
+				clk_disable_unprepare(ctx->mclk);
 			return ret;
 		}
 
@@ -85,6 +87,8 @@ 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);
+			if (ctx->mclk)
+				clk_disable_unprepare(ctx->mclk);
 			return ret;
 		}
 	} else {
Signature · 1 line
2.47.3
#4 lore raw

PATCH v6 4/4 ASoC: Intel: Standardize MCLK error logs across RT boards

In reply to [email protected]

From: Aravind Anilraj <[email protected]>

Standardize the error logging in platform_clock_control() by adding missing newline characters to dev_err() strings. Additionally, include the return code in the error messages to assist with debugging.

---
 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
index e4c21c9c5b38..40da3eea5fa7 100644
@@ -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
index 8932fc5d6f4f..62cb4856c797 100644
@@ -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: %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
index 57d6997eb12f..fd4cefd298d2 100644
@@ -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: %d\n", ret);
 				return ret;
 			}
 		}
Signature · 1 line
2.47.3
maintainer Reviewed-by on the v6 series
#5 lore raw
In reply to [email protected]
Quoted 32 lines · On 2026-04-02 12:05 AM, [email protected] wrote:

From: Aravind Anilraj <[email protected]>

This series fixes MCLK resource leaks in the platform_clock_control() implementations for bytcr_rt5640, bytcr_rt5651, and cht_bsw_rt5672.

In the SND_SOC_DAPM_EVENT_ON() path, clk_prepare_enable() is called to enable MCLK, but subsequent failures in codec clock configuration (eg:
*_prepare_and_enable_pll1() or snd_soc_dai_set_sysclk()) return without disabling the clock, leaking a reference.

Patches 1-3 fix this by adding the missing clk_disable_unprepare() calls in the relevant error paths, ensuring proper symmetry between enable and disable operations within the EVENT_ON scope.

Patch 4 moves unrelated logging changes into a separate patch and standardizes error messages.

Changes in v6:
Place cleanup logic within SND_SOC_DAPM_EVENT_ON() scope Avoid redundant condition checks in error paths Split logging changes into a separate patch Address review feedback from Mark Brown and Cezary Rojewski

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 on platform_clock_control
error
ASoC: Intel: Standardize MCLK error logs across RT boards

Quoted 5 lines
  sound/soc/intel/boards/bytcr_rt5640.c   | 4 +++-
  sound/soc/intel/boards/bytcr_rt5651.c   | 4 +++-
  sound/soc/intel/boards/cht_bsw_rt5672.c | 6 +++++-
  3 files changed, 11 insertions(+), 3 deletions(-)

Thank you for the update. For the series:

maintainer
#6 lore raw
In reply to [email protected]
Quoted 8 lines · On Wed, 01 Apr 2026 18:05:03 -0400, [email protected] wrote:

ASoC: Intel: Fix MCLK leaks and clean up error

From: Aravind Anilraj <[email protected]>

This series fixes MCLK resource leaks in the platform_clock_control() implementations for bytcr_rt5640, bytcr_rt5651, and cht_bsw_rt5672.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.1

Thanks!

[1/4] ASoC: Intel: bytcr_rt5640: Fix MCLK leak on platform_clock_control error

      https://git.kernel.org/broonie/sound/c/a02496a29463
[2/4] ASoC: Intel: bytcr_rt5651: Fix MCLK leak on platform_clock_control error
      https://git.kernel.org/broonie/sound/c/b022e5c142ef
[3/4] ASoC: Intel: cht_bsw_rt5672: Fix MCLK leak on platform_clock_control error
      https://git.kernel.org/broonie/sound/c/dced5a373a96
[4/4] ASoC: Intel: Standardize MCLK error logs across RT boards
      https://git.kernel.org/broonie/sound/c/85c38c2fa17d

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

author
#7 lore raw

Thanks Mark, appreciate it.

Quoted 45 lines · Mark Brown
Quoted 8 lines · On Wed, 01 Apr 2026 18:05:03 -0400, [email protected] wrote:

ASoC: Intel: Fix MCLK leaks and clean up error

From: Aravind Anilraj <[email protected]>

This series fixes MCLK resource leaks in the platform_clock_control() implementations for bytcr_rt5640, bytcr_rt5651, and cht_bsw_rt5672.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.1

Thanks!

[1/4] ASoC: Intel: bytcr_rt5640: Fix MCLK leak on platform_clock_control error

      https://git.kernel.org/broonie/sound/c/a02496a29463
[2/4] ASoC: Intel: bytcr_rt5651: Fix MCLK leak on platform_clock_control error
      https://git.kernel.org/broonie/sound/c/b022e5c142ef
[3/4] ASoC: Intel: cht_bsw_rt5672: Fix MCLK leak on platform_clock_control error
      https://git.kernel.org/broonie/sound/c/dced5a373a96
[4/4] ASoC: Intel: Standardize MCLK error logs across RT boards
      https://git.kernel.org/broonie/sound/c/85c38c2fa17d

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