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 02/21] ASoC: codecs: da7218: Fix devm resource leaks across card bind/unbind
Date: Wed, 23 Sep 2026 15:12:46 +0900 [thread overview]
Message-ID: <20260923061305.4041197-3-chancel.liu@oss.nxp.com> (raw)
In-Reply-To: <20260923061305.4041197-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, the platform data parsed
from the device tree and the IRQ on every card bind/unbind cycle.
Move the mclk clock and the regulator supplies (pure hardware
resources tied to the I2C device) to da7218_i2c_probe() using devm on
&i2c->dev. Likewise move the device tree parsing (da7218_of_to_pdata()),
which also allocates with devm, to da7218_i2c_probe() and store the
result in da7218->pdata; the OF helpers now take a struct device so
they no longer depend on the component. 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 | 129 +++++++++++++++++++-------------------
1 file changed, 65 insertions(+), 64 deletions(-)
diff --git a/sound/soc/codecs/da7218.c b/sound/soc/codecs/da7218.c
index 361daf14152e..a538b3dd1635 100644
--- a/sound/soc/codecs/da7218.c
+++ b/sound/soc/codecs/da7218.c
@@ -2298,7 +2298,7 @@ static const struct of_device_id da7218_of_match[] = {
MODULE_DEVICE_TABLE(of, da7218_of_match);
static enum da7218_micbias_voltage
- da7218_of_micbias_lvl(struct snd_soc_component *component, u32 val)
+ da7218_of_micbias_lvl(struct device *dev, u32 val)
{
switch (val) {
case 1200:
@@ -2320,13 +2320,13 @@ static enum da7218_micbias_voltage
case 3000:
return DA7218_MICBIAS_3_0V;
default:
- dev_warn(component->dev, "Invalid micbias level");
+ dev_warn(dev, "Invalid micbias level");
return DA7218_MICBIAS_1_6V;
}
}
static enum da7218_mic_amp_in_sel
- da7218_of_mic_amp_in_sel(struct snd_soc_component *component, const char *str)
+ da7218_of_mic_amp_in_sel(struct device *dev, const char *str)
{
if (!strcmp(str, "diff")) {
return DA7218_MIC_AMP_IN_SEL_DIFF;
@@ -2335,39 +2335,39 @@ static enum da7218_mic_amp_in_sel
} else if (!strcmp(str, "se_n")) {
return DA7218_MIC_AMP_IN_SEL_SE_N;
} else {
- dev_warn(component->dev, "Invalid mic input type selection");
+ dev_warn(dev, "Invalid mic input type selection");
return DA7218_MIC_AMP_IN_SEL_DIFF;
}
}
static enum da7218_dmic_data_sel
- da7218_of_dmic_data_sel(struct snd_soc_component *component, const char *str)
+ da7218_of_dmic_data_sel(struct device *dev, const char *str)
{
if (!strcmp(str, "lrise_rfall")) {
return DA7218_DMIC_DATA_LRISE_RFALL;
} else if (!strcmp(str, "lfall_rrise")) {
return DA7218_DMIC_DATA_LFALL_RRISE;
} else {
- dev_warn(component->dev, "Invalid DMIC data type selection");
+ dev_warn(dev, "Invalid DMIC data type selection");
return DA7218_DMIC_DATA_LRISE_RFALL;
}
}
static enum da7218_dmic_samplephase
- da7218_of_dmic_samplephase(struct snd_soc_component *component, const char *str)
+ da7218_of_dmic_samplephase(struct device *dev, const char *str)
{
if (!strcmp(str, "on_clkedge")) {
return DA7218_DMIC_SAMPLE_ON_CLKEDGE;
} else if (!strcmp(str, "between_clkedge")) {
return DA7218_DMIC_SAMPLE_BETWEEN_CLKEDGE;
} else {
- dev_warn(component->dev, "Invalid DMIC sample phase");
+ dev_warn(dev, "Invalid DMIC sample phase");
return DA7218_DMIC_SAMPLE_ON_CLKEDGE;
}
}
static enum da7218_dmic_clk_rate
- da7218_of_dmic_clkrate(struct snd_soc_component *component, u32 val)
+ da7218_of_dmic_clkrate(struct device *dev, u32 val)
{
switch (val) {
case 1500000:
@@ -2375,13 +2375,13 @@ static enum da7218_dmic_clk_rate
case 3000000:
return DA7218_DMIC_CLK_3_0MHZ;
default:
- dev_warn(component->dev, "Invalid DMIC clock rate");
+ dev_warn(dev, "Invalid DMIC clock rate");
return DA7218_DMIC_CLK_3_0MHZ;
}
}
static enum da7218_hpldet_jack_rate
- da7218_of_jack_rate(struct snd_soc_component *component, u32 val)
+ da7218_of_jack_rate(struct device *dev, u32 val)
{
switch (val) {
case 5:
@@ -2401,13 +2401,13 @@ static enum da7218_hpldet_jack_rate
case 640:
return DA7218_HPLDET_JACK_RATE_640US;
default:
- dev_warn(component->dev, "Invalid jack detect rate");
+ dev_warn(dev, "Invalid jack detect rate");
return DA7218_HPLDET_JACK_RATE_40US;
}
}
static enum da7218_hpldet_jack_debounce
- da7218_of_jack_debounce(struct snd_soc_component *component, u32 val)
+ da7218_of_jack_debounce(struct device *dev, u32 val)
{
switch (val) {
case 0:
@@ -2419,13 +2419,13 @@ static enum da7218_hpldet_jack_debounce
case 4:
return DA7218_HPLDET_JACK_DEBOUNCE_4;
default:
- dev_warn(component->dev, "Invalid jack debounce");
+ dev_warn(dev, "Invalid jack debounce");
return DA7218_HPLDET_JACK_DEBOUNCE_2;
}
}
static enum da7218_hpldet_jack_thr
- da7218_of_jack_thr(struct snd_soc_component *component, u32 val)
+ da7218_of_jack_thr(struct device *dev, u32 val)
{
switch (val) {
case 84:
@@ -2437,76 +2437,76 @@ static enum da7218_hpldet_jack_thr
case 96:
return DA7218_HPLDET_JACK_THR_96PCT;
default:
- dev_warn(component->dev, "Invalid jack threshold level");
+ dev_warn(dev, "Invalid jack threshold level");
return DA7218_HPLDET_JACK_THR_84PCT;
}
}
-static struct da7218_pdata *da7218_of_to_pdata(struct snd_soc_component *component)
+static struct da7218_pdata *da7218_of_to_pdata(struct device *dev,
+ struct da7218_priv *da7218)
{
- struct da7218_priv *da7218 = snd_soc_component_get_drvdata(component);
- struct device_node *np = component->dev->of_node;
+ struct device_node *np = dev->of_node;
struct device_node *hpldet_np;
struct da7218_pdata *pdata;
struct da7218_hpldet_pdata *hpldet_pdata;
const char *of_str;
u32 of_val32;
- pdata = devm_kzalloc(component->dev, sizeof(*pdata), GFP_KERNEL);
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return NULL;
if (of_property_read_u32(np, "dlg,micbias1-lvl-millivolt", &of_val32) >= 0)
- pdata->micbias1_lvl = da7218_of_micbias_lvl(component, of_val32);
+ pdata->micbias1_lvl = da7218_of_micbias_lvl(dev, of_val32);
else
pdata->micbias1_lvl = DA7218_MICBIAS_1_6V;
if (of_property_read_u32(np, "dlg,micbias2-lvl-millivolt", &of_val32) >= 0)
- pdata->micbias2_lvl = da7218_of_micbias_lvl(component, of_val32);
+ pdata->micbias2_lvl = da7218_of_micbias_lvl(dev, of_val32);
else
pdata->micbias2_lvl = DA7218_MICBIAS_1_6V;
if (!of_property_read_string(np, "dlg,mic1-amp-in-sel", &of_str))
pdata->mic1_amp_in_sel =
- da7218_of_mic_amp_in_sel(component, of_str);
+ da7218_of_mic_amp_in_sel(dev, of_str);
else
pdata->mic1_amp_in_sel = DA7218_MIC_AMP_IN_SEL_DIFF;
if (!of_property_read_string(np, "dlg,mic2-amp-in-sel", &of_str))
pdata->mic2_amp_in_sel =
- da7218_of_mic_amp_in_sel(component, of_str);
+ da7218_of_mic_amp_in_sel(dev, of_str);
else
pdata->mic2_amp_in_sel = DA7218_MIC_AMP_IN_SEL_DIFF;
if (!of_property_read_string(np, "dlg,dmic1-data-sel", &of_str))
- pdata->dmic1_data_sel = da7218_of_dmic_data_sel(component, of_str);
+ pdata->dmic1_data_sel = da7218_of_dmic_data_sel(dev, of_str);
else
pdata->dmic1_data_sel = DA7218_DMIC_DATA_LRISE_RFALL;
if (!of_property_read_string(np, "dlg,dmic1-samplephase", &of_str))
pdata->dmic1_samplephase =
- da7218_of_dmic_samplephase(component, of_str);
+ da7218_of_dmic_samplephase(dev, of_str);
else
pdata->dmic1_samplephase = DA7218_DMIC_SAMPLE_ON_CLKEDGE;
if (of_property_read_u32(np, "dlg,dmic1-clkrate-hz", &of_val32) >= 0)
- pdata->dmic1_clk_rate = da7218_of_dmic_clkrate(component, of_val32);
+ pdata->dmic1_clk_rate = da7218_of_dmic_clkrate(dev, of_val32);
else
pdata->dmic1_clk_rate = DA7218_DMIC_CLK_3_0MHZ;
if (!of_property_read_string(np, "dlg,dmic2-data-sel", &of_str))
- pdata->dmic2_data_sel = da7218_of_dmic_data_sel(component, of_str);
+ pdata->dmic2_data_sel = da7218_of_dmic_data_sel(dev, of_str);
else
pdata->dmic2_data_sel = DA7218_DMIC_DATA_LRISE_RFALL;
if (!of_property_read_string(np, "dlg,dmic2-samplephase", &of_str))
pdata->dmic2_samplephase =
- da7218_of_dmic_samplephase(component, of_str);
+ da7218_of_dmic_samplephase(dev, of_str);
else
pdata->dmic2_samplephase = DA7218_DMIC_SAMPLE_ON_CLKEDGE;
if (of_property_read_u32(np, "dlg,dmic2-clkrate-hz", &of_val32) >= 0)
- pdata->dmic2_clk_rate = da7218_of_dmic_clkrate(component, of_val32);
+ pdata->dmic2_clk_rate = da7218_of_dmic_clkrate(dev, of_val32);
else
pdata->dmic2_clk_rate = DA7218_DMIC_CLK_3_0MHZ;
@@ -2520,7 +2520,7 @@ static struct da7218_pdata *da7218_of_to_pdata(struct snd_soc_component *compone
if (!hpldet_np)
return pdata;
- hpldet_pdata = devm_kzalloc(component->dev, sizeof(*hpldet_pdata),
+ hpldet_pdata = devm_kzalloc(dev, sizeof(*hpldet_pdata),
GFP_KERNEL);
if (!hpldet_pdata) {
of_node_put(hpldet_np);
@@ -2531,14 +2531,14 @@ static struct da7218_pdata *da7218_of_to_pdata(struct snd_soc_component *compone
if (of_property_read_u32(hpldet_np, "dlg,jack-rate-us",
&of_val32) >= 0)
hpldet_pdata->jack_rate =
- da7218_of_jack_rate(component, of_val32);
+ da7218_of_jack_rate(dev, of_val32);
else
hpldet_pdata->jack_rate = DA7218_HPLDET_JACK_RATE_40US;
if (of_property_read_u32(hpldet_np, "dlg,jack-debounce",
&of_val32) >= 0)
hpldet_pdata->jack_debounce =
- da7218_of_jack_debounce(component, of_val32);
+ da7218_of_jack_debounce(dev, of_val32);
else
hpldet_pdata->jack_debounce =
DA7218_HPLDET_JACK_DEBOUNCE_2;
@@ -2546,7 +2546,7 @@ static struct da7218_pdata *da7218_of_to_pdata(struct snd_soc_component *compone
if (of_property_read_u32(hpldet_np, "dlg,jack-threshold-pct",
&of_val32) >= 0)
hpldet_pdata->jack_thr =
- da7218_of_jack_thr(component, of_val32);
+ da7218_of_jack_thr(dev, of_val32);
else
hpldet_pdata->jack_thr = DA7218_HPLDET_JACK_THR_84PCT;
@@ -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;
@@ -2887,21 +2876,8 @@ static int da7218_probe(struct snd_soc_component *component)
if (ret)
return ret;
- /* Handle DT/Platform data */
- if (component->dev->of_node)
- da7218->pdata = da7218_of_to_pdata(component);
- else
- da7218->pdata = dev_get_platdata(component->dev);
-
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 +2941,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 +2965,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 +3238,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 +3263,28 @@ 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);
+
+ /* Handle DT/Platform data */
+ if (i2c->dev.of_node)
+ da7218->pdata = da7218_of_to_pdata(&i2c->dev, da7218);
+ else
+ da7218->pdata = dev_get_platdata(&i2c->dev);
+
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_da7218, &da7218_dai, 1);
if (ret < 0) {
--
2.50.1
next prev parent 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 ` [PATCH v2 01/21] ASoC: codecs: cpcap: Fix devm " Chancel Liu
2026-09-23 6:12 ` Chancel Liu [this message]
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-3-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®