From: Wentao Liang <vulab@iscas.ac.cn>
To: andi.shyti@kernel.org
Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org, piotr.wojtaszczyk@timesys.com,
stigge@antcom.de, vz@mleia.com, wsa@kernel.org,
Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] i2c: pnx: Fix of_node reference leak in i2c_pnx_probe()
Date: Wed, 16 Sep 2026 15:58:38 +0000 [thread overview]
Message-ID: <20260916155838.2078067-1-vulab@iscas.ac.cn> (raw)
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@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
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
reply other threads:[~2026-09-16 15:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916155838.2078067-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=andi.shyti@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=piotr.wojtaszczyk@timesys.com \
--cc=stable@vger.kernel.org \
--cc=stigge@antcom.de \
--cc=vz@mleia.com \
--cc=wsa@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox