]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pinctrl: cirrus: Fix fwnode leak in cs42l43_pin_probe()
authorHaotian Zhang <vulab@iscas.ac.cn>
Tue, 28 Oct 2025 03:05:09 +0000 (11:05 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Sun, 9 Nov 2025 23:01:22 +0000 (00:01 +0100)
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>
drivers/pinctrl/cirrus/pinctrl-cs42l43.c

index 68abb6d6cecd8c5453ceb3461b37294b470cbaa7..a8f82104a3842e3adda929b4c09cf20743a4ead4 100644 (file)
@@ -532,6 +532,11 @@ static int cs42l43_gpio_add_pin_ranges(struct gpio_chip *chip)
        return ret;
 }
 
+static void cs42l43_fwnode_put(void *data)
+{
+       fwnode_handle_put(data);
+}
+
 static int cs42l43_pin_probe(struct platform_device *pdev)
 {
        struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
@@ -563,10 +568,20 @@ static int cs42l43_pin_probe(struct platform_device *pdev)
        priv->gpio_chip.ngpio = CS42L43_NUM_GPIOS;
 
        if (is_of_node(fwnode)) {
-               fwnode = fwnode_get_named_child_node(fwnode, "pinctrl");
-
-               if (fwnode && !fwnode->dev)
-                       fwnode->dev = priv->dev;
+               struct fwnode_handle *child;
+
+               child = fwnode_get_named_child_node(fwnode, "pinctrl");
+               if (child) {
+                       ret = devm_add_action_or_reset(&pdev->dev,
+                               cs42l43_fwnode_put, child);
+                       if (ret) {
+                               fwnode_handle_put(child);
+                               return ret;
+                       }
+                       if (!child->dev)
+                               child->dev = priv->dev;
+                       fwnode = child;
+               }
        }
 
        priv->gpio_chip.fwnode = fwnode;