From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795044100; b=q97ad5iSzT9hKRJ31XlJwlr3yqHrCHQpwTL+E8xlzAMDUquuupYDdGlpcwIvPWJT6R22 pJADSlhijtX7Sd4Us7M5mUnXY7F4ByViHmsYKXk6V3LUr2qOMrSXL/11yzYCmEpSNcwZU HS0n/gNGpJBHWgZCNouu188XTrn3zRYB1jWpuMpQuA21mLySOB3JwY4zlxpgiXLWrecVx tcPjmeOKDbJvAfQ7VCWQu5lU53nJSoYhVJs01uuLBAkx5isD1gx/Nuh7Uw9J4avuSeAn4 d01lORYhgsRVg4hNYh5yvm4KtBNCFINrvWHmQPjimlCAeZMweuth12ycjLP8xrtV9gA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795044100; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=XUFa2wJb9Q3pt/xFSXFZnbiGw8itGqOpZMpl5XMFOaQ=; b=0n99ipQ4aS7xfJBtrBVGKNnDs7hNkir+W8dFLfLSgNpLCcXQSuj266860T1uEEzUk8Ha XWGo8Lp7TL1Pl8Rmg1b8IAIq57815m6+eIuFnpxwBYj1/DwRlg+/7YTaRKsF6uXk4fB41 TxrR/GmlK74aYrFE7wO84/glptxYKsyQR4tArGxeM8gTOb0vbuRO2M4LC7aufnCYjpLUQ THQOpuNs3IVyEnyQgYEyguMPvla25/zUU8fWe9KgVm8+JX6CcBWf87gQCzYYzvNeokkQH i7TuKXOaBlsPr8nWoiVydUGKlZqU3dmQ2QKX1dw8t8zoUB5JRnfI0IJe82Uiv6TtCrA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kZxvoDO5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34F14606A32C; Wed, 18 Nov 2026 23:21:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kZxvoDO5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 857F31F000C4; Wed, 18 Nov 2026 23:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795044100; bh=XUFa2wJb9Q3pt/xFSXFZnbiGw8itGqOpZMpl5XMFOaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kZxvoDO5Gwn0PYFBZRUnxtuUna3f8F+2XpcnBL/ek9CkWifPTMJ0tzxMWZ9iM/KAD Y9tiB08x04WMLrTa50KKjg3E+AR5e7pP9bbYAf2/nFZKFkg8XoVGSAwRN50Aj8X4Oc tWAm3OGCcECxvZxjEFYC56AR4hLwBnugRyeO7cls= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Konrad Dybcio , Liu Zhenlong , Vladimir Zapolskiy , Andi Shyti , Sasha Levin Subject: [PATCH 6.1 0446/2857] i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove() Date: Wed, 18 Nov 2026 15:24:40 +0100 Message-ID: <20261118150217.434575623@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Zhenlong [ 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 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 Cc: # v5.17+ Reviewed-by: Vladimir Zapolskiy Reviewed-by: Konrad Dybcio Signed-off-by: Andi Shyti Link: https://patch.msgid.link/20260818175750.4205-1-dragonliu2018@gmail.com Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-qcom-cci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c index 16c2b7d9069de..aebc552f0f4b2 100644 --- a/drivers/i2c/busses/i2c-qcom-cci.c +++ b/drivers/i2c/busses/i2c-qcom-cci.c @@ -520,10 +520,14 @@ 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 resource *r; struct cci *cci; int ret, i; @@ -539,7 +543,7 @@ static int cci_probe(struct platform_device *pdev) if (!cci->data) return -ENOENT; - for_each_available_child_of_node(dev->of_node, child) { + for_each_available_child_of_node_scoped(dev->of_node, child) { struct cci_master *master; u32 idx; @@ -560,6 +564,9 @@ static int cci_probe(struct platform_device *pdev) master->adap.algo = &cci_algo; master->adap.dev.parent = dev; master->adap.dev.of_node = of_node_get(child); + ret = devm_add_action_or_reset(dev, cci_put_of_node, child); + if (ret) + return ret; master->master = idx; master->cci = cci; @@ -634,10 +641,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; @@ -645,10 +650,8 @@ static int cci_probe(struct platform_device *pdev) error_i2c: 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); - } } disable_irq(cci->irq); @@ -673,7 +676,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