bcma: Fix mem leak in bcma_bus_scan()
authorJesper Juhl <jj@chaosbits.net>
Sun, 29 Jan 2012 20:34:04 +0000 (21:34 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 1 Feb 2012 20:24:35 +0000 (15:24 -0500)
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>
drivers/bcma/scan.c

index cad9948576837a53373791179b388d59276c7596..3a2f672db9ad217c264cf7a2203e4d96aa0910d7 100644 (file)
@@ -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++;