Skip to contentSkip to conversation

ASoC: cs35l56: Fix some cleanup memory leaks

PATCH Superseded Richard Fitzgerald 2 participants 6 messages Jun 9 – Jun 10

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Richard Fitzgerald

author maintainer
#0 lore raw

cover ASoC: cs35l56: Fix some cleanup memory leaks

These are for-next.

They are not urgent because it only leaks memory if the driver failed to component_probe or is removed, which wouldn't happen in normal use.

These two patches fix some memory leaks:
- The memory allocated by wm_adsp/cs_dsp was not freed.
- If component_probe() failed it didn't clean up.

Richard Fitzgerald (2):
ASoC: cs35l56: Fix missing calls to wm_adsp2_remove()
ASoC: cs35l56: Cleanup if component_probe fails

 sound/soc/codecs/cs35l56.c | 20 ++++++++++++++++++--
 sound/soc/codecs/wm_adsp.c |  7 +++++++
 2 files changed, 25 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/2 ASoC: cs35l56: Fix missing calls to wm_adsp2_remove()

Call wm_adsp2_remove() in cs35l56_remove() and the error path of cs35l56_common_probe().

Depends on commit 7d3fb78b5503 ("ASoC: wm_adsp: Fix NULL dereference when removing firmware controls").

The call to wm_halo_init() during driver probe should be paired with a call to wm_adsp2_remove() but this was missing. The consequence would be a memory leak of the control lists in the cs_dsp driver.

Fixes e49611252900 ("ASoC: cs35l56: Add driver for Cirrus Logic CS35L56")
---
 sound/soc/codecs/cs35l56.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
sound/soc/codecs/cs35l56.c +6 -1
index b4b126753c10..5de9cf3d0330 100644
@@ -1997,11 +1997,14 @@ int cs35l56_common_probe(struct cs35l56_private *cs35l56)
 					 cs35l56_dai, ARRAY_SIZE(cs35l56_dai));
 	if (ret < 0) {
 		dev_err_probe(cs35l56->base.dev, ret, "Register codec failed\n");
-		goto err;
+		goto err_remove_wm_adsp;
 	}
 
 	return 0;
 
+err_remove_wm_adsp:
+	wm_adsp2_remove(&cs35l56->dsp);
+
 err:
 	gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);
 	regulator_bulk_disable(ARRAY_SIZE(cs35l56->supplies), cs35l56->supplies);
@@ -2109,6 +2112,8 @@ void cs35l56_remove(struct cs35l56_private *cs35l56)
 
 	destroy_workqueue(cs35l56->dsp_wq);
 
+	wm_adsp2_remove(&cs35l56->dsp);
+
 	pm_runtime_dont_use_autosuspend(cs35l56->base.dev);
 	pm_runtime_suspend(cs35l56->base.dev);
 	pm_runtime_disable(cs35l56->base.dev);
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 2/2 ASoC: cs35l56: Cleanup if component_probe fails

In reply to Richard Fitzgerald

If cs35l56_component_probe() fails, call cs35l56_component_remove() to clean up.

All the cleanup in cs35l56_component_remove() is the same cleanup that would need to be done (at least partially) if cs35l56_component_probe() fails. So calling cs35l56_component_remove() avoids convoluted cleanup gotos and duplicated code in cs35l56_component_probe().

The only action in cs35l56_component_remove() that is nominally dependent on having completed the component_probe() action is the call to wm_adsp2_component_remove(). Though it is currently safe to call that even if wm_adsp2_component_probe() was not called. However, wm_adsp2_component_probe() has been trivially updated to check itself whether it needs to cleanup.

Fixes e49611252900 ("ASoC: cs35l56: Add driver for Cirrus Logic CS35L56")
---
 sound/soc/codecs/cs35l56.c | 13 ++++++++++++-
 sound/soc/codecs/wm_adsp.c |  7 +++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
sound/soc/codecs/cs35l56.c +12 -1
index 5de9cf3d0330..6e2d92ab98e1 100644
@@ -1359,7 +1359,7 @@ VISIBLE_IF_KUNIT int cs35l56_set_fw_name(struct snd_soc_component *component)
 }
 EXPORT_SYMBOL_IF_KUNIT(cs35l56_set_fw_name);
 
-static int cs35l56_component_probe(struct snd_soc_component *component)
+static int _cs35l56_component_probe(struct snd_soc_component *component)
 {
 	struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
 	struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(component);
@@ -1459,6 +1459,17 @@ static void cs35l56_component_remove(struct snd_soc_component *component)
 	cs35l56->component = NULL;
 }
 
+static int cs35l56_component_probe(struct snd_soc_component *component)
+{
+	int ret;
+
+	ret = _cs35l56_component_probe(component);
+	if (ret < 0)
+		cs35l56_component_remove(component);
+
+	return ret;
+}
+
 static int cs35l56_set_bias_level(struct snd_soc_component *component,
 				  enum snd_soc_bias_level level)
 {
sound/soc/codecs/wm_adsp.c +7 -0
index ca630c9948e4..baa75e7ff53b 100644
@@ -1170,7 +1170,14 @@ EXPORT_SYMBOL_GPL(wm_adsp2_component_probe);
 
 int wm_adsp2_component_remove(struct wm_adsp *dsp, struct snd_soc_component *component)
 {
+	if (!dsp)
+		return 0;
+
+	if (!dsp->component)
+		return 0;
+
 	cs_dsp_cleanup_debugfs(&dsp->cs_dsp);
+	dsp->component = NULL;
 
 	return 0;
 }
Signature · 1 line
2.47.3
author maintainer
#3 lore raw
In reply to Richard Fitzgerald
Quoted 9 lines · Richard Fitzgerald

These are for-next.

They are not urgent because it only leaks memory if the driver failed to component_probe or is removed, which wouldn't happen in normal use.

These two patches fix some memory leaks:
- The memory allocated by wm_adsp/cs_dsp was not freed.
- If component_probe() failed it didn't clean up.

Quoted 8 lines

Richard Fitzgerald (2):
ASoC: cs35l56: Fix missing calls to wm_adsp2_remove()
ASoC: cs35l56: Cleanup if component_probe fails

  sound/soc/codecs/cs35l56.c | 20 ++++++++++++++++++--
  sound/soc/codecs/wm_adsp.c |  7 +++++++
  2 files changed, 25 insertions(+), 2 deletions(-)

Sashiko doesn't like these, so ignore them and I'll look at its complaints and do a V2.

maintainer
#4 lore raw
Quoted 2 lines · Richard Fitzgerald

Sashiko doesn't like these, so ignore them and I'll look at its complaints and do a V2.

FWIW it's not gospel, and in particular if it's a preexisting issue while it's obviously good to fix them I'm not going to block something for it unless there's some really special reason.

author maintainer
#5 lore raw
Quoted 8 lines · Mark Brown
Quoted 2 lines · Richard Fitzgerald

Sashiko doesn't like these, so ignore them and I'll look at its complaints and do a V2.

FWIW it's not gospel, and in particular if it's a preexisting issue while it's obviously good to fix them I'm not going to block something for it unless there's some really special reason.

I know, and it depends which AI engine Sashiko chooses. But I like to take the time to be sure there isn't something real hiding in apparently bogus reports.