Skip to content

Commit

Permalink
of: unittest: Add of_node_put() before return
Browse files Browse the repository at this point in the history
The local variable np in function of_unittest_platform_populate takes
the return value of of_find_node_by_path, which gets a node but does not
put it. If np is not put before return it may cause a memory leak. Hence
put np before a return statement.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
  • Loading branch information
Nishka Dasgupta authored and Rob Herring committed Aug 27, 2019
1 parent 476646e commit a7bcae5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/of/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,10 @@ static void __init of_unittest_platform_populate(void)
test_bus = platform_device_register_full(&test_bus_info);
rc = PTR_ERR_OR_ZERO(test_bus);
unittest(!rc, "testbus registration failed; rc=%i\n", rc);
if (rc)
if (rc) {
of_node_put(np);
return;
}
test_bus->dev.of_node = np;

/*
Expand Down

0 comments on commit a7bcae5

Please sign in to comment.