| Message ID | 20260424000000.558-1-mhun512@gmail.com (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-23324-sunxi=pue.re@lists.linux.dev>
X-Original-To: noreply@patchwork.local
Delivered-To: noreply@patchwork.local
Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mxe881.netcup.net (Postfix) with ESMTPS id 5BA051C053C
for <noreply@patchwork.local>; Wed, 13 May 2026 09:11:45 +0200 (CEST)
Authentication-Results: mxe881;
dkim=pass header.d=gmail.com;
spf=pass (sender IP is 172.232.135.74)
smtp.mailfrom=linux-sunxi+bounces-23324-noreply=patchwork.local@lists.linux.dev
smtp.helo=sto.lore.kernel.org
Received-SPF: pass (mxe881: domain of lists.linux.dev designates
172.232.135.74 as permitted sender) client-ip=172.232.135.74;
envelope-from=linux-sunxi+bounces-23324-noreply=patchwork.local@lists.linux.dev;
helo=sto.lore.kernel.org;
Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org
[100.90.174.1])
by sto.lore.kernel.org (Postfix) with ESMTP id 5EEB6302EF50
for <noreply@patchwork.local>; Wed, 13 May 2026 07:11:31 +0000 (UTC)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 0EE603D5C23;
Wed, 13 May 2026 07:11:26 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com
header.b="o77jdzrU"
X-Original-To: linux-sunxi@lists.linux.dev
Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com
[209.85.214.175])
(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 7AB7938B130
for <linux-sunxi@lists.linux.dev>; Wed, 13 May 2026 07:11:23 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=none smtp.client-ip=209.85.214.175
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1778656285; cv=none;
b=hV/KsNiQrTmcnMGWqQMwH7R3yHvolj81jkS9eHQ9IrkxwSCM93muTt3cHkcJ26UuCy1xCMdfrZqom3fd2TZxGSngicqdfP27rS+xACQaaqsqZfiG9JJLENy3xSBHgxUHrewcPwV9cV8ju+T4yxKCoJmSCiM0/Df2KSjf8aT8riE=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1778656285; c=relaxed/simple;
bh=h207wMrvvV1Ldhg9nEqnfEuJuI1hYIKUwGDHp11u7W0=;
h=From:To:Cc:Subject:Date:Message-ID:MIME-Version;
b=Td4IpEUbF5XzU+gzNjT3xJLiXWM1SalLSjOTz1GYHtZqePHFlpy+CvzivLUWJrgEVbSoUElrqdZ2Y7OOFJmKmykFjnwOhEnlaUn4XBQAM7IJDlVsZJhupFSHJaID5mG+XQjw9HZ9kIsNdUBlJJ3titir4O8og9fPTJaapw9JPNc=
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=o77jdzrU; arc=none smtp.client-ip=209.85.214.175
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-f175.google.com with SMTP id
d9443c01a7336-2baca4df358so39330805ad.2
for <linux-sunxi@lists.linux.dev>;
Wed, 13 May 2026 00:11:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1778656283; x=1779261083;
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=MAUm05/737IqhRNlo9FHhqv1K5HUvIKv2GcQLIvOcf0=;
b=o77jdzrUTAE7OPCVkfiypKJLnJ9Wmc9TA20oeVatOmqQrh8Ru4F7q5Td/zf+lwxAV+
Il9j2YhftdPlJrBrmpqByTQaTMgpQB9ouUuas0glYvlOKff2rIVIhgu5W1MqCTLcyAAU
nw/LPfBflKMRYbpDdUa63FWv6y7RKYshbXz7L9IytDwoHwMcJNj2ekiBz8xn0ozDLkmM
1P6wDqZOqtsw+wl3rwe84vSbAnklzJarBEjiNcM0hkkbRH719AoWLkVf0z/zTyHyFZ8H
Uu1unFpjhUBxVF36fJhkLURPF+JYxFNQasQczeepHz9hGJ45NMGHLjBN0xsHXS2/sA9B
T6WQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20251104; t=1778656283; x=1779261083;
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=MAUm05/737IqhRNlo9FHhqv1K5HUvIKv2GcQLIvOcf0=;
b=Y7wmCj7ZOhQtfodsdBSBzK9g5gPUi2ULpi4b04QlpPmNLdoGZv9A+IdPNALNuvpnQ7
5w6IYLp7aEWDgfWMJuP/wE0znX7pDA4CBJfeeMgGHuf7Gg/T6om2In1XZz8TJHwBlX9Q
eGv5TVZHcFUq2OSdYHm+JzBJ3J0qTzswN5rz0Z/Msc+B2+wWjzjYk7V07bh7UZ99AW4n
maw3W3FPXINT7jQqNPEZ59koEdlK+W8OYmnoTJR1o+sKdf9UUQvT6iE0giZzORTYWD3d
oKsAENrqzNIpYWX7tWwmP8fepC30kS8NlUUY6iz9WYH/uGiI5e0CZmpN/gxDci7PocJO
5jzw==
X-Forwarded-Encrypted: i=1;
AFNElJ/jtXeC8Gd//lYSWTA6bnbeT71Cq71G2lDZq5BqBb0nehXQYJskBFeLs5OrWBkzLclsW3imr4+MMd3sSQ==@lists.linux.dev
X-Gm-Message-State: AOJu0Yz5X7JnTndYzlclJVAJ2htx+hLcRq1rBgPOdN6YWxlX1cbIxYFS
YNV/9D6FfY1JMkFcjK1BJ7Fj83I1wgw7CH9AkjO4BceDz8n/ppKy+js=
X-Gm-Gg: Acq92OHoTQMO4mIxX/OhmKis+5c8AIWpu1hWS994CmDTQEggOHkrndvRZkTdzaPOPLC
7RDnrTP5HAHwoP7EX/Mb5zAZ8NSbew2lB9Tl/aM3DO320+qqe1o3uX0OR8ZAUBvDdvOxnDB+2uk
B/cLYknNSFaXV7eCIGbfdd7N7P4je3yGYXDdODKg80nT/Is+mW/n9gcd5RLF21kOy+dNgBtQmvy
kvrja5a4Qu2uSmX6+RTXrx/QgFSJTrRfB6/R7YaqZKUPYVLvyL0HPzwB8eMS3LkwjlCB0yHM5XB
ttKuDJIikWnGvvH44GSgNWu6HrCZmBzHJAgJMKj5+nrzeeImFdA2+tCkomjC08wUnPNMjjCHuJV
kaXmOX/hkf5BqC4EkHZlN696S/LqeE2AFzBb+yzwTgikuxkMzqZr+CR3o+6i6mlkK24xsRAXNDK
w7Pl6qyQz0nKsJi7h6CEu2R4xUr3gBXOPYPBMIAgiWaWhXfKhuPBAg6+ui/8bkVPVfltsbGsXO7
wYQhXi6Q4f8TPL0D6pVY6fxJfQssdOnTsFbgSU=
X-Received: by 2002:a17:903:1448:b0:2bd:2458:50d4 with SMTP id
d9443c01a7336-2bd27706be2mr20525425ad.41.1778656282606;
Wed, 13 May 2026 00:11:22 -0700 (PDT)
Received: from localhost.localdomain ([211.198.234.66])
by smtp.gmail.com with ESMTPSA id
d9443c01a7336-2baf1d405efsm165677855ad.23.2026.05.13.00.11.20
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Wed, 13 May 2026 00:11:22 -0700 (PDT)
From: " =?utf-8?b?67CV66qF7ZuI?= " <mhun512@gmail.com>
X-Google-Original-From: =?utf-8?b?67CV66qF7ZuI?=
<pakmyeonghun@bagmyeonghun-ui-MacBookPro.local>
To: Sean Young <sean@mess.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Myeonghun Pak <mhun512@gmail.com>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
linux-media@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev,
linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
Ijae Kim <ae878000@gmail.com>
Subject: [PATCH] media: rc: sunxi-cir: unregister rc device on probe failure
Date: Wed, 13 May 2026 16:11:03 +0900
Message-ID: <20260424000000.558-1-mhun512@gmail.com>
X-Mailer: git-send-email 2.47.1
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)[99.99%];
RBL_SENDERSCORE(2.00)[172.232.135.74: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)[12];
FREEMAIL_FROM(0.00)[gmail.com];
FUZZY_BLOCKED(0.00)[rspamd.com];
FORGED_SENDER_MAILLIST(0.00)[];
DBL_BLOCKED_OPENRESOLVER(0.00)[sto.lore.kernel.org:rdns,sto.lore.kernel.org:helo];
FREEMAIL_CC(0.00)[gmail.com,kernel.org,sholland.org,vger.kernel.org,lists.infradead.org,lists.linux.dev];
TO_DN_SOME(0.00)[];
R_SPF_ALLOW(0.00)[+ip4:172.232.135.74];
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:172.232.128.0/19, country:SG];
ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1];
TAGGED_FROM(0.00)[bounces-23324-noreply=patchwork.local];
RCVD_COUNT_FIVE(0.00)[6];
FROM_NEQ_ENVFROM(0.00)[mhun512@gmail.com,linux-sunxi@lists.linux.dev];
RCVD_VIA_SMTP_AUTH(0.00)[]
X-Rspamd-Queue-Id: 5BA051C053C
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 |
media: rc: sunxi-cir: unregister rc device on probe failure
|
|
Commit Message
박명훈
May 13, 2026, 7:11 a.m. UTC
From: Myeonghun Pak <mhun512@gmail.com> After rc_register_device() succeeds, later probe failures must undo the registration with rc_unregister_device(). The current error path jumps to the allocation cleanup label and only calls rc_free_device(), leaving the rc device registration and resources created by rc_register_device() behind. Add a registered-device unwind label for the IRQ lookup, IRQ request, and hardware initialization failure paths. Keep rc_free_device() for failures before rc_register_device() succeeds. Fixes: b4e3e59fb59c ("[media] rc: add sunxi-ir driver") Cc: stable@vger.kernel.org Co-developed-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Myeonghun Pak <mhun512@gmail.com> --- drivers/media/rc/sunxi-cir.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Comments
Dne sreda, 13. maj 2026 ob 09:11:03 Srednjeevropski poletni čas je 박명훈 napisal(a): > From: Myeonghun Pak <mhun512@gmail.com> > > After rc_register_device() succeeds, later probe failures must undo the > registration with rc_unregister_device(). The current error path jumps to > the allocation cleanup label and only calls rc_free_device(), leaving the > rc device registration and resources created by rc_register_device() > behind. > > Add a registered-device unwind label for the IRQ lookup, IRQ request, and > hardware initialization failure paths. Keep rc_free_device() for failures > before rc_register_device() succeeds. > > Fixes: b4e3e59fb59c ("[media] rc: add sunxi-ir driver") > Cc: stable@vger.kernel.org > Co-developed-by: Ijae Kim <ae878000@gmail.com> > Signed-off-by: Ijae Kim <ae878000@gmail.com> > Signed-off-by: Myeonghun Pak <mhun512@gmail.com> > --- > drivers/media/rc/sunxi-cir.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c > index 92ef4e7c6f..cc64a68dfe 100644 > --- a/drivers/media/rc/sunxi-cir.c > +++ b/drivers/media/rc/sunxi-cir.c > @@ -344,22 +344,26 @@ static int sunxi_ir_probe(struct platform_device *pdev) > ir->irq = platform_get_irq(pdev, 0); > if (ir->irq < 0) { > ret = ir->irq; > - goto exit_free_dev; > + goto exit_unregister_dev; > } > > ret = devm_request_irq(dev, ir->irq, sunxi_ir_irq, 0, SUNXI_IR_DEV, ir); > if (ret) { > dev_err(dev, "failed request irq\n"); > - goto exit_free_dev; > + goto exit_unregister_dev; > } > > ret = sunxi_ir_hw_init(dev); > if (ret) > - goto exit_free_dev; > + goto exit_unregister_dev; > > dev_info(dev, "initialized sunXi IR driver\n"); > return 0; > > +exit_unregister_dev: > + rc_unregister_device(ir->rc); > + return ret; This return should not be here. Device must be freed too. Best regards, Jernej > + > exit_free_dev: > rc_free_device(ir->rc); > >
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] The newly added error path leaks the `rc_dev` structure. - [High] Device registration and IRQ request occur before hardware clocks are enabled, creating a race condition that can panic the kernel. - [High] Mixing devm-managed IRQ with manual error path cleanup creates a Use-After-Free vulnerability. - [High] Unvalidated `clock-frequency` device tree property allows a divide-by-zero kernel panic. -- commit 230e9a371e882d2d3972a39ec6ca89c53afbeaf9 Author: Myeonghun Pak <mhun512@gmail.com> media: rc: sunxi-cir: unregister rc device on probe failure This commit updates the error handling in sunxi_ir_probe() to ensure the RC device is unregistered if a failure occurs after rc_register_device() succeeds. While reviewing this commit, I noticed a few potential issues, including some existing concerns in the probe function. > diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c > index cb4c56bf0752a..f40f3ea0ac8e5 100644 > --- a/drivers/media/rc/sunxi-cir.c > +++ b/drivers/media/rc/sunxi-cir.c > @@ -344,22 +344,26 @@ static int sunxi_ir_probe(struct platform_device *pdev) > ir->irq = platform_get_irq(pdev, 0); > if (ir->irq < 0) { > ret = ir->irq; > - goto exit_free_dev; > + goto exit_unregister_dev; > } > > ret = devm_request_irq(dev, ir->irq, sunxi_ir_irq, 0, SUNXI_IR_DEV, ir); > if (ret) { > dev_err(dev, "failed request irq\n"); > - goto exit_free_dev; > + goto exit_unregister_dev; > } > > ret = sunxi_ir_hw_init(dev); Is there a race condition since rc_register_device() and devm_request_irq() are called before sunxi_ir_hw_init() enables the hardware clocks? If an early interrupt fires, or if userspace interacts with the device via sysfs or lirc (like setting the timeout), could the driver attempt to read or write memory-mapped registers while the clocks are still disabled? Also, if sunxi_ir_hw_init() fails, the code jumps to exit_unregister_dev. Because the IRQ is managed by devm_request_irq(), it remains active until the probe function completely returns. If the interrupt fires concurrently while rc_unregister_device() is tearing down the device, could the handler access freed resources? > if (ret) > - goto exit_free_dev; > + goto exit_unregister_dev; > > dev_info(dev, "initialized sunXi IR driver\n"); > return 0; > > +exit_unregister_dev: > + rc_unregister_device(ir->rc); > + return ret; > + Does this error path leak the rc_dev structure? rc_allocate_device() initializes the structure with a reference count of 1. While rc_unregister_device() removes the device from the system, it does not drop this initial reference count. Would it be necessary to fall through or explicitly call rc_free_device() here to fully free the memory? > exit_free_dev: > rc_free_device(ir->rc); > Additionally, earlier in sunxi_ir_probe(), the driver reads the clock-frequency property and calculates the rx_resolution: drivers/media/rc/sunxi-cir.c:sunxi_ir_probe() { ... of_property_read_u32(dn, "clock-frequency", &b_clk_freq); ... ir->rc->rx_resolution = (USEC_PER_SEC / (b_clk_freq / 64)); ... } Could this cause a divide-by-zero issue? If the device tree specifies a clock frequency less than 64 (such as 0), b_clk_freq / 64 would evaluate to 0.
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c index 92ef4e7c6f..cc64a68dfe 100644 --- a/drivers/media/rc/sunxi-cir.c +++ b/drivers/media/rc/sunxi-cir.c @@ -344,22 +344,26 @@ static int sunxi_ir_probe(struct platform_device *pdev) ir->irq = platform_get_irq(pdev, 0); if (ir->irq < 0) { ret = ir->irq; - goto exit_free_dev; + goto exit_unregister_dev; } ret = devm_request_irq(dev, ir->irq, sunxi_ir_irq, 0, SUNXI_IR_DEV, ir); if (ret) { dev_err(dev, "failed request irq\n"); - goto exit_free_dev; + goto exit_unregister_dev; } ret = sunxi_ir_hw_init(dev); if (ret) - goto exit_free_dev; + goto exit_unregister_dev; dev_info(dev, "initialized sunXi IR driver\n"); return 0; +exit_unregister_dev: + rc_unregister_device(ir->rc); + return ret; + exit_free_dev: rc_free_device(ir->rc);