mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chancel Liu <chancel.liu@oss.nxp.com>
To: Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Charles Keepax <ckeepax@opensource.cirrus.com>,
	Oder Chiou <oder_chiou@realtek.com>
Cc: Support Opensource <support.opensource@diasemi.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: [PATCH 02/21] ASoC: da7218: Fix devm resource leaks across card bind/unbind
Date: Mon, 21 Sep 2026 19:46:21 +0900	[thread overview]
Message-ID: <20260921104640.1941554-3-chancel.liu@oss.nxp.com> (raw)
In-Reply-To: <20260921104640.1941554-1-chancel.liu@oss.nxp.com>

From: Chancel Liu <chancel.liu@nxp.com>

component->dev is the underlying I2C device, so resources requested
with devm_*(component->dev, ...) in the component .probe are only
released when the I2C device is removed, not on card unbind. This
leaks the mclk clock, the regulator bulk and the IRQ on every card
bind/unbind cycle.

Move the mclk clock and the regulator supplies (pure hardware
resources tied to the platform device) to da7218_i2c_probe() using
devm on &i2c->dev. Keep the IRQ in the component .probe (it feeds the
component) but request it with the non-devm API and free it in
da7218_remove().

Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
---
 sound/soc/codecs/da7218.c | 49 ++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/sound/soc/codecs/da7218.c b/sound/soc/codecs/da7218.c
index 361daf14152e..f8928545b70f 100644
--- a/sound/soc/codecs/da7218.c
+++ b/sound/soc/codecs/da7218.c
@@ -2638,18 +2638,7 @@ static int da7218_handle_supplies(struct snd_soc_component *component)
 	struct da7218_priv *da7218 = snd_soc_component_get_drvdata(component);
 	struct regulator *vddio;
 	u8 io_voltage_lvl = DA7218_IO_VOLTAGE_LEVEL_2_5V_3_6V;
-	int i, ret;
-
-	/* Get required supplies */
-	for (i = 0; i < DA7218_NUM_SUPPLIES; ++i)
-		da7218->supplies[i].supply = da7218_supply_names[i];
-
-	ret = devm_regulator_bulk_get(component->dev, DA7218_NUM_SUPPLIES,
-				      da7218->supplies);
-	if (ret) {
-		dev_err(component->dev, "Failed to get supplies\n");
-		return ret;
-	}
+	int ret;
 
 	/* Determine VDDIO voltage provided */
 	vddio = da7218->supplies[DA7218_SUPPLY_VDDIO].consumer;
@@ -2895,13 +2884,6 @@ static int da7218_probe(struct snd_soc_component *component)
 
 	da7218_handle_pdata(component);
 
-	/* Check if MCLK provided, if not the clock is NULL */
-	da7218->mclk = devm_clk_get_optional(component->dev, "mclk");
-	if (IS_ERR(da7218->mclk)) {
-		ret = PTR_ERR(da7218->mclk);
-		goto err_disable_reg;
-	}
-
 	/* Default PC to free-running */
 	snd_soc_component_write(component, DA7218_PC_COUNT, DA7218_PC_FREERUN_MASK);
 
