public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
From: Hsieh Hung-En <hungen3108@gmail.com>
To: broonie@kernel.org, lgirdwood@gmail.com
Cc: linux-sound@vger.kernel.org, perex@perex.cz, tiwai@suse.com,
	ckeepax@opensource.cirrus.com, kuninori.morimoto.gx@renesas.com,
	matteomartelli3@gmail.com, Hsieh Hung-En <hungen3108@gmail.com>
Subject: [PATCH v1 2/2] ASoC: es8311: Fix clock leak and check update_bits in set_bias_level()
Date: Wed, 15 Apr 2026 11:02:52 +0800	[thread overview]
Message-ID: <20260415030252.5547-3-hungen3108@gmail.com> (raw)
In-Reply-To: <20260415030252.5547-1-hungen3108@gmail.com>

In es8311_set_bias_level(), the return value of
snd_soc_component_update_bits() was ignored. If this fails, not only
is the VMID selection not applied, but the previously enabled mclk
is left running, leading to an unbalanced clock reference count
(clock leak).

Check the return value and ensure clk_disable_unprepare() is called on
failure to maintain proper resource management.

Signed-off-by: Hsieh Hung-En <hungen3108@gmail.com>
---
 sound/soc/codecs/es8311.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/es8311.c b/sound/soc/codecs/es8311.c
index 9e371e2d6eae..564af5c04dbb 100644
--- a/sound/soc/codecs/es8311.c
+++ b/sound/soc/codecs/es8311.c
@@ -761,6 +761,7 @@ static int es8311_set_bias_level(struct snd_soc_component *component,
 {
 	struct es8311_priv *es8311 = snd_soc_component_get_drvdata(component);
 	struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
+	int ret;
 
 	switch (level) {
 	case SND_SOC_BIAS_ON:
@@ -769,17 +770,21 @@ static int es8311_set_bias_level(struct snd_soc_component *component,
 		break;
 	case SND_SOC_BIAS_STANDBY:
 		if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF) {
-			int ret = clk_prepare_enable(es8311->mclk);
+			ret = clk_prepare_enable(es8311->mclk);
 			if (ret) {
 				dev_err(component->dev,
 					"unable to prepare mclk\n");
 				return ret;
 			}
 
-			snd_soc_component_update_bits(
-				component, ES8311_SYS3,
-				ES8311_SYS3_PDN_VMIDSEL_MASK,
-				ES8311_SYS3_PDN_VMIDSEL_STARTUP_NORMAL_SPEED);
+			ret = snd_soc_component_update_bits(
+				      component, ES8311_SYS3,
+				      ES8311_SYS3_PDN_VMIDSEL_MASK,
+				      ES8311_SYS3_PDN_VMIDSEL_STARTUP_NORMAL_SPEED);
+			if (ret < 0) {
+				clk_disable_unprepare(es8311->mclk);
+				return ret;
+			}
 		}
 
 		break;
-- 
2.34.1


  parent reply	other threads:[~2026-04-15  3:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  3:02 [PATCH v1 0/2] ASoC: es8311: Improve error handling and power Hsieh Hung-En
2026-04-15  3:02 ` [PATCH v1 1/2] ASoC: es8311: Check regcache_sync() error in resume Hsieh Hung-En
2026-04-15  3:02 ` Hsieh Hung-En [this message]
2026-04-16 12:39 ` [PATCH v1 0/2] ASoC: es8311: Improve error handling and power Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260415030252.5547-3-hungen3108@gmail.com \
    --to=hungen3108@gmail.com \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=matteomartelli3@gmail.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox