From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Liu Zhenlong <dragonliu2018@gmail.com>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>,
Andi Shyti <andi.shyti@kernel.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.15.y 4/4] i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()
Date: Tue, 22 Sep 2026 13:51:06 -0400 [thread overview]
Message-ID: <20260922175106.3308111-4-sashal@kernel.org> (raw)
In-Reply-To: <20260922175106.3308111-1-sashal@kernel.org>
From: Liu Zhenlong <dragonliu2018@gmail.com>
[ Upstream commit 7362a1553eb09a8cdf8be7e509bd5309a8342486 ]
The of_node_put() matching of_node_get() runs after i2c_del_adapter(),
whose trailing memset() zeroes adap->dev and thus adap->dev.of_node,
making the put a no-op and leaking the node on every adapter removal
and error cleanup.
Use a devm action: the pointer is captured at registration, out of
reach of that memset(), and devres runs the put once on probe failure
and detach, replacing the three manual of_node_put() calls. The
setup loop uses the scoped iterator form so the child node is released
automatically if devm_add_action_or_reset() fails mid-loop.
Suggested-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Fixes: 02a4a69667a2 ("i2c: qcom-cci: don't put a device tree node before i2c_add_adapter()")
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
Cc: <stable@vger.kernel.org> # v5.17+
Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://patch.msgid.link/20260818175750.4205-1-dragonliu2018@gmail.com
[ Replaced the scoped iterator with the existing iterator and a function-scoped cleanup variable for GNU89 compatibility. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/i2c/busses/i2c-qcom-cci.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index 6a4d8a546fa75..f3af3a14d2b57 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -520,10 +520,15 @@ static const struct dev_pm_ops qcom_cci_pm = {
SET_RUNTIME_PM_OPS(cci_suspend_runtime, cci_resume_runtime, NULL)
};
+static void cci_put_of_node(void *data)
+{
+ of_node_put(data);
+}
+
static int cci_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *child;
+ struct device_node *child __free(device_node) = NULL;
struct resource *r;
struct cci *cci;
int ret, i;
@@ -558,6 +563,9 @@ static int cci_probe(struct platform_device *pdev)
cci->master[idx].adap.algo = &cci_algo;
cci->master[idx].adap.dev.parent = dev;
cci->master[idx].adap.dev.of_node = of_node_get(child);
+ ret = devm_add_action_or_reset(dev, cci_put_of_node, child);
+ if (ret)
+ return ret;
cci->master[idx].master = idx;
cci->master[idx].cci = cci;
@@ -631,10 +639,8 @@ static int cci_probe(struct platform_device *pdev)
continue;
ret = i2c_add_adapter(&cci->master[i].adap);
- if (ret < 0) {
- of_node_put(cci->master[i].adap.dev.of_node);
+ if (ret < 0)
goto error_i2c;
- }
}
return 0;
@@ -644,10 +650,8 @@ static int cci_probe(struct platform_device *pdev)
pm_runtime_dont_use_autosuspend(dev);
for (--i ; i >= 0; i--) {
- if (cci->master[i].cci) {
+ if (cci->master[i].cci)
i2c_del_adapter(&cci->master[i].adap);
- of_node_put(cci->master[i].adap.dev.of_node);
- }
}
error:
disable_irq(cci->irq);
@@ -665,7 +669,6 @@ static int cci_remove(struct platform_device *pdev)
for (i = 0; i < cci->data->num_masters; i++) {
if (cci->master[i].cci) {
i2c_del_adapter(&cci->master[i].adap);
- of_node_put(cci->master[i].adap.dev.of_node);
cci_halt(cci, i);
}
}
--
2.53.0
prev parent reply other threads:[~2026-09-22 17:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 9:39 FAILED: patch "[PATCH] i2c: qcom-cci: fix device_node refcount leak in" failed to apply to 5.15-stable tree gregkh
2026-09-22 17:51 ` [PATCH 5.15.y 1/4] of: Introduce for_each_*_child_of_node_scoped() to automate of_node_put() handling Sasha Levin
2026-09-22 17:51 ` [PATCH 5.15.y 2/4] i2c: qcom-cci: Stop complaining about DT set clock rate Sasha Levin
2026-09-22 17:51 ` [PATCH 5.15.y 3/4] i2c: qcom-cci: Remove the unused variable cci_clk_rate Sasha Levin
2026-09-22 17:51 ` Sasha Levin [this message]
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=20260922175106.3308111-4-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andi.shyti@kernel.org \
--cc=dragonliu2018@gmail.com \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=stable@vger.kernel.org \
--cc=vladimir.zapolskiy@linaro.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