summaryrefslogtreecommitdiffstats
path: root/drivers/staging/altera-stapl/altera.c
diff options
context:
space:
mode:
authorPeter Huewe <peterhuewe@gmx.de>2011-05-31 01:11:17 +0200
committerGreg Kroah-Hartman <gregkh@suse.de>2011-06-28 13:26:23 -0700
commitc0777d228892f6a6f87f3439a030d52406f8d637 (patch)
treef37ddef27285b4680c30d954fe34f6ece5c1d2a9 /drivers/staging/altera-stapl/altera.c
parent8ded351ad1889e5351f29b3b1b1716c4992856ee (diff)
downloadop-kernel-dev-c0777d228892f6a6f87f3439a030d52406f8d637.zip
op-kernel-dev-c0777d228892f6a6f87f3439a030d52406f8d637.tar.gz
staging: altera-stapl: Fix memory leak of altera_init()
In case kzalloc() fails the second or third time we should free the previous allocated resources. In order to keep one return point and to keep the cleanup code to one place, some reordering was necessary. Also while at it, removed the *sizeof(char) - to quote Linus: "" Also removed the silly "* sizeof(u8)". If that isn't 1, we have way deeper problems than a simple multiplication can fix. """ Reported-by: Andre Bartke <andre.bartke@gmail.com> Signed-off-by: Peter Huewe <peterhuewe@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/altera-stapl/altera.c')
-rw-r--r--drivers/staging/altera-stapl/altera.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/drivers/staging/altera-stapl/altera.c b/drivers/staging/altera-stapl/altera.c
index 9cd5e76..8d73a86 100644
--- a/drivers/staging/altera-stapl/altera.c
+++ b/drivers/staging/altera-stapl/altera.c
@@ -2430,16 +2430,23 @@ int altera_init(struct altera_config *config, const struct firmware *fw)
int index = 0;
s32 offset = 0L;
s32 error_address = 0L;
+ int retval = 0;
- key = kzalloc(33 * sizeof(char), GFP_KERNEL);
- if (!key)
- return -ENOMEM;
- value = kzalloc(257 * sizeof(char), GFP_KERNEL);
- if (!value)
- return -ENOMEM;
+ key = kzalloc(33, GFP_KERNEL);
+ if (!key) {
+ retval = -ENOMEM;
+ goto out;
+ }
+ value = kzalloc(257, GFP_KERNEL);
+ if (!value) {
+ retval = -ENOMEM;
+ goto free_key;
+ }
astate = kzalloc(sizeof(struct altera_state), GFP_KERNEL);
- if (!astate)
- return -ENOMEM;
+ if (!astate) {
+ retval = -ENOMEM;
+ goto free_value;
+ }
astate->config = config;
if (!astate->config->jtag_io) {
@@ -2518,10 +2525,12 @@ int altera_init(struct altera_config *config, const struct firmware *fw)
} else if (exec_result)
printk(KERN_ERR "%s: error %d\n", __func__, exec_result);
- kfree(key);
- kfree(value);
kfree(astate);
-
- return 0;
+free_value:
+ kfree(value);
+free_key:
+ kfree(key);
+out:
+ return retval;
}
EXPORT_SYMBOL(altera_init);
OpenPOWER on IntegriCloud