Skip to content

Commit

Permalink
bcma: Fix mem leak in bcma_bus_scan()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jesper Juhl authored and John W. Linville committed Feb 1, 2012
1 parent 6f01fd6 commit f9721ed
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions drivers/bcma/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit f9721ed

Please sign in to comment.