Skip to content

Commit f9721ed

Browse files
jjuhllinvjw
authored andcommitted
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>
1 parent 6f01fd6 commit f9721ed

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎drivers/bcma/scan.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,18 @@ int bcma_bus_scan(struct bcma_bus *bus)
399399
core->bus = bus;
400400

401401
err = bcma_get_next_core(bus, &eromptr, NULL, core_num, core);
402-
if (err == -ENODEV) {
403-
core_num++;
404-
continue;
405-
} else if (err == -ENXIO)
406-
continue;
407-
else if (err == -ESPIPE)
408-
break;
409-
else if (err < 0)
402+
if (err < 0) {
403+
kfree(core);
404+
if (err == -ENODEV) {
405+
core_num++;
406+
continue;
407+
} else if (err == -ENXIO) {
408+
continue;
409+
} else if (err == -ESPIPE) {
410+
break;
411+
}
410412
return err;
413+
}
411414

412415
core->core_index = core_num++;
413416
bus->nr_cores++;

0 commit comments

Comments
 (0)