Skip to contentSkip to conversation

pinctrl: meson: amlogic-a4: Fix device node reference leak in aml_dt_node_to_map_pinmux()

PATCH In review Felix Gu 2 participants 2 messages Feb 18 – Feb 24

Subsystems (4)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 pinctrl: meson: amlogic-a4: Fix device node reference leak in aml_dt_node_to_map_pinmux()

The of_get_parent() function returns a device_node with an incremented reference count.

Use the __free(device_node) cleanup attribute to ensure of_node_put() is automatically called when pnode goes out of scope, fixing a reference leak.

Fixes 6e9be3abb78c ("pinctrl: Add driver support for Amlogic SoCs")
---
 drivers/pinctrl/meson/pinctrl-amlogic-a4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pinctrl/meson/pinctrl-amlogic-a4.c +1 -2
index dfa32b11555c..e2293a872dcb 100644
@@ -679,7 +679,6 @@ static int aml_dt_node_to_map_pinmux(struct pinctrl_dev *pctldev,
 				     unsigned int *num_maps)
 {
 	struct device *dev = pctldev->dev;
-	struct device_node *pnode;
 	unsigned long *configs = NULL;
 	unsigned int num_configs = 0;
 	struct property *prop;
@@ -693,7 +692,7 @@ static int aml_dt_node_to_map_pinmux(struct pinctrl_dev *pctldev,
 		return -ENOENT;
 	}
 
-	pnode = of_get_parent(np);
+	struct device_node *pnode __free(device_node) = of_get_parent(np);
 	if (!pnode) {
 		dev_info(dev, "Missing function node\n");
 		return -EINVAL;

---
base-commit: fe9e3edb6a215515d1148d32a5c445c5bdd7916f
change-id: 20260218-a4-3782d6b094c5

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
maintainer
#1 lore raw
Quoted 9 lines · Felix Gu

The of_get_parent() function returns a device_node with an incremented reference count.

Use the __free(device_node) cleanup attribute to ensure of_node_put() is automatically called when pnode goes out of scope, fixing a reference leak.

Fixes 6e9be3abb78c ("pinctrl: Add driver support for Amlogic SoCs")

Patch applied!

Yours,
Linus Walleij