[PATCH] vga: Fix mem leaks in vga_arb_write()

From: Jesper Juhl
Date: Sun Jul 17 2011 - 14:41:00 EST


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@xxxxxxxxxxxxx>
---
drivers/gpu/vga/vgaarb.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)

compile tested.

diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 8a1021f..7f41a8d 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@xxxxxxxxxxxxx> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/