@@ -2965,10 +2947,10 @@ static int da7218_probe(struct snd_soc_component *component)
 	}
 
 	if (da7218->irq) {
-		ret = devm_request_threaded_irq(component->dev, da7218->irq, NULL,
-						da7218_irq_thread,
-						IRQF_TRIGGER_LOW | IRQF_ONESHOT,
-						"da7218", component);
+		ret = request_threaded_irq(da7218->irq, NULL,
+					   da7218_irq_thread,
+					   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					   "da7218", component);
 		if (ret != 0) {
 			dev_err(component->dev, "Failed to request IRQ %d: %d\n",
 				da7218->irq, ret);
@@ -2989,6 +2971,9 @@ static void da7218_remove(struct snd_soc_component *component)
 {
 	struct da7218_priv *da7218 = snd_soc_component_get_drvdata(component);
 
+	if (da7218->irq)
+		free_irq(da7218->irq, component);
+
 	regulator_bulk_disable(DA7218_NUM_SUPPLIES, da7218->supplies);
 }
 
@@ -3259,7 +3244,7 @@ static const struct regmap_config da7218_regmap_config = {
 static int da7218_i2c_probe(struct i2c_client *i2c)
 {
 	struct da7218_priv *da7218;
-	int ret;
+	int i, ret;
 
 	da7218 = devm_kzalloc(&i2c->dev, sizeof(*da7218), GFP_KERNEL);
 	if (!da7218)
@@ -3284,6 +3269,22 @@ static int da7218_i2c_probe(struct i2c_client *i2c)
 		return ret;
 	}
 
+	/* Get required supplies */
+	for (i = 0; i < DA7218_NUM_SUPPLIES; ++i)
+		da7218->supplies[i].supply = da7218_supply_names[i];
+
+	ret = devm_regulator_bulk_get(&i2c->dev, DA7218_NUM_SUPPLIES,
+				      da7218->supplies);
+	if (ret) {
+		dev_err(&i2c->dev, "Failed to get supplies\n");
+		return ret;
+	}
+
+	/* Check if MCLK provided, if not the clock is NULL */
+	da7218->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
+	if (IS_ERR(da7218->mclk))
+		return PTR_ERR(da7218->mclk);
+
 	ret = devm_snd_soc_register_component(&i2c->dev,
 			&soc_component_dev_da7218, &da7218_dai, 1);
 	if (ret < 0) {
-- 
2.50.1


  parent reply	other threads:[~2026-09-21 10:47 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 10:46 [PATCH 00/21] ASoC: codecs: Fix " Chancel Liu
2026-09-21 10:46 ` [PATCH 01/21] ASoC: cpcap: Fix devm " Chancel Liu
2026-09-21 10:46 ` Chancel Liu [this message]
2026-09-21 10:46 ` [PATCH 03/21] ASoC: tlv320aic32x4: Fix clock leak from runtime callbacks Chancel Liu
2026-09-21 10:46 ` [PATCH 04/21] ASoC: twl4030: Acquire board params and hs_extmute GPIO in the platform probe Chancel Liu
2026-09-21 10:46 ` [PATCH 05/21] ASoC: es8316: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-21 10:46 ` [PATCH 06/21] ASoC: es8323: " Chancel Liu
2026-09-21 13:17   ` Mark Brown
2026-09-21 13:18     ` Mark Brown
2026-09-22  2:18       ` Chancel Liu
2026-09-21 10:46 ` [PATCH 07/21] ASoC: es8311: " Chancel Liu
2026-09-21 10:46 ` [PATCH 08/21] ASoC: es8328: Move clk acquisition to the bus probe Chancel Liu
2026-09-21 10:46 ` [PATCH 09/21] ASoC: rt5640: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-21 18:28   ` Cezary Rojewski
2026-09-21 10:46 ` [PATCH 10/21] ASoC: rt5616: " Chancel Liu
2026-09-21 10:46 ` [PATCH 11/21] ASoC: rt5514: Move clk " Chancel Liu
2026-09-21 10:46 ` [PATCH 12/21] ASoC: rt5682s: Move mclk " Chancel Liu
2026-09-21 18:44   ` Cezary Rojewski
2026-09-22  2:34     ` Chancel Liu
2026-09-21 10:46 ` [PATCH 13/21] ASoC: max98090: " Chancel Liu
2026-09-21 10:46 ` [PATCH 14/21] ASoC: max98095: " Chancel Liu
2026-09-21 10:46 ` [PATCH 15/21] ASoC: wm8985: Move regulator acquisition to the bus probe Chancel Liu
2026-09-21 11:52   ` Charles Keepax
2026-09-22  2:01     ` Chancel Liu
2026-09-21 10:46 ` [PATCH 16/21] ASoC: wm8955: Move regulator acquisition to the i2c probe Chancel Liu
2026-09-21 10:58   ` Charles Keepax
2026-09-21 10:46 ` [PATCH 17/21] ASoC: es8389: Move regulator and mclk " Chancel Liu
2026-09-21 10:46 ` [PATCH 18/21] ASoC: rt5677-spi: Free the DSP context on component remove Chancel Liu
2026-09-21 10:46 ` [PATCH 19/21] ASoC: rt1011: Free the bq/drc coefficient arrays " Chancel Liu
2026-09-21 10:46 ` [PATCH 20/21] ASoC: rt5645: Free the hardware EQ parameters " Chancel Liu
2026-09-21 10:46 ` [PATCH 21/21] ASoC: rt5514-spi: Free the DSP context " Chancel Liu
2026-09-21 13:23   ` Mark Brown
2026-09-22  2:31     ` Chancel Liu

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=20260921104640.1941554-3-chancel.liu@oss.nxp.com \
    --to=chancel.liu@oss.nxp.com \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=support.opensource@diasemi.com \
    --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

all inboxes | Powered by JetHome®