Commit d344873c authored by Richard Fitzgerald's avatar Richard Fitzgerald Committed by Takashi Iwai

ALSA: hda: cs35l56: Fix lifetime of cs_dsp instance

The cs_dsp instance is initialized in the driver probe() so it
should be freed in the driver remove(). Also fix a missing call
to cs_dsp_remove() in the error path of cs35l56_hda_common_probe().

The call to cs_dsp_remove() was being done in the component unbind
callback cs35l56_hda_unbind(). This meant that if the driver was
unbound and then re-bound it would be using an uninitialized cs_dsp
instance.

It is best to initialize the cs_dsp instance in probe() so that it
can return an error if it fails. The component binding API doesn't
have any error handling so there's no way to handle a failure if
cs_dsp was initialized in the bind.
Signed-off-by: default avatarRichard Fitzgerald <rf@opensource.cirrus.com>
Fixes: 73cfbfa9 ("ALSA: hda/cs35l56: Add driver for Cirrus Logic CS35L56 amplifier")
Link: https://lore.kernel.org/r/20240508100811.49514-1-rf@opensource.cirrus.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ec6f32bc
...@@ -732,8 +732,6 @@ static void cs35l56_hda_unbind(struct device *dev, struct device *master, void * ...@@ -732,8 +732,6 @@ static void cs35l56_hda_unbind(struct device *dev, struct device *master, void *
if (cs35l56->base.fw_patched) if (cs35l56->base.fw_patched)
cs_dsp_power_down(&cs35l56->cs_dsp); cs_dsp_power_down(&cs35l56->cs_dsp);
cs_dsp_remove(&cs35l56->cs_dsp);
if (comps[cs35l56->index].dev == dev) if (comps[cs35l56->index].dev == dev)
memset(&comps[cs35l56->index], 0, sizeof(*comps)); memset(&comps[cs35l56->index], 0, sizeof(*comps));
...@@ -1035,7 +1033,7 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int hid, int id) ...@@ -1035,7 +1033,7 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int hid, int id)
ARRAY_SIZE(cs35l56_hda_dai_config)); ARRAY_SIZE(cs35l56_hda_dai_config));
ret = cs35l56_force_sync_asp1_registers_from_cache(&cs35l56->base); ret = cs35l56_force_sync_asp1_registers_from_cache(&cs35l56->base);
if (ret) if (ret)
goto err; goto dsp_err;
/* /*
* By default only enable one ASP1TXn, where n=amplifier index, * By default only enable one ASP1TXn, where n=amplifier index,
...@@ -1061,6 +1059,8 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int hid, int id) ...@@ -1061,6 +1059,8 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int hid, int id)
pm_err: pm_err:
pm_runtime_disable(cs35l56->base.dev); pm_runtime_disable(cs35l56->base.dev);
dsp_err:
cs_dsp_remove(&cs35l56->cs_dsp);
err: err:
gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0); gpiod_set_value_cansleep(cs35l56->base.reset_gpio, 0);
...@@ -1078,6 +1078,8 @@ void cs35l56_hda_remove(struct device *dev) ...@@ -1078,6 +1078,8 @@ void cs35l56_hda_remove(struct device *dev)
component_del(cs35l56->base.dev, &cs35l56_hda_comp_ops); component_del(cs35l56->base.dev, &cs35l56_hda_comp_ops);
cs_dsp_remove(&cs35l56->cs_dsp);
kfree(cs35l56->system_name); kfree(cs35l56->system_name);
pm_runtime_put_noidle(cs35l56->base.dev); pm_runtime_put_noidle(cs35l56->base.dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment