Skip to contentSkip to conversation

ALSA: lx6464es: Fix memory leaks in snd_lx6464es_create

PATCH In review Navid Emamdoost 3 participants 3 messages Oct 27, 2019 – Oct 28, 2019

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

PATCH 1/1 ALSA: lx6464es: Fix memory leaks in snd_lx6464es_create

In the implementation of snd_lx6464es_create() it there are memory leaks when error happens. Go to error path if any of these calls fail:
lx_init_dsp(), lx_pcm_create(), lx_proc_create(), snd_ctl_add().

Fixes 02bec4904508 ("ALSA: lx6464es - driver for the digigram lx6464es interface")
---
 sound/pci/lx6464es/lx6464es.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
sound/pci/lx6464es/lx6464es.c +5 -4
index fe10714380f2..7c6e8f4ef826 100644
@@ -1020,25 +1020,26 @@ static int snd_lx6464es_create(struct snd_card *card,
 	err = lx_init_dsp(chip);
 	if (err < 0) {
 		dev_err(card->dev, "error during DSP initialization\n");
-		return err;
+		goto cleanup;
 	}
 
 	err = lx_pcm_create(chip);
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	err = lx_proc_create(card, chip);
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch,
 					     chip));
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	*rchip = chip;
 	return 0;
 
+cleanup:
 device_new_failed:
 	free_irq(pci->irq, chip);
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines

In the implementation of snd_lx6464es_create() it there are memory leaks when error happens. Go to error path if any of these calls fail:

Please improve the wording for such a change description.

Regards,
Markus

#2 lore raw
In reply to Navid Emamdoost
Quoted 4 lines · Navid Emamdoost

In the implementation of snd_lx6464es_create() it there are memory leaks when error happens. Go to error path if any of these calls fail:
lx_init_dsp(), lx_pcm_create(), lx_proc_create(), snd_ctl_add().

Again no for this patch, it'll lead to double-frees.
After registered via snd_device_new(), the device object gets released by its callback and the single snd_card_free() call suffices.

thanks,

Takashi

Quoted 45 lines
Fixes 02bec4904508 ("ALSA: lx6464es - driver for the digigram lx6464es interface")
---
 sound/pci/lx6464es/lx6464es.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
sound/pci/lx6464es/lx6464es.c +5 -4
index fe10714380f2..7c6e8f4ef826 100644
@@ -1020,25 +1020,26 @@ static int snd_lx6464es_create(struct snd_card *card,
 	err = lx_init_dsp(chip);
 	if (err < 0) {
 		dev_err(card->dev, "error during DSP initialization\n");
-		return err;
+		goto cleanup;
 	}
 
 	err = lx_pcm_create(chip);
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	err = lx_proc_create(card, chip);
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch,
 					     chip));
 	if (err < 0)
-		return err;
+		goto cleanup;
 
 	*rchip = chip;
 	return 0;
 
+cleanup:
 device_new_failed:
 	free_irq(pci->irq, chip);
 
Signature · 1 line
2.17.1