* [PATCH 0/5] i2c: fix device_node refcount leaks in 5 bus drivers
@ 2026-08-15 18:11 Liu Zhenlong
2026-08-15 18:12 ` [PATCH 1/5] i2c: mpc: fix device_node refcount leak in fsl_i2c_probe()/fsl_i2c_remove() Liu Zhenlong
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Liu Zhenlong @ 2026-08-15 18:11 UTC (permalink / raw)
To: andi.shyti, chris.packham, jochen, maddy, vz, piotr.wojtaszczyk
Cc: mpe, npiggin, chleroy, grant.likely, neelegup, benh, wsa, stigge,
linux-i2c, linuxppc-dev, linux-arm-kernel, linux-kernel,
Liu Zhenlong, stable
This series fixes device_node refcount leaks in 5 i2c bus drivers that
share the same bug pattern:
adap->dev.of_node = of_node_get(pdev->dev.of_node);
Each driver calls of_node_get() to take an extra reference on the
platform device's of_node when assigning it to the adapter device, but
none of them drop it in the probe error paths nor in the remove()
callback.
device_release() does not call of_node_put(), and
i2c_adapter_dev_release() only completes a struct, so the extra
reference is never released, leaking the device_node on every probe
failure and every adapter removal.
Additionally, in the remove() callbacks, i2c_del_adapter() clears
adap->dev with memset() at the end (commit bd4bc3dbded9 ("i2c: Clear
i2c_adapter.dev on adapter removal")), which zeroes adap->dev.of_node
before of_node_put() runs, turning it into a no-op. The fix caches the
pointer before calling i2c_del_adapter(), the same approach used in
i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3 ("mtd: core:
Fix refcount error in del_mtd_device()")).
A related fix for the i2c-qcom-cci driver has already been submitted
separately:
https://lore.kernel.org/linux-i2c/20260815140931.53297-1-dragonliu2018@gmail.com/
These 5 drivers are the remaining i2c bus drivers that use of_node_get()
on the adapter device; all other drivers either assign of_node directly
(without taking an extra reference) or don't use Device Tree at all.
Each patch has its own Fixes: tag pointing to the commit that introduced
of_node_get() in the respective driver, and requests stable backport via
Cc: stable@vger.kernel.org.
Compile-tested with gcc on arm64 defconfig using COMPILE_TEST; no
hardware available for runtime testing.
Liu Zhenlong (5):
i2c: mpc: fix device_node refcount leak in fsl_i2c_probe()/fsl_i2c_remove()
i2c: cpm: fix device_node refcount leak in cpm_i2c_probe()/cpm_i2c_remove()
i2c: ibm_iic: fix device_node refcount leak in iic_probe()/iic_remove()
i2c: opal: fix device_node refcount leak in i2c_opal_probe/remove()
i2c: pnx: fix device_node refcount leak in i2c_pnx_probe()/i2c_pnx_remove()
drivers/i2c/busses/i2c-cpm.c | 3 +++
drivers/i2c/busses/i2c-ibm_iic.c | 4 ++++
drivers/i2c/busses/i2c-mpc.c | 6 +++++-
drivers/i2c/busses/i2c-opal.c | 6 +++++-
drivers/i2c/busses/i2c-pnx.c | 15 ++++++++++++---
5 files changed, 29 insertions(+), 5 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] i2c: mpc: fix device_node refcount leak in fsl_i2c_probe()/fsl_i2c_remove()
2026-08-15 18:11 [PATCH 0/5] i2c: fix device_node refcount leaks in 5 bus drivers Liu Zhenlong
@ 2026-08-15 18:12 ` Liu Zhenlong
2026-08-15 18:12 ` [PATCH 2/5] i2c: cpm: fix device_node refcount leak in cpm_i2c_probe()/cpm_i2c_remove() Liu Zhenlong
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Liu Zhenlong @ 2026-08-15 18:12 UTC (permalink / raw)
To: andi.shyti, chris.packham, jochen, maddy, vz, piotr.wojtaszczyk
Cc: mpe, npiggin, chleroy, grant.likely, neelegup, benh, wsa, stigge,
linux-i2c, linuxppc-dev, linux-arm-kernel, linux-kernel,
Liu Zhenlong, stable
fsl_i2c_probe() calls of_node_get() to take an extra reference on the
platform device's of_node when assigning it to the adapter device, but
neither the probe error path nor fsl_i2c_remove() drops it.
device_release() does not call of_node_put() and i2c_adapter_dev_release()
only completes a struct, so the extra reference is never released, leaking
the device_node on every probe failure and every adapter removal.
Add the matching of_node_put() to both paths.
In the probe error path, i2c_add_numbered_adapter() failure does not run
i2c_del_adapter(), so of_node_put(i2c->adap.dev.of_node) is safe.
In fsl_i2c_remove(), i2c_del_adapter() clears adap->dev with memset() at
the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter
removal")), which zeroes adap->dev.of_node before of_node_put() runs,
turning it into a no-op. Cache the pointer before calling
i2c_del_adapter(), the same approach used in i2c-mux
(i2c_mux_del_adapters) and mtd (commit 56570bdad5e3 ("mtd: core: Fix
refcount error in del_mtd_device()")).
Compile-tested with gcc-powerpc-linux-gnu on pmac32 defconfig; no
hardware available for runtime testing.
Fixes: 9fd049927ccb ("of/i2c: Generalize OF support")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
---
drivers/i2c/busses/i2c-mpc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index a21fa45bd64c..8182f7dc3d0f 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -867,8 +867,10 @@ static int fsl_i2c_probe(struct platform_device *op)
i2c_set_adapdata(&i2c->adap, i2c);
result = i2c_add_numbered_adapter(&i2c->adap);
- if (result)
+ if (result) {
+ of_node_put(i2c->adap.dev.of_node);
return result;
+ }
return 0;
};
@@ -876,8 +878,10 @@ static int fsl_i2c_probe(struct platform_device *op)
static void fsl_i2c_remove(struct platform_device *op)
{
struct mpc_i2c *i2c = platform_get_drvdata(op);
+ struct device_node *node = i2c->adap.dev.of_node;
i2c_del_adapter(&i2c->adap);
+ of_node_put(node);
};
static int __maybe_unused mpc_i2c_suspend(struct device *dev)
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/5] i2c: cpm: fix device_node refcount leak in cpm_i2c_probe()/cpm_i2c_remove()
2026-08-15 18:11 [PATCH 0/5] i2c: fix device_node refcount leaks in 5 bus drivers Liu Zhenlong
2026-08-15 18:12 ` [PATCH 1/5] i2c: mpc: fix device_node refcount leak in fsl_i2c_probe()/fsl_i2c_remove() Liu Zhenlong
@ 2026-08-15 18:12 ` Liu Zhenlong
2026-08-15 18:12 ` [PATCH 3/5] i2c: ibm_iic: fix device_node refcount leak in iic_probe()/iic_remove() Liu Zhenlong
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Liu Zhenlong @ 2026-08-15 18:12 UTC (permalink / raw)
To: andi.shyti, chris.packham, jochen, maddy, vz, piotr.wojtaszczyk
Cc: mpe, npiggin, chleroy, grant.likely, neelegup, benh, wsa, stigge,
linux-i2c, linuxppc-dev, linux-arm-kernel, linux-kernel,
Liu Zhenlong, stable
cpm_i2c_probe() calls of_node_get() to take an extra reference on the
platform device's of_node when assigning it to the adapter device, but
neither the probe error paths nor cpm_i2c_remove() drops it.
device_release() does not call of_node_put() and i2c_adapter_dev_release()
only completes a struct, so the extra reference is never released, leaking
the device_node on every probe failure and every adapter removal.
Add the matching of_node_put() to the probe error cleanup (out_free, which
covers both the cpm_i2c_setup() and i2c_add_numbered_adapter() failure
paths, neither of which runs i2c_del_adapter()) and to cpm_i2c_remove().
In cpm_i2c_remove(), i2c_del_adapter() clears adap->dev with memset() at
the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter
removal")), which zeroes adap->dev.of_node before of_node_put() runs.
Cache the pointer before calling i2c_del_adapter(), the same approach
used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3
("mtd: core: Fix refcount error in del_mtd_device()")).
Compile-tested with gcc-powerpc-linux-gnu on tqm8xx defconfig; no
hardware available for runtime testing.
Fixes: 9fd049927ccb ("of/i2c: Generalize OF support")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
---
drivers/i2c/busses/i2c-cpm.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index 2cb6a233d313..08e33db32f14 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -671,6 +671,7 @@ static int cpm_i2c_probe(struct platform_device *ofdev)
out_shut:
cpm_i2c_shutdown(cpm);
out_free:
+ of_node_put(cpm->adap.dev.of_node);
kfree(cpm);
return result;
@@ -679,9 +680,11 @@ static int cpm_i2c_probe(struct platform_device *ofdev)
static void cpm_i2c_remove(struct platform_device *ofdev)
{
struct cpm_i2c *cpm = platform_get_drvdata(ofdev);
+ struct device_node *node = cpm->adap.dev.of_node;
i2c_del_adapter(&cpm->adap);
+ of_node_put(node);
cpm_i2c_shutdown(cpm);
kfree(cpm);
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] i2c: ibm_iic: fix device_node refcount leak in iic_probe()/iic_remove()
2026-08-15 18:11 [PATCH 0/5] i2c: fix device_node refcount leaks in 5 bus drivers Liu Zhenlong
2026-08-15 18:12 ` [PATCH 1/5] i2c: mpc: fix device_node refcount leak in fsl_i2c_probe()/fsl_i2c_remove() Liu Zhenlong
2026-08-15 18:12 ` [PATCH 2/5] i2c: cpm: fix device_node refcount leak in cpm_i2c_probe()/cpm_i2c_remove() Liu Zhenlong
@ 2026-08-15 18:12 ` Liu Zhenlong
2026-08-15 18:12 ` [PATCH 4/5] i2c: opal: fix device_node refcount leak in i2c_opal_probe/remove() Liu Zhenlong
2026-08-15 18:12 ` [PATCH 5/5] i2c: pnx: fix device_node refcount leak in i2c_pnx_probe()/i2c_pnx_remove() Liu Zhenlong
4 siblings, 0 replies; 6+ messages in thread
From: Liu Zhenlong @ 2026-08-15 18:12 UTC (permalink / raw)
To: andi.shyti, chris.packham, jochen, maddy, vz, piotr.wojtaszczyk
Cc: mpe, npiggin, chleroy, grant.likely, neelegup, benh, wsa, stigge,
linux-i2c, linuxppc-dev, linux-arm-kernel, linux-kernel,
Liu Zhenlong, stable
iic_probe() calls of_node_get() to take an extra reference on the
platform device's of_node when assigning it to the adapter device, but
neither the probe error path nor iic_remove() drops it.
device_release() does not call of_node_put() and i2c_adapter_dev_release()
only completes a struct, so the extra reference is never released, leaking
the device_node on every probe failure and every adapter removal.
Add the matching of_node_put() to the probe error cleanup (error_cleanup,
which covers the i2c_add_adapter() failure path; the earlier error paths
jump to the same label before of_node_get() runs, but dev is kzalloc'ed
so dev->adap.dev.of_node is NULL and of_node_put() is a no-op there) and
to iic_remove().
In iic_remove(), i2c_del_adapter() clears adap->dev with memset() at the
end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter
removal")), which zeroes adap->dev.of_node before of_node_put() runs.
Cache the pointer before calling i2c_del_adapter(), the same approach
used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3
("mtd: core: Fix refcount error in del_mtd_device()")).
Compile-tested with gcc-powerpc-linux-gnu on ppc44x defconfig; no
hardware available for runtime testing.
Fixes: 9fd049927ccb ("of/i2c: Generalize OF support")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
---
drivers/i2c/busses/i2c-ibm_iic.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 7c70e8bda24e..5c3b973c40d9 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -751,6 +751,8 @@ static int iic_probe(struct platform_device *ofdev)
free_irq(dev->irq, dev);
}
+ of_node_put(dev->adap.dev.of_node);
+
if (dev->vaddr)
iounmap(dev->vaddr);
@@ -764,8 +766,10 @@ static int iic_probe(struct platform_device *ofdev)
static void iic_remove(struct platform_device *ofdev)
{
struct ibm_iic_private *dev = platform_get_drvdata(ofdev);
+ struct device_node *node = dev->adap.dev.of_node;
i2c_del_adapter(&dev->adap);
+ of_node_put(node);
if (dev->irq) {
iic_interrupt_mode(dev, 0);
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] i2c: opal: fix device_node refcount leak in i2c_opal_probe/remove()
2026-08-15 18:11 [PATCH 0/5] i2c: fix device_node refcount leaks in 5 bus drivers Liu Zhenlong
` (2 preceding siblings ...)
2026-08-15 18:12 ` [PATCH 3/5] i2c: ibm_iic: fix device_node refcount leak in iic_probe()/iic_remove() Liu Zhenlong
@ 2026-08-15 18:12 ` Liu Zhenlong
2026-08-15 18:12 ` [PATCH 5/5] i2c: pnx: fix device_node refcount leak in i2c_pnx_probe()/i2c_pnx_remove() Liu Zhenlong
4 siblings, 0 replies; 6+ messages in thread
From: Liu Zhenlong @ 2026-08-15 18:12 UTC (permalink / raw)
To: andi.shyti, chris.packham, jochen, maddy, vz, piotr.wojtaszczyk
Cc: mpe, npiggin, chleroy, grant.likely, neelegup, benh, wsa, stigge,
linux-i2c, linuxppc-dev, linux-arm-kernel, linux-kernel,
Liu Zhenlong, stable
i2c_opal_probe() calls of_node_get() to take an extra reference on the
platform device's of_node when assigning it to the adapter device, but
neither the probe error path nor i2c_opal_remove() drops it.
device_release() does not call of_node_put() and i2c_adapter_dev_release()
only completes a struct, so the extra reference is never released, leaking
the device_node on every probe failure and every adapter removal.
Add the matching of_node_put() to both paths.
In the probe error path, i2c_add_adapter() failure does not run
i2c_del_adapter(), so of_node_put(adapter->dev.of_node) is safe.
In i2c_opal_remove(), i2c_del_adapter() clears adap->dev with memset()
at the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter
removal")), which zeroes adap->dev.of_node before of_node_put() runs.
Cache the pointer before calling i2c_del_adapter(), the same approach
used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3
("mtd: core: Fix refcount error in del_mtd_device()")).
Compile-tested with gcc-powerpc-linux-gnu on powernv defconfig; no
hardware available for runtime testing.
Fixes: 470834508f87 ("i2c: Driver to expose PowerNV platform i2c busses")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
---
drivers/i2c/busses/i2c-opal.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-opal.c b/drivers/i2c/busses/i2c-opal.c
index c9b62892397a..43b3d17e933b 100644
--- a/drivers/i2c/busses/i2c-opal.c
+++ b/drivers/i2c/busses/i2c-opal.c
@@ -226,8 +226,10 @@ static int i2c_opal_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, adapter);
rc = i2c_add_adapter(adapter);
- if (rc)
+ if (rc) {
dev_err(&pdev->dev, "Failed to register the i2c adapter\n");
+ of_node_put(adapter->dev.of_node);
+ }
return rc;
}
@@ -235,8 +237,10 @@ static int i2c_opal_probe(struct platform_device *pdev)
static void i2c_opal_remove(struct platform_device *pdev)
{
struct i2c_adapter *adapter = platform_get_drvdata(pdev);
+ struct device_node *node = adapter->dev.of_node;
i2c_del_adapter(adapter);
+ of_node_put(node);
}
static const struct of_device_id i2c_opal_of_match[] = {
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/5] i2c: pnx: fix device_node refcount leak in i2c_pnx_probe()/i2c_pnx_remove()
2026-08-15 18:11 [PATCH 0/5] i2c: fix device_node refcount leaks in 5 bus drivers Liu Zhenlong
` (3 preceding siblings ...)
2026-08-15 18:12 ` [PATCH 4/5] i2c: opal: fix device_node refcount leak in i2c_opal_probe/remove() Liu Zhenlong
@ 2026-08-15 18:12 ` Liu Zhenlong
4 siblings, 0 replies; 6+ messages in thread
From: Liu Zhenlong @ 2026-08-15 18:12 UTC (permalink / raw)
To: andi.shyti, chris.packham, jochen, maddy, vz, piotr.wojtaszczyk
Cc: mpe, npiggin, chleroy, grant.likely, neelegup, benh, wsa, stigge,
linux-i2c, linuxppc-dev, linux-arm-kernel, linux-kernel,
Liu Zhenlong, stable
i2c_pnx_probe() calls of_node_get() to take an extra reference on the
platform device's of_node when assigning it to the adapter device, but
none of the probe error paths nor i2c_pnx_remove() drops it.
device_release() does not call of_node_put() and i2c_adapter_dev_release()
only completes a struct, so the extra reference is never released, leaking
the device_node on every probe failure and every adapter removal.
Add the matching of_node_put() to all probe error paths (the three early
return paths before clk_prepare_enable(), and the out_clock label which
covers the wait_reset(), platform_get_irq(), devm_request_irq() and
i2c_add_numbered_adapter() failure paths; dev is devm_kzalloc'ed so
adapter.dev.of_node is NULL and of_node_put() is a no-op when CONFIG_OF
is not set) and to i2c_pnx_remove().
In i2c_pnx_remove(), i2c_del_adapter() clears adap->dev with memset()
at the end (commit bd4bc3dbded9 ("i2c: Clear i2c_adapter.dev on adapter
removal")), which zeroes adap->dev.of_node before of_node_put() runs.
Cache the pointer before calling i2c_del_adapter(), the same approach
used in i2c-mux (i2c_mux_del_adapters) and mtd (commit 56570bdad5e3
("mtd: core: Fix refcount error in del_mtd_device()")).
Compile-tested with gcc on arm64 defconfig using COMPILE_TEST; no
hardware available for runtime testing.
Fixes: b41a216dafe4 ("i2c: Add device tree support to i2c-pnx.c")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
---
drivers/i2c/busses/i2c-pnx.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 8daa0008bd05..0b6c144d9a21 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -644,20 +644,26 @@ 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))
+ if (IS_ERR(alg_data->clk)) {
+ of_node_put(alg_data->adapter.dev.of_node);
return PTR_ERR(alg_data->clk);
+ }
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))
+ if (IS_ERR(alg_data->ioaddr)) {
+ of_node_put(alg_data->adapter.dev.of_node);
return PTR_ERR(alg_data->ioaddr);
+ }
ret = clk_prepare_enable(alg_data->clk);
- if (ret)
+ if (ret) {
+ of_node_put(alg_data->adapter.dev.of_node);
return ret;
+ }
freq = clk_get_rate(alg_data->clk);
@@ -707,14 +713,17 @@ static int i2c_pnx_probe(struct platform_device *pdev)
out_clock:
clk_disable_unprepare(alg_data->clk);
+ of_node_put(alg_data->adapter.dev.of_node);
return ret;
}
static void i2c_pnx_remove(struct platform_device *pdev)
{
struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
+ struct device_node *node = alg_data->adapter.dev.of_node;
i2c_del_adapter(&alg_data->adapter);
+ of_node_put(node);
clk_disable_unprepare(alg_data->clk);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-08-15 18:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15 18:11 [PATCH 0/5] i2c: fix device_node refcount leaks in 5 bus drivers Liu Zhenlong
2026-08-15 18:12 ` [PATCH 1/5] i2c: mpc: fix device_node refcount leak in fsl_i2c_probe()/fsl_i2c_remove() Liu Zhenlong
2026-08-15 18:12 ` [PATCH 2/5] i2c: cpm: fix device_node refcount leak in cpm_i2c_probe()/cpm_i2c_remove() Liu Zhenlong
2026-08-15 18:12 ` [PATCH 3/5] i2c: ibm_iic: fix device_node refcount leak in iic_probe()/iic_remove() Liu Zhenlong
2026-08-15 18:12 ` [PATCH 4/5] i2c: opal: fix device_node refcount leak in i2c_opal_probe/remove() Liu Zhenlong
2026-08-15 18:12 ` [PATCH 5/5] i2c: pnx: fix device_node refcount leak in i2c_pnx_probe()/i2c_pnx_remove() Liu Zhenlong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox