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

pinctrl: cirrus: Fix fwnode leak in cs42l43_pin_probe()

The driver calls fwnode_get_named_child_node() which takes a reference
on the child node, but never releases it, which causes a reference leak.

Fix by using devm_add_action_or_reset() to automatically release the
reference when the device is removed.

Fixes: d5282a539297 ("pinctrl: cs42l43: Add support for the cs42l43")
Suggested-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Haotian Zhang and committed by
Linus Walleij
9b07cdf8 316e361b

+18 -3
+18 -3
drivers/pinctrl/cirrus/pinctrl-cs42l43.c
··· 532 532 return ret; 533 533 } 534 534 535 + static void cs42l43_fwnode_put(void *data) 536 + { 537 + fwnode_handle_put(data); 538 + } 539 + 535 540 static int cs42l43_pin_probe(struct platform_device *pdev) 536 541 { 537 542 struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent); ··· 568 563 priv->gpio_chip.ngpio = CS42L43_NUM_GPIOS; 569 564 570 565 if (is_of_node(fwnode)) { 571 - fwnode = fwnode_get_named_child_node(fwnode, "pinctrl"); 566 + struct fwnode_handle *child; 572 567 573 - if (fwnode && !fwnode->dev) 574 - fwnode->dev = priv->dev; 568 + child = fwnode_get_named_child_node(fwnode, "pinctrl"); 569 + if (child) { 570 + ret = devm_add_action_or_reset(&pdev->dev, 571 + cs42l43_fwnode_put, child); 572 + if (ret) { 573 + fwnode_handle_put(child); 574 + return ret; 575 + } 576 + if (!child->dev) 577 + child->dev = priv->dev; 578 + fwnode = child; 579 + } 575 580 } 576 581 577 582 priv->gpio_chip.fwnode = fwnode;