Skip to contentSkip to conversation

ASoC: Intel: Fix MCLK leaks and improve error

PATCH Superseded [email protected] 2 participants 6 messages Mar 31 – Apr 1

Subsystems (3)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover ASoC: Intel: Fix MCLK leaks and improve error

From: Aravind Anilraj <[email protected]>

This series fixes MCLK reference leaks in the platform_clock_control() paths of bytcr_rt5640, bytcr_rt5651, and cht_bsw_rt5672.

It also improves error reporting by including return codes in dev_err() messages.

Changes in v5:
Split functional fixes from logging changes as requested by Cezary Rojewski.
Include return codes and newlines in error messages as suggested by Mark Brown.
Move clk_disable_unprepare() into the relevant error paths.

Changes in v4:
Add missing clk_disable_unprepare() in error paths for cht_bsw_rt5672. Align error message formatting across 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   | 6 ++++--
 sound/soc/intel/boards/bytcr_rt5651.c   | 5 ++++-
 sound/soc/intel/boards/cht_bsw_rt5672.c | 4 +++-
 3 files changed, 11 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v5 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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/intel/boards/bytcr_rt5640.c +4 -2
index 103e0b445603..cd611c0da4e1 100644
@@ -285,10 +285,12 @@ 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");
 			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
@@ -303,7 +305,7 @@ 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);
+		dev_err(card->dev, "can't set codec sysclk");
 		return ret;
 	}
 
Signature · 1 line
2.47.3
maintainer
#2 lore raw

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

sound/soc/intel/boards/bytcr_rt5640.c static int platform_clock_control(struct snd_soc_dapm_widget *w, · line 290

Quoted 5 lines · On Tue, Mar 31, 2026 at 12:36:32PM -0400, [email protected] wrote:
sound/soc/intel/boards/bytcr_rt5640.c +1 -1
 		if (ret < 0) {
-			dev_err(card->dev, "could not configure MCLK state\n");
+			dev_err(card->dev, "could not configure MCLK state");
 			return ret;
 		}

To repeat what I have said multiple times:

| 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.

Please pay attention.

#3 lore raw

PATCH v5 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 | 3 +++
 1 file changed, 3 insertions(+)
sound/soc/intel/boards/bytcr_rt5651.c +3 -0
index 68cf463f1d50..e2f59a008b29 100644
@@ -209,6 +209,9 @@ 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
#4 lore raw

PATCH v5 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 | 2 ++
 1 file changed, 2 insertions(+)
sound/soc/intel/boards/cht_bsw_rt5672.c +2 -0
index 359723f2700e..0c2435edbd08 100644
@@ -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
#5 lore raw

PATCH v5 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 diagnose 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
index cd611c0da4e1..a934b3684347 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");
+			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 e2f59a008b29..3c5082034f5c 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 0c2435edbd08..016732a57278 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