Skip to content

Commit 9b07cdf

Browse files
ISCAS-VulabLinus Walleij
authored andcommitted
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: d5282a5 ("pinctrl: cs42l43: Add support for the cs42l43") Suggested-by: Charles Keepax <[email protected]> Signed-off-by: Haotian Zhang <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 316e361 commit 9b07cdf

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

drivers/pinctrl/cirrus/pinctrl-cs42l43.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,11 @@ static int cs42l43_gpio_add_pin_ranges(struct gpio_chip *chip)
532532
return ret;
533533
}
534534

535+
static void cs42l43_fwnode_put(void *data)
536+
{
537+
fwnode_handle_put(data);
538+
}
539+
535540
static int cs42l43_pin_probe(struct platform_device *pdev)
536541
{
537542
struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
@@ -563,10 +568,20 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
563568
priv->gpio_chip.ngpio = CS42L43_NUM_GPIOS;
564569

565570
if (is_of_node(fwnode)) {
566-
fwnode = fwnode_get_named_child_node(fwnode, "pinctrl");
567-
568-
if (fwnode && !fwnode->dev)
569-
fwnode->dev = priv->dev;
571+
struct fwnode_handle *child;
572+
573+
child = fwnode_get_named_child_node(fwnode, "pinctrl");
574+
if (child) {
575+
ret = devm_add_action_or_reset(&pdev->dev,
576+
cs42l43_fwnode_put, child);
577+
if (ret) {
578+
fwnode_handle_put(child);
579+
return ret;
580+
}
581+
if (!child->dev)
582+
child->dev = priv->dev;
583+
fwnode = child;
584+
}
570585
}
571586

572587
priv->gpio_chip.fwnode = fwnode;

0 commit comments

Comments
 (0)