[PATCH] bcma: Fix mem leak in bcma_bus_scan()

From: Jesper Juhl
Date: Sun Jan 29 2012 - 15:33:50 EST


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@xxxxxxxxxxxxx>
---
drivers/bcma/scan.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)

Note: Patch is compile tested only.

diff --git a/drivers/bcma/scan.c b/drivers/bcma/scan.c
index cad9948..3a2f672 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++;
--
1.7.8.4


--
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/