[PATCH] i2c: pnx: Fix of_node reference leak in i2c_pnx_probe()
From: Wentao Liang
Date: Wed Sep 16 2026 - 13:49:58 EST
The device node reference taken with of_node_get() for the adapter
device is never released: the early probe error paths return without
dropping it, and neither the late error paths nor i2c_pnx_remove() put
it back. The i2c core does not release the adapter device's of_node
either.
Route the clock, I/O mapping and clock-enable error paths to a common
label that drops the node reference, and drop the reference after
i2c_del_adapter() in the remove path.
Fixes: b41a216dafe4 ("i2c: Add device tree support to i2c-pnx.c")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/i2c/busses/i2c-pnx.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 8daa0008bd05..b2a686b132ea 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -644,20 +644,24 @@ static int i2c_pnx_probe(struct platform_device *pdev)
}
#endif
alg_data->clk = devm_clk_get(&pdev->dev, NULL);
- if (IS_ERR(alg_data->clk))
- return PTR_ERR(alg_data->clk);
+ if (IS_ERR(alg_data->clk)) {
+ ret = PTR_ERR(alg_data->clk);
+ goto err_of_node;
+ }
snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name),
"%s", pdev->name);
/* Register I/O resource */
alg_data->ioaddr = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
- if (IS_ERR(alg_data->ioaddr))
- return PTR_ERR(alg_data->ioaddr);
+ if (IS_ERR(alg_data->ioaddr)) {
+ ret = PTR_ERR(alg_data->ioaddr);
+ goto err_of_node;
+ }
ret = clk_prepare_enable(alg_data->clk);
if (ret)
- return ret;
+ goto err_of_node;
freq = clk_get_rate(alg_data->clk);
@@ -707,6 +711,8 @@ static int i2c_pnx_probe(struct platform_device *pdev)
out_clock:
clk_disable_unprepare(alg_data->clk);
+err_of_node:
+ of_node_put(alg_data->adapter.dev.of_node);
return ret;
}
@@ -716,6 +722,7 @@ static void i2c_pnx_remove(struct platform_device *pdev)
i2c_del_adapter(&alg_data->adapter);
clk_disable_unprepare(alg_data->clk);
+ of_node_put(alg_data->adapter.dev.of_node);
}
#ifdef CONFIG_OF
--
2.34.1