pinctrl: cirrus: Fix fwnode leak in cs42l43_pin_probe()
Subsystems (5)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 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.
---
Changes in v2:
- Use devm_add_action_or_reset() instead of manual put in success path to properly manage fwnode lifetime throughout device lifecycle (suggested by Charles Keepax)
--- drivers/pinctrl/cirrus/pinctrl-cs42l43.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/pinctrl/cirrus/pinctrl-cs42l43.c +19 -4
@@ -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;
Signature · 1 line
2.50.1.windows.1
…
Quoted 1 line
+++
b/drivers/pinctrl/cirrus/pinctrl-cs42l43.c
…
Quoted 4 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c +0
-0@@ -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)) {
…
drivers/pinctrl/cirrus/pinctrl-cs42l43.c static int cs42l43_pin_probe(struct platform_device *pdev) · line 580
Quoted 8 lines
drivers/pinctrl/cirrus/pinctrl-cs42l43.c +8
-0+ 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; + }
…
I doubt that such a function call is needed in this if branch.
https://elixir.bootlin.com/linux/v6.18-rc3/source/include/linux/device/devres.h#L152-L168
Regards,
Markus
Quoted 9 lines · Haotian Zhang
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 <[email protected]>Signed-off-by Haotian Zhang <[email protected]>
Patch applied.
Yours,
Linus Walleij