summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Juhl <jj@chaosbits.net>2012-01-29 21:34:04 +0100
committerJohn W. Linville <linville@tuxdriver.com>2012-02-01 15:24:35 -0500
commitf9721ed2707661af75a414d09cdcd71f99a13f62 (patch)
treec77aa11e55066e784182b15f450144c37af62f3b
parent6f01fd6e6f6809061b56e78f1e8d143099716d70 (diff)
downloadlinux-f9721ed2707661af75a414d09cdcd71f99a13f62.tar.gz
linux-f9721ed2707661af75a414d09cdcd71f99a13f62.tar.bz2
linux-f9721ed2707661af75a414d09cdcd71f99a13f62.zip
bcma: Fix mem leak in bcma_bus_scan()
bcma_bus_scan() leaks 'struct bcma_device' bytes if bcma_get_next_core() returns error. Restructure the code so we always kfree() the memory we allocate to the variable 'core' before it goes out of scope. Signed-off-by: Jesper Juhl <jj@chaosbits.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/bcma/scan.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/drivers/bcma/scan.c b/drivers/bcma/scan.c
index cad994857683..3a2f672db9ad 100644
--- a/drivers/bcma/scan.c
+++ b/drivers/bcma/scan.c
@@ -399,15 +399,18 @@ int bcma_bus_scan(struct bcma_bus *bus)
core->bus = bus;
err = bcma_get_next_core(bus, &eromptr, NULL, core_num, core);
- if (err == -ENODEV) {
- core_num++;
- continue;
- } else if (err == -ENXIO)
- continue;
- else if (err == -ESPIPE)
- break;
- else if (err < 0)
+ if (err < 0) {
+ kfree(core);
+ if (err == -ENODEV) {
+ core_num++;
+ continue;
+ } else if (err == -ENXIO) {
+ continue;
+ } else if (err == -ESPIPE) {
+ break;
+ }
return err;
+ }
core->core_index = core_num++;
bus->nr_cores++;