Skip to content

Commit

Permalink
leds: netxbig: Add of_node_put() in netxbig_leds_get_of_pdata()
Browse files Browse the repository at this point in the history
The variable gpio_ext_np in the function netxbig_leds_get_of_pdata takes
the value returned by of_parse_phandle; hence, it must be put in order
to prevent a memory leak. Add an of_node_put for gpio_ext_np before a
return statement, and move a pre-existing of_node_put statement to right
after the last usage of this variable.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <[email protected]>
Acked-by: Pavel Machek <[email protected]>
Signed-off-by: Jacek Anaszewski <[email protected]>
  • Loading branch information
gaurijhangiani authored and jacek-anaszewski committed Jul 29, 2019
1 parent 156189a commit af7b650
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/leds/leds-netxbig.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,14 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
}

gpio_ext = devm_kzalloc(dev, sizeof(*gpio_ext), GFP_KERNEL);
if (!gpio_ext)
if (!gpio_ext) {
of_node_put(gpio_ext_np);
return -ENOMEM;
}
ret = gpio_ext_get_of_pdata(dev, gpio_ext_np, gpio_ext);
of_node_put(gpio_ext_np);
if (ret)
return ret;
of_node_put(gpio_ext_np);
pdata->gpio_ext = gpio_ext;

/* Timers (optional) */
Expand Down

0 comments on commit af7b650

Please sign in to comment.