| Message ID | 20260618143727.18534-1-udaykhare77@gmail.com (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-23867-sunxi=pue.re@lists.linux.dev>
X-Original-To: noreply@patchwork.local
Delivered-To: noreply@patchwork.local
Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mxe881.netcup.net (Postfix) with ESMTPS id 648351C007A
for <noreply@patchwork.local>; Thu, 18 Jun 2026 16:37:45 +0200 (CEST)
Authentication-Results: mxe881;
dkim=pass header.d=gmail.com;
spf=pass (sender IP is 104.64.211.4)
smtp.mailfrom=linux-sunxi+bounces-23867-noreply=patchwork.local@lists.linux.dev
smtp.helo=sin.lore.kernel.org
Received-SPF: pass (mxe881: domain of lists.linux.dev designates 104.64.211.4
as permitted sender) client-ip=104.64.211.4;
envelope-from=linux-sunxi+bounces-23867-noreply=patchwork.local@lists.linux.dev;
helo=sin.lore.kernel.org;
Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org
[100.90.174.1])
by sin.lore.kernel.org (Postfix) with ESMTP id 9375930034B5
for <noreply@patchwork.local>; Thu, 18 Jun 2026 14:37:40 +0000 (UTC)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B9D7309EE7;
Thu, 18 Jun 2026 14:37:39 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com
header.b="qwWClK1S"
X-Original-To: linux-sunxi@lists.linux.dev
Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com
[209.85.214.176])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28F6742AA9
for <linux-sunxi@lists.linux.dev>; Thu, 18 Jun 2026 14:37:38 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=none smtp.client-ip=209.85.214.176
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1781793459; cv=none;
b=TFY2xQvnoYsZweQEUFPWM/RQapxt89QQcYd2KqumbV9bQuWxiwpVW0eMTUOIP3Gw5Ix6uH1UhxGuheimQD4eYyklu1EOcgEdwgF0/SXOoPoaGPwhbWb2eEJeSqD0CMpSJDlH2CxDRCCu31YV5ArMywzJ7ABJdBRevihsPKxCvbU=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1781793459; c=relaxed/simple;
bh=3RrLXo8g5qNVx7ZmgCg1GjrH6fG8zBsnfo5ZLbth0eQ=;
h=From:To:Cc:Subject:Date:Message-ID:MIME-Version;
b=bqnfgk4pKZVd+P5cBjLNKzTAnsKkSZTLl1grswyuYiA4mpKUtlLnJNjeksoPPu6VgnGs1azvqlaqzql0YaS59aJoiR4kvlb5zRM4IyGQ+JJCWljTtSn9C3MOsjm/zbmAX52Ema3OwlFRgkBuaOkdMchN5CZFQoRKgCVT5SpAtoA=
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass (p=none dis=none) header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com
header.b=qwWClK1S; arc=none smtp.client-ip=209.85.214.176
Authentication-Results: smtp.subspace.kernel.org;
dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
spf=pass smtp.mailfrom=gmail.com
Received: by mail-pl1-f176.google.com with SMTP id
d9443c01a7336-2c0c3546924so9025375ad.3
for <linux-sunxi@lists.linux.dev>;
Thu, 18 Jun 2026 07:37:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1781793457; x=1782398257;
darn=lists.linux.dev;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to;
bh=eWNFSAoF1QlxpTcEDqHs6xokC99S7BGwHt6RGWcEFBE=;
b=qwWClK1Sn1jbo1Q5ctiGC2wk9t/+Mby4P2aO55tNPLDy9hjzqT2G1jNOwzi42myUd/
meQoXM5dKjUs7uXWPMMFaQ0zWeJNJq/CfYAbOkKI8QbyT3MWkrwS6El+xJ9y5MllfDPr
Jq4GI5nTNhIYGilKrfA8sSxkcCrTSW/snKm+ii2sxHn/Si2ydqOJ2yddbxR8Kif474pa
D9TsF9puWNP07zMlxSb57zjz8XKtCNX66Y0lrWo9SVwbc0DUfMvfNm/Aa+SCbSXwjxgx
8yB7heBz21ow72Bkp1Z8ubCRQ6NLXY1NQtEJr/hnFTWoC1RjW0TXnXNmKtED6BEB+KH7
o52g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20251104; t=1781793457; x=1782398257;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to;
bh=eWNFSAoF1QlxpTcEDqHs6xokC99S7BGwHt6RGWcEFBE=;
b=EGsIa5J2eH3C1B+X9ivKBK/3d/AFdy6kAWtEtyeYztexCFQHdjNZo2TTIbmCVpgJ07
dnxkAdhG4pSeeDyyK31OBT0LYc7VB0sqGOIuIo8+C6+G98b5xFTe8+i9O5Y75L6Eh5FR
xI0ewP8+Yfwu27hOjDCyxLLahzwbHGTLb+9e3hjO8CB9fDOaUnXabrbNjLOq2+5UwbDY
iYFwf+wmPhXE8wWaSfrtLWK8HyETuZ43XxT2bzwPKMs4WvUKTtClZSztiDW7ezfgCO1Y
HC42/SRrvm9P74Gt173WFepgG9irGklwDXTXaFYHOtEFS3b8lWL62pB94lA8YqoBqfgX
rP3A==
X-Forwarded-Encrypted: i=1;
AFNElJ9kaK0SsikCib4J1hflrV4bOoXeuMjP/3rmT0WfmhcyD4tSwBcZY7Jjgit9IsWyn8SobxK0QRpTM50yFg==@lists.linux.dev
X-Gm-Message-State: AOJu0YyMXlBrbqOuCEtTDDgfa+CgjfKhralEOCL59PQ+wauDLsD0pXs3
+d4ahEVr9zce60QzqBfEKfMFWMyjwuyWZlZhfM90zLeU17BMXZ8b41to
X-Gm-Gg: AfdE7cl/nssrb3eLq09Bf5QrazathskaeFIzkk9qe17U8kYKl3SyBljFD9G6HYCvqwa
boVcE/0xdaUCPYnuvw1Fzr5Av6+hhMSblLztGbaxq+nXxrF4w5zlpQr4M1dgRc6XY+Qr35QYFFS
VFmMnWS6gAYPgxjPOwF6ebfIqYcibe1D7w/HchHFuNINXV/sF4YrrdZapbtcu7CcJ3ngeFsXMZd
8OWZR8upWLQcMmNYiE3j0qEhN+81arUA+duBRKB093T0HgknJ0mCpWV62ckIjPNk82XEDadrVIE
6yPL2HzkLEaOPWFrZWo75ljaaq63TQhq9gni0pQi845c0raaft0w+dumSPornMJqXstO9fTOTMJ
iOc1bdTmsWXzYd26FVYj7QgXZTolJVuPHE5EJCYeTnsWRIN+8YN+91v1SYt5LyZw3mTRjeSRS8S
tPp9ij5qplXt4tEAx3du6ivXTQA0aKF1ejhoXq7ZC8sA==
X-Received: by 2002:a17:902:f64d:b0:2bf:1e59:d99 with SMTP id
d9443c01a7336-2c6e47253b2mr49138885ad.8.1781793457447;
Thu, 18 Jun 2026 07:37:37 -0700 (PDT)
Received: from steellegend.taila75641.ts.net
([2409:40c4:35e:20d7:2ccf:7534:4b88:ba43])
by smtp.gmail.com with ESMTPSA id
d9443c01a7336-2c6f9aec764sm22554115ad.2.2026.06.18.07.37.32
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 18 Jun 2026 07:37:36 -0700 (PDT)
From: Uday Khare <udaykhare77@gmail.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Arnd Bergmann <arnd@arndb.de>,
Boris Brezillon <bbrezillon@kernel.org>,
Maxime Ripard <mripard@kernel.org>,
Wolfram Sang <wsa@kernel.org>,
linux-i2c@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev,
linux-kernel@vger.kernel.org,
Uday Khare <udaykhare77@gmail.com>
Subject: [PATCH v3] i2c: sun6i-p2wi: Fix device node reference leak in
p2wi_probe
Date: Thu, 18 Jun 2026 20:07:27 +0530
Message-ID: <20260618143727.18534-1-udaykhare77@gmail.com>
X-Mailer: git-send-email 2.54.0
Precedence: bulk
X-Mailing-List: linux-sunxi@lists.linux.dev
List-Id: <linux-sunxi.lists.linux.dev>
List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Rspamd-Server: rspamd-worker-8404
X-Spamd-Result: default: False [0.34 / 15.00];
BAYES_HAM(-5.50)[100.00%];
RBL_SENDERSCORE(2.00)[104.64.211.4:from];
SUSPICIOUS_RECIPS(1.50)[];
MID_CONTAINS_FROM(1.00)[];
DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed),
No valid DKIM,none];
R_MISSING_CHARSET(0.50)[];
MAILLIST(-0.15)[generic];
MIME_GOOD(-0.10)[text/plain];
BAD_REP_POLICIES(0.10)[];
HAS_LIST_UNSUB(-0.01)[];
RCPT_COUNT_TWELVE(0.00)[13];
DBL_BLOCKED_OPENRESOLVER(0.00)[sin.lore.kernel.org:rdns,sin.lore.kernel.org:helo];
FUZZY_BLOCKED(0.00)[rspamd.com];
FORGED_SENDER_MAILLIST(0.00)[];
FREEMAIL_FROM(0.00)[gmail.com];
FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,arndb.de,vger.kernel.org,lists.infradead.org,lists.linux.dev];
TO_DN_SOME(0.00)[];
R_SPF_ALLOW(0.00)[+ip4:104.64.211.4];
TAGGED_RCPT(0.00)[];
FROM_HAS_DN(0.00)[];
RCVD_TLS_LAST(0.00)[];
MIME_TRACE(0.00)[0:+];
FORGED_RECIPIENTS_MAILLIST(0.00)[];
PRECEDENCE_BULK(0.00)[];
ASN(0.00)[asn:63949, ipnet:104.64.192.0/19, country:SG];
ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1];
TAGGED_FROM(0.00)[bounces-23867-noreply=patchwork.local];
RCVD_COUNT_FIVE(0.00)[6];
FROM_NEQ_ENVFROM(0.00)[udaykhare77@gmail.com,linux-sunxi@lists.linux.dev];
RCVD_VIA_SMTP_AUTH(0.00)[]
X-Rspamd-Queue-Id: 648351C007A
X-MORS-Enabled: yes
X-MORS-DOMAIN: patchwork.local
X-MORS-HOSTING: hosting172546
X-MORS-USER: hosting172546
X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?=
|
| Series |
[v3] i2c: sun6i-p2wi: Fix device node reference leak in p2wi_probe
|
|
Commit Message
Uday Khare
June 18, 2026, 2:37 p.m. UTC
In p2wi_probe(), the device node reference obtained via
of_get_next_available_child() is stored in childnp. This reference is
never released, causing a device node reference leak.
Fix this by calling of_node_put(childnp) on both the error and success
paths.
Fixes: 3e833490fae5 ("i2c: sunxi: add P2WI (Push/Pull 2 Wire Interface) controller support")
Signed-off-by: Uday Khare <udaykhare77@gmail.com>
---
v3:
- Revert back to manual of_node_put() because the function uses goto-based
error handling, and mixing the two styles is discouraged (reported by
Sashiko-bot).
v2:
- Use __free(device_node) and include <linux/cleanup.h> to automate the device
node reference cleanup instead of manually calling of_node_put() on error and
success paths (suggested by Chen-Yu Tsai).
drivers/i2c/busses/i2c-sun6i-p2wi.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
Comments
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: New issues: - [High] Calling `of_node_put(childnp)` before passing `childnp` to `dev_err_probe()` causes a use-after-free because the `%pOF` format specifier dereferences the freed node. Pre-existing issues: - [High] Hardware reset is asserted before the I2C adapter is deleted in `p2wi_remove()`, risking hangs and incomplete transfers. - [High] The I2C transfer function `p2wi_smbus_xfer()` uses `wait_for_completion()` without a timeout, which can permanently hang the kernel task if the hardware fails. -- commit c8d2fd420d274dc476834daabf9f1fb97be750d0 Author: Uday Khare <udaykhare77@gmail.com> i2c: sun6i-p2wi: Fix device node reference leak in p2wi_probe This commit addresses a device node reference leak in p2wi_probe() by calling of_node_put() on the child node reference obtained via of_get_next_available_child(). The fix is applied to both the success and error paths. > diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c > index dffbe776a195d..7c0239f8937ea 100644 > --- a/drivers/i2c/busses/i2c-sun6i-p2wi.c > +++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c [ ... ] > @@ -217,14 +216,19 @@ static int p2wi_probe(struct platform_device *pdev) > * In this case the target_addr is set to -1 and won't be checked when > * launching a P2WI transfer. > */ > + struct device_node *childnp; > + > childnp = of_get_next_available_child(np, NULL); > if (childnp) { > ret = of_property_read_u32(childnp, "reg", &target_addr); > - if (ret) > + if (ret) { > + of_node_put(childnp); > return dev_err_probe(dev, -EINVAL, > "invalid target address on node %pOF\n", childnp); [Severity: High] Does calling of_node_put() before dev_err_probe() cause a use-after-free? The %pOF format specifier in dev_err_probe() will dereference childnp to read its full name. Since of_node_put() decrements the reference count and can potentially free the node, accessing it immediately afterwards might lead to a use-after-free. Could the node be released after logging the error instead? > + } > > p2wi->target_addr = target_addr; > + of_node_put(childnp); > } While reviewing the above, I also noticed a couple of pre-existing issues in the same file: drivers/i2c/busses/i2c-sun6i-p2wi.c:p2wi_remove() { ... reset_control_assert(p2wi->rstc); i2c_del_adapter(&p2wi->adapter); } [Severity: High] This is a pre-existing issue, but could asserting the hardware reset before deleting the I2C adapter risk hanging the system? If reset_control_assert() disables the hardware while i2c_del_adapter() is still waiting for ongoing transfers to finish or accepting new ones, any in-flight transfers might interact with a disabled controller. This could lead to the driver waiting indefinitely for an interrupt. Should i2c_del_adapter() be called before asserting the hardware reset? drivers/i2c/busses/i2c-sun6i-p2wi.c:p2wi_smbus_xfer() { ... writel(P2WI_CTRL_START_TRANS | P2WI_CTRL_GLOBAL_INT_ENB, p2wi->regs + P2WI_CTRL); wait_for_completion(&p2wi->complete); ... } [Severity: High] This is a pre-existing issue, but can this wait_for_completion() hang the kernel task permanently? If the hardware fails to generate an interrupt due to a bus lockup, a missed edge, or reset, the calling thread will block indefinitely in an uninterruptible sleep state because there is no timeout mechanism. Would it be safer to use wait_for_completion_timeout() and handle the timeout condition by reporting an error and cleaning up?
diff --git a/drivers/i2c/busses/i2c-sun6i-p2wi.c b/drivers/i2c/busses/i2c-sun6i-p2wi.c index dffbe776a195..7c0239f8937e 100644 --- a/drivers/i2c/busses/i2c-sun6i-p2wi.c +++ b/drivers/i2c/busses/i2c-sun6i-p2wi.c @@ -184,7 +184,6 @@ static int p2wi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - struct device_node *childnp; unsigned long parent_clk_freq; u32 clk_freq = I2C_MAX_STANDARD_MODE_FREQ; struct p2wi *p2wi; @@ -217,14 +216,19 @@ static int p2wi_probe(struct platform_device *pdev) * In this case the target_addr is set to -1 and won't be checked when * launching a P2WI transfer. */ + struct device_node *childnp; + childnp = of_get_next_available_child(np, NULL); if (childnp) { ret = of_property_read_u32(childnp, "reg", &target_addr); - if (ret) + if (ret) { + of_node_put(childnp); return dev_err_probe(dev, -EINVAL, "invalid target address on node %pOF\n", childnp); + } p2wi->target_addr = target_addr; + of_node_put(childnp); } p2wi->regs = devm_platform_ioremap_resource(pdev, 0);