Skip to contentSkip to conversation

ASoC: Intel: avs: fix possible memory leak in probe_codec()

PATCH In review Yang Yingliang 2 participants 3 messages Oct 22, 2022 – Nov 2, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: Intel: avs: fix possible memory leak in probe_codec()

If snd_hda_codec_configure() fails, 'codec' and name allocated in dev_set_name() called in snd_hdac_device_init() are leaked. Fix this by calling snd_hdac_device_unregister() and put_device(), so they can be freed in snd_hda_codec_dev_release() and kobject_cleanup().

Fixes 1affc44ea5dd ("ASoC: Intel: avs: PCI driver implementation")
---
 sound/soc/intel/avs/core.c | 2 ++
 1 file changed, 2 insertions(+)
sound/soc/intel/avs/core.c +2 -0
index bb0719c58ca4..2fde2b3f8790 100644
@@ -140,6 +140,8 @@ static int probe_codec(struct hdac_bus *bus, int addr)
 	ret = snd_hda_codec_configure(codec);
 	if (ret < 0) {
 		dev_err(bus->dev, "failed to config codec %d\n", ret);
+		snd_hdac_device_unregister(&codec->core);
+		put_device(&codec->core.dev);
 		return ret;
 	}
 
Signature · 1 line
2.25.1
#1 lore raw

+Cc: Takashi Iwai <[email protected]>

Hi, is this patch good?

Thanks,
Yang

Quoted 24 lines · Yang Yingliang

If snd_hda_codec_configure() fails, 'codec' and name allocated in dev_set_name() called in snd_hdac_device_init() are leaked. Fix this by calling snd_hdac_device_unregister() and put_device(), so they can be freed in snd_hda_codec_dev_release() and kobject_cleanup().

Fixes 1affc44ea5dd ("ASoC: Intel: avs: PCI driver implementation")
---
  sound/soc/intel/avs/core.c | 2 ++
  1 file changed, 2 insertions(+)
sound/soc/intel/avs/core.c +2 -0
index bb0719c58ca4..2fde2b3f8790 100644
@@ -140,6 +140,8 @@ static int probe_codec(struct hdac_bus *bus, int addr)
  	ret = snd_hda_codec_configure(codec);
  	if (ret < 0) {
  		dev_err(bus->dev, "failed to config codec %d\n", ret);
+		snd_hdac_device_unregister(&codec->core);
+		put_device(&codec->core.dev);
  		return ret;
  	}
 
#2 lore raw
Quoted 4 lines · Yang Yingliang

+Cc: Takashi Iwai <[email protected]>

Hi, is this patch good?

Not really. The codec instances are freed later at avs_pci_remove().

Takashi

Quoted 29 lines

Thanks,
Yang

Quoted 24 lines · Yang Yingliang

If snd_hda_codec_configure() fails, 'codec' and name allocated in dev_set_name() called in snd_hdac_device_init() are leaked. Fix this by calling snd_hdac_device_unregister() and put_device(), so they can be freed in snd_hda_codec_dev_release() and kobject_cleanup().

Fixes 1affc44ea5dd ("ASoC: Intel: avs: PCI driver implementation")
---
  sound/soc/intel/avs/core.c | 2 ++
  1 file changed, 2 insertions(+)
sound/soc/intel/avs/core.c +2 -0
index bb0719c58ca4..2fde2b3f8790 100644
@@ -140,6 +140,8 @@ static int probe_codec(struct hdac_bus *bus, int addr)
  	ret = snd_hda_codec_configure(codec);
  	if (ret < 0) {
  		dev_err(bus->dev, "failed to config codec %d\n", ret);
+		snd_hdac_device_unregister(&codec->core);
+		put_device(&codec->core.dev);
  		return ret;
  	}