From: Jesper Juhl Date: Sun, 29 Jan 2012 20:34:04 +0000 (+0100) Subject: bcma: Fix mem leak in bcma_bus_scan() X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=f9721ed2707661af75a414d09cdcd71f99a13f62;p=linux-beck.git 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 Signed-off-by: John W. Linville --- 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++;