Skip to content

Commit

Permalink
mtd: spi-nor: aspeed-smc: Add of_node_put()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nishka Dasgupta authored and Tudor Ambarus committed Aug 28, 2019
1 parent 620df24 commit 6597f0b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/mtd/spi-nor/aspeed-smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6597f0b

Please sign in to comment.