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

pinctrl: freescale: mxs: 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/20190804160420.5309-1-nishkadg.linux@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Nishka Dasgupta and committed by
Linus Walleij
646d90c3 f4524447

+9 -3
+9 -3
drivers/pinctrl/freescale/pinctrl-mxs.c
··· 488 488 if (of_property_read_u32(child, "reg", &val)) { 489 489 ret = mxs_pinctrl_parse_group(pdev, child, 490 490 idxg++, NULL); 491 - if (ret) 491 + if (ret) { 492 + of_node_put(child); 492 493 return ret; 494 + } 493 495 continue; 494 496 } 495 497 ··· 501 499 f->ngroups, 502 500 sizeof(*f->groups), 503 501 GFP_KERNEL); 504 - if (!f->groups) 502 + if (!f->groups) { 503 + of_node_put(child); 505 504 return -ENOMEM; 505 + } 506 506 fn = child->name; 507 507 i = 0; 508 508 } 509 509 ret = mxs_pinctrl_parse_group(pdev, child, idxg++, 510 510 &f->groups[i++]); 511 - if (ret) 511 + if (ret) { 512 + of_node_put(child); 512 513 return ret; 514 + } 513 515 } 514 516 515 517 return 0;