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>,
	Cezary Rojewski <cezary.rojewski@intel.com>
Cc: Support Opensource <support.opensource@diasemi.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: [PATCH v2 01/21] ASoC: codecs: cpcap: Fix devm resource leaks across card bind/unbind
Date: Wed, 23 Sep 2026 15:12:45 +0900	[thread overview]
Message-ID: <20260923061305.4041197-2-chancel.liu@oss.nxp.com> (raw)
In-Reply-To: <20260923061305.4041197-1-chancel.liu@oss.nxp.com>

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

The ASoC component .probe/.remove are called on card bind/unbind, but
component->dev is the underlying platform device. Resources requested
with devm_*(component->dev, ...) or request_irq() in the component
.probe are only released when the platform device is removed, not on
card unbind, leaking on every bind/unbind cycle.

The VAUDIO regulator is a pure hardware resource that only depends on
the platform device, so acquire it with devm_regulator_get() in the
platform probe where its devres lifetime matches the device.

The headset/mic-button IRQs genuinely depend on the component, so
keep them in cpcap_soc_probe() but request them with the non-devm
request_irq() API and free them explicitly in cpcap_soc_remove().

Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
---
 sound/soc/codecs/cpcap.c | 74 ++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 29 deletions(-)

diff --git a/sound/soc/codecs/cpcap.c b/sound/soc/codecs/cpcap.c
index 0262900fbb7d..dda68165b817 100644
--- a/sound/soc/codecs/cpcap.c
+++ b/sound/soc/codecs/cpcap.c
@@ -1622,21 +1622,12 @@ static int cpcap_soc_probe(struct snd_soc_component *component)
 {
 	struct platform_device *pdev = to_platform_device(component->dev);
 	struct snd_soc_card *card = component->card;
-	struct cpcap_audio *cpcap;
+	struct cpcap_audio *cpcap = dev_get_drvdata(component->dev);
 	int err;
 
-	cpcap = devm_kzalloc(component->dev, sizeof(*cpcap), GFP_KERNEL);
-	if (!cpcap)
-		return -ENOMEM;
-
 	snd_soc_component_set_drvdata(component, cpcap);
 	cpcap->component = component;
 
-	cpcap->vaudio = devm_regulator_get(component->dev, "VAUDIO");
-	if (IS_ERR(cpcap->vaudio))
-		return dev_err_probe(component->dev, PTR_ERR(cpcap->vaudio),
-				     "Cannot get VAUDIO regulator\n");
-
 	err = snd_soc_card_jack_new(card, "Headphones",
 				    SND_JACK_HEADSET | SND_JACK_BTN_0,
 				    &cpcap->jack);
@@ -1660,13 +1651,13 @@ static int cpcap_soc_probe(struct snd_soc_component *component)
 	if (cpcap->hsirq < 0)
 		return cpcap->hsirq;
 
-	err = devm_request_threaded_irq(component->dev, cpcap->hsirq, NULL,
-					cpcap_hs_irq_thread,
-					IRQF_TRIGGER_RISING |
-					IRQF_TRIGGER_FALLING |
-					IRQF_ONESHOT,
-					"cpcap-codec-hs",
-					component);
+	err = request_threaded_irq(cpcap->hsirq, NULL,
+				   cpcap_hs_irq_thread,
+				   IRQF_TRIGGER_RISING |
+				   IRQF_TRIGGER_FALLING |
+				   IRQF_ONESHOT,
+				   "cpcap-codec-hs",
+				   component);
 	if (err) {
 		dev_warn(component->dev, "no HS irq%i: %i\n",
 			 cpcap->hsirq, err);
@@ -1674,25 +1665,27 @@ static int cpcap_soc_probe(struct snd_soc_component *component)
 	}
 
 	cpcap->mb2irq = platform_get_irq_byname(pdev, "mb2");
-	if (cpcap->mb2irq < 0)
-		return cpcap->mb2irq;
-
-	err = devm_request_threaded_irq(component->dev, cpcap->mb2irq, NULL,
-					cpcap_mb2_irq_thread,
-					IRQF_TRIGGER_RISING |
-					IRQF_TRIGGER_FALLING |
-					IRQF_ONESHOT,
-					"cpcap-codec-mb2",
-					component);
+	if (cpcap->mb2irq < 0) {
+		err = cpcap->mb2irq;
+		goto err_free_hsirq;
+	}
+
+	err = request_threaded_irq(cpcap->mb2irq, NULL,
+				   cpcap_mb2_irq_thread,
+				   IRQF_TRIGGER_RISING |
+				   IRQF_TRIGGER_FALLING |
+				   IRQF_ONESHOT,
+				   "cpcap-codec-mb2",
+				   component);
 	if (err) {
 		dev_warn(component->dev, "no MB2 irq%i: %i\n",
 			 cpcap->mb2irq, err);
-		return err;
+		goto err_free_hsirq;
 	}
 
 	err = cpcap_audio_reset(component, false);
 	if (err)
-		return err;
+		goto err_free_mb2irq;
 
 	cpcap_hs_irq_thread(cpcap->hsirq, component);
 
@@ -1700,6 +1693,13 @@ static int cpcap_soc_probe(struct snd_soc_component *component)
 	enable_irq_wake(cpcap->mb2irq);
 
 	return 0;
+
+err_free_mb2irq:
+	free_irq(cpcap->mb2irq, component);
+err_free_hsirq:
+	free_irq(cpcap->hsirq, component);
+
+	return err;
 }
 
 static void cpcap_soc_remove(struct snd_soc_component *component)
