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>
This commit is contained in:
Jesper Juhl 2012-01-29 21:34:04 +01:00 committed by John W. Linville
parent 6f01fd6e6f
commit f9721ed270
1 changed files with 11 additions and 8 deletions

View File

@ -399,15 +399,18 @@ int bcma_bus_scan(struct bcma_bus *bus)
core->bus = bus; core->bus = bus;
err = bcma_get_next_core(bus, &eromptr, NULL, core_num, core); err = bcma_get_next_core(bus, &eromptr, NULL, core_num, core);
if (err == -ENODEV) { if (err < 0) {
core_num++; kfree(core);
continue; if (err == -ENODEV) {
} else if (err == -ENXIO) core_num++;
continue; continue;
else if (err == -ESPIPE) } else if (err == -ENXIO) {
break; continue;
else if (err < 0) } else if (err == -ESPIPE) {
break;
}
return err; return err;
}
core->core_index = core_num++; core->core_index = core_num++;
bus->nr_cores++; bus->nr_cores++;