]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: cs35l56: Cleanup if component_probe fails
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Wed, 10 Jun 2026 09:34:32 +0000 (10:34 +0100)
committerMark Brown <broonie@kernel.org>
Wed, 10 Jun 2026 10:24:45 +0000 (11:24 +0100)
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")
Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260610093432.557375-4-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/cs35l56.c
sound/soc/codecs/wm_adsp.c

index 3ab5395f15bb250abcdb6665d4a5d460c5abe003..3641ac1378c7c28fea3b619399f5cc1a423cba36 100644 (file)
@@ -1326,7 +1326,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);
@@ -1426,6 +1426,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)
 {
index ca630c9948e49a3d08e4204a68058a8c7e716931..baa75e7ff53ba9e81945368a90cf21864213e715 100644 (file)
@@ -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;
 }