@@ -1708,6 +1708,9 @@ static void cpcap_soc_remove(struct snd_soc_component *component)
 
 	disable_irq_wake(cpcap->hsirq);
 	disable_irq_wake(cpcap->mb2irq);
+
+	free_irq(cpcap->mb2irq, component);
+	free_irq(cpcap->hsirq, component);
 }
 
 static int cpcap_set_bias_level(struct snd_soc_component *component,
@@ -1754,11 +1757,24 @@ static int cpcap_codec_probe(struct platform_device *pdev)
 {
 	struct device_node *codec_node =
 		of_get_child_by_name(pdev->dev.parent->of_node, "audio-codec");
+	struct cpcap_audio *cpcap;
+
 	if (!codec_node)
 		return -ENODEV;
 
 	pdev->dev.of_node = codec_node;
 
+	cpcap = devm_kzalloc(&pdev->dev, sizeof(*cpcap), GFP_KERNEL);
+	if (!cpcap)
+		return -ENOMEM;
+
+	cpcap->vaudio = devm_regulator_get(&pdev->dev, "VAUDIO");
+	if (IS_ERR(cpcap->vaudio))
+		return dev_err_probe(&pdev->dev, PTR_ERR(cpcap->vaudio),
+				     "Cannot get VAUDIO regulator\n");
+
+	platform_set_drvdata(pdev, cpcap);
+
 	return devm_snd_soc_register_component(&pdev->dev, &soc_codec_dev_cpcap,
 				      cpcap_dai, ARRAY_SIZE(cpcap_dai));
 }
-- 
2.50.1


  reply	other threads:[~2026-09-23  6:13 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  6:12 [PATCH v2 00/21] ASoC: codecs: Fix " Chancel Liu
2026-09-23  6:12 ` Chancel Liu [this message]
2026-09-23  6:12 ` [PATCH v2 02/21] ASoC: codecs: da7218: Fix devm " Chancel Liu
2026-09-23  6:12 ` [PATCH v2 03/21] ASoC: codecs: tlv320aic32x4: Fix clock leak from runtime callbacks Chancel Liu
2026-09-23  6:12 ` [PATCH v2 04/21] ASoC: codecs: twl4030: Acquire board params and hs_extmute GPIO in the platform probe Chancel Liu
2026-09-23  6:12 ` [PATCH v2 05/21] ASoC: codecs: es8316: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-23  8:19   ` Cezary Rojewski
2026-09-23  6:12 ` [PATCH v2 06/21] ASoC: codecs: es8323: " Chancel Liu
2026-09-23  6:12 ` [PATCH v2 07/21] ASoC: codecs: es8311: " Chancel Liu
2026-09-23  6:12 ` [PATCH v2 08/21] ASoC: codecs: es8328: Move clk acquisition to the bus probe Chancel Liu
2026-09-23  6:12 ` [PATCH v2 09/21] ASoC: codecs: rt5640: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-23  8:16   ` Cezary Rojewski
2026-09-23  8:22     ` Chancel Liu
2026-09-23  6:12 ` [PATCH v2 10/21] ASoC: codecs: rt5616: " Chancel Liu
2026-09-23  6:12 ` [PATCH v2 11/21] ASoC: codecs: rt5514: Move clk " Chancel Liu
2026-09-23  8:19   ` Cezary Rojewski
2026-09-23  6:12 ` [PATCH v2 12/21] ASoC: codecs: rt5682s: Move mclk " Chancel Liu
2026-09-23  6:12 ` [PATCH v2 13/21] ASoC: codecs: max98090: " Chancel Liu
2026-09-23  6:12 ` [PATCH v2 14/21] ASoC: codecs: max98095: " Chancel Liu
2026-09-23  6:12 ` [PATCH v2 15/21] ASoC: codecs: wm8985: Move regulator acquisition to the bus probe Chancel Liu
2026-09-23  8:56   ` Charles Keepax
2026-09-23  6:13 ` [PATCH v2 16/21] ASoC: codecs: wm8955: Move regulator acquisition to the i2c probe Chancel Liu
2026-09-23  6:13 ` [PATCH v2 17/21] ASoC: codecs: es8389: Move regulator and mclk " Chancel Liu
2026-09-23  6:13 ` [PATCH v2 18/21] ASoC: codecs: rt5677-spi: Free the DSP context on component remove Chancel Liu
2026-09-23  6:13 ` [PATCH v2 19/21] ASoC: codecs: rt1011: Free the bq/drc coefficient arrays " Chancel Liu
2026-09-23  6:13 ` [PATCH v2 20/21] ASoC: codecs: rt5645: Free the hardware EQ parameters " Chancel Liu
2026-09-23  6:13 ` [PATCH v2 21/21] ASoC: codecs: rt5514-spi: Free the DSP context " Chancel Liu
2026-09-23 12:27 ` [PATCH v2 00/21] ASoC: codecs: Fix resource leaks across card bind/unbind 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=20260923061305.4041197-2-chancel.liu@oss.nxp.com \
    --to=chancel.liu@oss.nxp.com \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --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®