All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][Resend] vga: Fix mem leaks in vga_arb_write()
@ 2011-08-01 22:07 Jesper Juhl
  0 siblings, 0 replies; only message in thread
From: Jesper Juhl @ 2011-08-01 22:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tiago Vignatti, Paulo R. Zanoni, Benjamin Herrenschmidt,
	Dave Airlie, Lucas De Marchi, Chris Wilson, Alex Deucher,
	Daniel J Blueman

We don't always free the memory allocated to 'kbuf' - make sure we do
so.
Also, while I was there anyway, remove a unneeded kfree call and
instead just set ret_val and fall through to the 'done' label.
I also made a small trivial change to a comment and a small whitespace
correction in an assignment.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/gpu/vga/vgaarb.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index c72f1c0..63c7d49 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -993,14 +993,15 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
 				uc = &priv->cards[i];
 		}
 
+		ret_val = -EINVAL;
 		if (!uc)
-			return -EINVAL;
+			goto done;
 
 		if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
-			return -EINVAL;
+			goto done;
 
 		if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
-			return -EINVAL;
+			goto done;
 
 		vga_put(pdev, io_state);
 
@@ -1115,7 +1116,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
 				MAX_USER_CARDS);
 			pci_dev_put(pdev);
 			/* XXX: which value to return? */
-			ret_val =  -ENOMEM;
+			ret_val = -ENOMEM;
 			goto done;
 		}
 
@@ -1143,10 +1144,8 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
 		ret_val = count;
 		goto done;
 	}
-	/* If we got here, the message written is not part of the protocol! */
-	kfree(kbuf);
-	return -EPROTO;
-
+	/* If we get here, the message written is not part of the protocol! */
+	ret_val = -EPROTO;
 done:
 	kfree(kbuf);
 	return ret_val;
-- 
1.7.6


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-01 22:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-01 22:07 [PATCH][Resend] vga: Fix mem leaks in vga_arb_write() Jesper Juhl

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.