From: Liu Zhenlong <dragonliu2018@gmail.com>
To: loic.poulain@oss.qualcomm.com, rfoss@kernel.org, andi.shyti@kernel.org
Cc: vladimir.zapolskiy@linaro.org, wsa@kernel.org,
andersson@kernel.org, linux-i2c@vger.kernel.org,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
Liu Zhenlong <dragonliu2018@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()
Date: Sat, 15 Aug 2026 22:09:31 +0800 [thread overview]
Message-ID: <20260815140931.53297-1-dragonliu2018@gmail.com> (raw)
cci_probe() calls of_node_get() to take an extra reference on the
child device_node when assigning it to the adapter device. The
matching of_node_put() calls exist in both the error cleanup path
and cci_remove(), but they are placed after i2c_del_adapter().
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 reference taken by of_node_get() is never released, leaking
the device_node on every cleanup of already-registered adapters and
every adapter removal.
The commit that added of_node_get() and the matching of_node_put()
calls placed the puts after i2c_del_adapter(), so the bug has been
present since the fix was introduced.
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()")).
The of_node_put() in the i2c_add_adapter() failure path (before any
i2c_del_adapter() runs) is correct and left unchanged.
Fixes: 02a4a69667a2 ("i2c: qcom-cci: don't put a device tree node before i2c_add_adapter()")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
---
drivers/i2c/busses/i2c-qcom-cci.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index bdeda3979c48..61c535b8196f 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -618,8 +618,10 @@ static int cci_probe(struct platform_device *pdev)
for (--i ; i >= 0; i--) {
if (cci->master[i].cci) {
+ struct device_node *node = cci->master[i].adap.dev.of_node;
+
i2c_del_adapter(&cci->master[i].adap);
- of_node_put(cci->master[i].adap.dev.of_node);
+ of_node_put(node);
}
}
disable_clocks:
@@ -635,8 +637,10 @@ static void cci_remove(struct platform_device *pdev)
for (i = 0; i < cci->data->num_masters; i++) {
if (cci->master[i].cci) {
+ struct device_node *node = cci->master[i].adap.dev.of_node;
+
i2c_del_adapter(&cci->master[i].adap);
- of_node_put(cci->master[i].adap.dev.of_node);
+ of_node_put(node);
cci_halt(cci, i);
}
}
--
2.55.0
next reply other threads:[~2026-08-15 14:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 14:09 Liu Zhenlong [this message]
2026-08-18 11:41 ` [PATCH] i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove() Konrad Dybcio
2026-08-18 17:57 ` [PATCH v2] " Liu Zhenlong
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=20260815140931.53297-1-dragonliu2018@gmail.com \
--to=dragonliu2018@gmail.com \
--cc=andersson@kernel.org \
--cc=andi.shyti@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=rfoss@kernel.org \
--cc=stable@vger.kernel.org \
--cc=vladimir.zapolskiy@linaro.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.