Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: st: Add of_node_put() before return

Each iteration of for_each_child_of_node puts the previous node, but in
the case of a return from the middle of the loop, there is no put, thus
causing a memory leak. Hence add an of_node_put before the return in
three places.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Link: https://lore.kernel.org/r/20190815060609.3056-1-nishkadg.linux@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Nishka Dasgupta and committed by
Linus Walleij
19d17d93 954fc5d2

+7 -2
+7 -2
drivers/pinctrl/pinctrl-st.c
··· 1263 1263 grp = &info->groups[*grp_index]; 1264 1264 *grp_index += 1; 1265 1265 ret = st_pctl_dt_parse_groups(child, grp, info, i++); 1266 - if (ret) 1266 + if (ret) { 1267 + of_node_put(child); 1267 1268 return ret; 1269 + } 1268 1270 } 1269 1271 dev_info(info->dev, "Function[%d\t name:%s,\tgroups:%d]\n", 1270 1272 index, func->name, func->ngroups); ··· 1626 1624 if (of_property_read_bool(child, "gpio-controller")) { 1627 1625 const char *bank_name = NULL; 1628 1626 ret = st_gpiolib_register_bank(info, bank, child); 1629 - if (ret) 1627 + if (ret) { 1628 + of_node_put(child); 1630 1629 return ret; 1630 + } 1631 1631 1632 1632 k = info->banks[bank].range.pin_base; 1633 1633 bank_name = info->banks[bank].range.name; ··· 1646 1642 i++, &grp_index); 1647 1643 if (ret) { 1648 1644 dev_err(&pdev->dev, "No functions found.\n"); 1645 + of_node_put(child); 1649 1646 return ret; 1650 1647 } 1651 1648 }