Skip to contentSkip to conversation

i2c: sun6i-p2wi: Fix device node reference leak in p2wi_probe

PATCH Applied Uday Khare 2 participants 2 messages Jun 18

Subsystems (2)
lore
Share & tools
lore

Uday Khare

author
#0 lore raw

PATCH 2/4 i2c: sun6i-p2wi: Fix device node reference leak in p2wi_probe

In p2wi_probe(), the device node reference obtained via of_get_next_available_child() is stored in childnp. This reference is never released via of_node_put() - neither on the error path when of_property_read_u32() fails to read the 'reg' property, nor on the success path after the target address has been read.

Fix this by calling of_node_put(childnp) on both the error and success paths.

Fixes 3e833490fae5 ("i2c: sunxi: add P2WI (Push/Pull 2 Wire Interface) controller support")
---
 drivers/i2c/busses/i2c-sun6i-p2wi.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-sun6i-p2wi.c +7 -4
index dffbe776a195..1ef0e82eeb63 100644
@@ -220,10 +220,13 @@ static int p2wi_probe(struct platform_device *pdev)
 	childnp = of_get_next_available_child(np, NULL);
 	if (childnp) {
 		ret = of_property_read_u32(childnp, "reg", &target_addr);
-		if (ret)
-			return dev_err_probe(dev, -EINVAL,
-					     "invalid target address on node %pOF\n", childnp);
-
+		if (ret) {
+			ret = dev_err_probe(dev, -EINVAL,
+					    "invalid target address on node %pOF\n", childnp);
+			of_node_put(childnp);
+			return ret;
+		}
+		of_node_put(childnp);
 		p2wi->target_addr = target_addr;
 	}
 
Signature · 1 line
2.54.0
maintainer
#1 lore raw

drivers/i2c/busses/i2c-sun6i-p2wi.c static int p2wi_probe(struct platform_device *pdev)

Quoted 21 lines · Uday Khare

In p2wi_probe(), the device node reference obtained via of_get_next_available_child() is stored in childnp. This reference is never released via of_node_put() - neither on the error path when of_property_read_u32() fails to read the 'reg' property, nor on the success path after the target address has been read.

Fix this by calling of_node_put(childnp) on both the error and success paths.

Fixes 3e833490fae5 ("i2c: sunxi: add P2WI (Push/Pull 2 Wire Interface) controller support")
---
 drivers/i2c/busses/i2c-sun6i-p2wi.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-sun6i-p2wi.c +0 -0
index dffbe776a195..1ef0e82eeb63 100644
@@ -220,10 +220,13 @@ static int p2wi_probe(struct platform_device *pdev)

I would just include linux/cleanup.h and make the following line:

drivers/i2c/busses/i2c-sun6i-p2wi.c static int p2wi_probe(struct platform_device *pdev) · line 220

Quoted 1 line
drivers/i2c/busses/i2c-sun6i-p2wi.c +0 -0
        childnp = of_get_next_available_child(np, NULL);

struct device_node *childnp __free(device_node) =
of_get_next_available_child(np, NULL);

No other changes needed, and much cleaner.

Quoted 19 lines
drivers/i2c/busses/i2c-sun6i-p2wi.c +7 -5
        if (childnp) {
                ret = of_property_read_u32(childnp, "reg", &target_addr);
-               if (ret)
-                       return dev_err_probe(dev, -EINVAL,
-                                            "invalid target address on node %pOF\n", childnp);
-
+               if (ret) {
+                       ret = dev_err_probe(dev, -EINVAL,
+                                           "invalid target address on node %pOF\n", childnp);
+                       of_node_put(childnp);
+                       return ret;
+               }
+               of_node_put(childnp);
                p2wi->target_addr = target_addr;
        }
 
--

2.54.0