All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roel Kluin <12o3l@tiscali.nl>
To: alsa-devel@alsa-project.org
Subject: [PATCH] Free after memory allocation failure in emu10k1
Date: Wed, 31 Oct 2007 02:19:36 +0100	[thread overview]
Message-ID: <4727D828.4010701@tiscali.nl> (raw)

I can confirm that it builds.
--
Free after memory allocation failure

Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 97c41d7..88f8fb3 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -1894,25 +1894,31 @@ static unsigned char saved_regs_audigy[] = {
 static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
 {
 	int size;
 
 	size = ARRAY_SIZE(saved_regs);
 	if (emu->audigy)
 		size += ARRAY_SIZE(saved_regs_audigy);
 	emu->saved_ptr = vmalloc(4 * NUM_G * size);
 	if (! emu->saved_ptr)
 		return -ENOMEM;
-	if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
+
+	if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0) {
+		vfree(emu->saved_ptr);
 		return -ENOMEM;
+	}
+
 	if (emu->card_capabilities->ca0151_chip &&
-	    snd_p16v_alloc_pm_buffer(emu) < 0)
+	    snd_p16v_alloc_pm_buffer(emu) < 0) {
+		vfree(emu->saved_ptr);
 		return -ENOMEM;
+	}
 	return 0;
 }
 
 static void free_pm_buffer(struct snd_emu10k1 *emu)
 {
 	vfree(emu->saved_ptr);
 	snd_emu10k1_efx_free_pm_buffer(emu);
 	if (emu->card_capabilities->ca0151_chip)
 		snd_p16v_free_pm_buffer(emu);
 }
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 9bf1cd5..a31ad02 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -2634,30 +2634,43 @@ int __devinit snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device, struct
 
 #ifdef CONFIG_PM
 int __devinit snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
 {
 	int len;
 
 	len = emu->audigy ? 0x200 : 0x100;
 	emu->saved_gpr = kmalloc(len * 4, GFP_KERNEL);
 	if (! emu->saved_gpr)
 		return -ENOMEM;
+
 	len = emu->audigy ? 0x100 : 0xa0;
 	emu->tram_val_saved = kmalloc(len * 4, GFP_KERNEL);
+	if (! emu->tram_val_saved)
+		goto free_gpr;
+
 	emu->tram_addr_saved = kmalloc(len * 4, GFP_KERNEL);
-	if (! emu->tram_val_saved || ! emu->tram_addr_saved)
-		return -ENOMEM;
+	if (! emu->tram_addr_saved)
+		goto free_tram_val;
+
 	len = emu->audigy ? 2 * 1024 : 2 * 512;
 	emu->saved_icode = vmalloc(len * 4);
 	if (! emu->saved_icode)
-		return -ENOMEM;
+		goto free_tram_addr;
+
 	return 0;
+free_gpr:
+	kfree(emu->saved_gpr);
+free_tram_val:
+	kfree(emu->tram_val_saved);
+free_tram_addr:
+	kfree(emu->tram_addr_saved);
+        return -ENOMEM;
 }
 
 void snd_emu10k1_efx_free_pm_buffer(struct snd_emu10k1 *emu)
 {
 	kfree(emu->saved_gpr);
 	kfree(emu->tram_val_saved);
 	kfree(emu->tram_addr_saved);
 	vfree(emu->saved_icode);
 }

             reply	other threads:[~2007-10-31  1:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-31  1:19 Roel Kluin [this message]
2007-10-31  8:13 ` [PATCH] Free after memory allocation failure in emu10k1 Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4727D828.4010701@tiscali.nl \
    --to=12o3l@tiscali.nl \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.