Skip to content

Commit bf4b87b

Browse files
gaurijhangianiLinus Walleij
authored andcommitted
pinctrl: freescale: imx: Add of_node_put() before return
Each iteration of for_each_child_of_node() puts the previous node; however, in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence put of_node_put() statements as required before two mid-loop return statements. Issue found with Coccinelle. Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com> Link: https://lore.kernel.org/r/20190808074720.15754-1-nishkadg.linux@gmail.com Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 5a6bc29 commit bf4b87b

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎drivers/pinctrl/freescale/pinctrl-imx.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,10 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
672672

673673
grp = devm_kzalloc(ipctl->dev, sizeof(struct group_desc),
674674
GFP_KERNEL);
675-
if (!grp)
675+
if (!grp) {
676+
of_node_put(child);
676677
return -ENOMEM;
678+
}
677679

678680
mutex_lock(&ipctl->mutex);
679681
radix_tree_insert(&pctl->pin_group_tree,
@@ -697,12 +699,17 @@ static bool imx_pinctrl_dt_is_flat_functions(struct device_node *np)
697699
struct device_node *pinctrl_np;
698700

699701
for_each_child_of_node(np, function_np) {
700-
if (of_property_read_bool(function_np, "fsl,pins"))
702+
if (of_property_read_bool(function_np, "fsl,pins")) {
703+
of_node_put(function_np);
701704
return true;
705+
}
702706

703707
for_each_child_of_node(function_np, pinctrl_np) {
704-
if (of_property_read_bool(pinctrl_np, "fsl,pins"))
708+
if (of_property_read_bool(pinctrl_np, "fsl,pins")) {
709+
of_node_put(pinctrl_np);
710+
of_node_put(function_np);
705711
return false;
712+
}
706713
}
707714
}
708715

0 commit comments

Comments
 (0)