]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mtd: spi-nor: aspeed-smc: Add of_node_put()
authorNishka Dasgupta <nishkadg.linux@gmail.com>
Thu, 8 Aug 2019 07:51:04 +0000 (13:21 +0530)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Wed, 28 Aug 2019 09:40:31 +0000 (12:40 +0300)
Each iteration of for_each_available_child_of_node puts the previous
node, but in the case of a break from the middle of the loop, there is
no put, thus causing a memory leak. Upon termination of the loop
(whether by break or a natural exit), either ret will have a non-zero
value or child will be NULL. Hence add an of_node_put() that will
execute only when ret has a non-zero value, as calling of_node_put() on
a possible NULL value does not cause any further issues.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
drivers/mtd/spi-nor/aspeed-smc.c

index 19b8757325d204e86e55485878f6ea572583fbaf..009c1da8574c917b9e96f4d6c64597e8119825bc 100644 (file)
@@ -836,8 +836,10 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller,
                controller->chips[cs] = chip;
        }
 
-       if (ret)
+       if (ret) {
+               of_node_put(child);
                aspeed_smc_unregister(controller);
+       }
 
        return ret;
 }