* [PATCH v3] i2c: sun6i-p2wi: Fix device node reference leak in p2wi_probe
@ 2026-06-18 14:37 Uday Khare
0 siblings, 0 replies; only message in thread
From: Uday Khare @ 2026-06-18 14:37 UTC (permalink / raw)
To: Andi Shyti
Cc: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Arnd Bergmann,
Boris Brezillon, Maxime Ripard, Wolfram Sang, linux-i2c,
linux-arm-kernel, linux-sunxi, linux-kernel, 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, causing a device node reference leak.
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")
Signed-off-by: Uday Khare <udaykhare77@gmail.com>
---
v3:
- Revert back to manual of_node_put() because the function uses goto-based
error handling, and mixing the two styles is discouraged (reported by
Sashiko-bot).
v2:
- Use __free(device_node) and include <linux/cleanup.h> to automate the device
node reference cleanup instead of manually calling of_node_put() on error and
success paths (suggested by Chen-Yu Tsai).
drivers/i2c/busses/i2c-sun6i-p2wi.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c
index dffbe776a195..7c0239f8937e 100644
--- a/drivers/i2c/busses/i2c-sun6i-p2wi.c
+++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c
@@ -184,7 +184,6 @@ static int p2wi_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
- struct device_node *childnp;
unsigned long parent_clk_freq;
u32 clk_freq = I2C_MAX_STANDARD_MODE_FREQ;
struct p2wi *p2wi;
@@ -217,14 +216,19 @@ static int p2wi_probe(struct platform_device *pdev)
* In this case the target_addr is set to -1 and won't be checked when
* launching a P2WI transfer.
*/
+ struct device_node *childnp;
+
childnp = of_get_next_available_child(np, NULL);
if (childnp) {
ret = of_property_read_u32(childnp, "reg", &target_addr);
- if (ret)
+ if (ret) {
+ of_node_put(childnp);
return dev_err_probe(dev, -EINVAL,
"invalid target address on node %pOF\n", childnp);
+ }
p2wi->target_addr = target_addr;
+ of_node_put(childnp);
}
p2wi->regs = devm_platform_ioremap_resource(pdev, 0);
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-06-18 14:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-18 14:37 [PATCH v3] i2c: sun6i-p2wi: Fix device node reference leak in p2wi_probe Uday Khare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox