| Message ID | 20260902200703.2016410-1-mukesh.ojha@oss.qualcomm.com (mailing list archive) |
|---|---|
| Headers |
Return-Path: <linux-sunxi+bounces-25505-sunxi=pue.re@lists.linux.dev>
X-Original-To: noreply@patchwork.local
Delivered-To: noreply@patchwork.local
Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mxe881.netcup.net (Postfix) with ESMTPS id 22CF71C1D7D
for <noreply@patchwork.local>; Wed, 2 Sep 2026 22:19:51 +0200 (CEST)
Authentication-Results: mxe881;
dkim=pass header.d=qualcomm.com;
dkim=pass header.d=oss.qualcomm.com;
spf=pass (sender IP is 172.234.253.10)
smtp.mailfrom=linux-sunxi+bounces-25505-noreply=patchwork.local@lists.linux.dev
smtp.helo=sea.lore.kernel.org
Received-SPF: pass (mxe881: domain of lists.linux.dev designates
172.234.253.10 as permitted sender) client-ip=172.234.253.10;
envelope-from=linux-sunxi+bounces-25505-noreply=patchwork.local@lists.linux.dev;
helo=sea.lore.kernel.org;
Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org
[100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 09D52C672F
for <noreply@patchwork.local>; Wed, 2 Sep 2026 20:07:48 +0000 (UTC)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BE7A3E3DA6;
Wed, 2 Sep 2026 20:07:27 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com
header.b="o8qTZHJ9";
dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com
header.b="Dyg9UUqa"
X-Original-To: linux-sunxi@lists.linux.dev
Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com
[205.220.180.131])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1C66330D4C
for <linux-sunxi@lists.linux.dev>; Wed, 2 Sep 2026 20:07:25 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=none smtp.client-ip=205.220.180.131
ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1788379647; cv=none;
b=Vnxic3BWYmE7hoI16jedoo7D9rvVJko0XfWQ2kOjTF3KnpClfzF5AoQAai0jc/k7kngu/6RtxT3dSB4AbnxfnbddIl40uzgD+6o2GYCqkXiao7Wgo/eedasLcCVZMUGGNDsQBlEkMw88xhxyTSaZNDVcQTkcJxObOE60kM7fXTg=
ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1788379647; c=relaxed/simple;
bh=+JRsAXUkPd/zCxfFhAsZWhnWtV5dxWny5nzrwbSSkXo=;
h=From:To:Cc:Subject:Date:Message-ID:MIME-Version;
b=UZSDb9DLyB9ZFwBEbVI3cBaR1PFVuWBwW6dQ5opelKfqsFaVksJjSk0JbqThGsICImNjDoWBXN6x4Goync/eNP83SNpFZ+IOm6smsT1p+uT9pB5gPVut/WYGmL1HpzYNHwAb+UmvnCaA1SPzfhvnK3GoDg1TA8ZY/0iCcmGrnyI=
ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com;
spf=pass smtp.mailfrom=oss.qualcomm.com;
dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com
header.b=o8qTZHJ9;
dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com
header.b=Dyg9UUqa; arc=none smtp.client-ip=205.220.180.131
Authentication-Results: smtp.subspace.kernel.org;
dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com
Authentication-Results: smtp.subspace.kernel.org;
spf=pass smtp.mailfrom=oss.qualcomm.com
Received: from pps.filterd (m0279869.ppops.net [127.0.0.1])
by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id
682HsPxv2485892
for <linux-sunxi@lists.linux.dev>; Wed, 2 Sep 2026 20:07:24 GMT
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=
cc:content-transfer-encoding:date:from:message-id:mime-version
:subject:to; s=qcppdkim1; bh=EoRunoHQ0ZfKUnR/gnkdF5veRCY4NTnXOgl
gLUq3iAA=; b=o8qTZHJ9wPF3L6nko83fbw4RSA3+laqGNZFT6uDbpl+YVhbI4Bh
AiRHxzRb6pGr6xp1CtxCYePGu78jL9tipjO+GqINkNKz9aKmqQETyzIoUWGhomIb
iHj2NQn7DXHMQGBwbiTG3w8x6S+gXIGWDSIGmvst6TY1qfC9HSx2tamypr9XuoZ4
uxtI+2HSG/JmVkElTyVouC3zK8UcSsL79XGYNVGgsHptK9GY2nADRzhKHoajUrxa
+OkIh/NIGe1kQa57LP0JOI/jkm6d3OdjCGYpl6KGAT0xozaNsl2RXZKAkvZlr6Op
jeOzEpXx21MYBqscJHxbUbwqhNyliYP0sag==
Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com
[209.85.216.72])
by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4gemjh9p6e-1
(version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)
for <linux-sunxi@lists.linux.dev>; Wed, 02 Sep 2026 20:07:24 +0000 (GMT)
Received: by mail-pj1-f72.google.com with SMTP id
98e67ed59e1d1-3823dcc1647so1951903a91.3
for <linux-sunxi@lists.linux.dev>;
Wed, 02 Sep 2026 13:07:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=oss.qualcomm.com; s=google; t=1788379643; x=1788984443;
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:content-type;
bh=EoRunoHQ0ZfKUnR/gnkdF5veRCY4NTnXOglgLUq3iAA=;
b=Dyg9UUqaaPjIUta4M9/FGNg/RSIiRE/aTC7fIne2hzpn281DLafzc8h1ADpOi+JhWx
K9ArAue1114A5igHI1fvfQGOUGegKDXU0z9N9RmdUkdHlvQYcwrt86rWvrxpWFEz3j+2
xCZx4KWPqnA0plLfcTEYpfr7z/oRuYXwHCciH06Vfe/80VhUcfIIFXFnaF2xBZ2arSEN
+mMfj6GReYWeU/NDKtZU1FLEIWOr0XPix5vYF4ekWQsds/ZRFL48l7UFEOkoZdPi09VG
VthGibORae0xNCa6/i03/j0oD69sL7RoD0lOTB20AzVaCnhFMrqMUlUTfGq+tGhJ+HXO
/XDg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20251104; t=1788379643; x=1788984443;
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:content-type;
bh=EoRunoHQ0ZfKUnR/gnkdF5veRCY4NTnXOglgLUq3iAA=;
b=qv09wLONbSjfE3hAOoPGcE46KXtPGPz4uiWRHjYO0DVL4xCldca+3YVbshWE0kh41F
cwCP50zGlD3qKvXeCtKnQdqv7UCWvqyEJr5Dt1ZXgtycFhosROWjPq5bPjDtwlWrQ66j
kJk0Uhv3o8y9KlXRMMfVYX5O2D3hP2w9JDL8TbCVWOFnOUu2udaBqKTuGIhwb642kHD8
yDdcveZKBcHnPdGbsHkJ/QgUCiOHSfFN/tNq40In1v84ge/ma9e5WYj5OPdBbaX/cmC0
QrLaNfMoVPNFpm31K/1PgE28NxBZDBnPBm5NKZDMULO5sua/m4v093j7xtE4pGQWNRwM
R4pw==
X-Forwarded-Encrypted: i=1;
AKwUvByiihlsInos1sh8Kfliehgzo87vGdoOc+aQYhdqG2IYs72hlDLhx9g/428QkWsl1Mt3JKensEji1c/k8g==@lists.linux.dev
X-Gm-Message-State: AFuF++lfpEBHPAcCTFvs139b0TBZr9qqZT31PBC4M/wIPUhOkvhOPr7h
BceX4D9D7xVyDPY2pN0GIEpUeABECSIB/g2AiJ2/znoa7KB8PsrUTQa9MbyH9dbHsAtdPwvkY92
L7JdKISiAq7QiDlUEEa9jZ86o7l0QMsZjYweq0vzBWRUv68dCEgz21Mfc0cijrlGHqw==
X-Gm-Gg: AYBFou0SJSJyig9K977MaqX96al6f2REndNRxCdh5MUljgPjino7/A1AJxUGtPo1jMt
Bn+xzB6nCKuUlLAOMAfTKkPLl4zVciQ2X3EfC/6bmBlZSxWblPsBmCvv7mo/rU6iaN3mednF7st
nFIMLMIyxVZdRxHGqLoXpcyJTi/p7BMSdPoqIqJboU2TnlVFYkHxwczk2kWQZzI744aRTLVJ0Q3
8u3iqJro+etV7y7t6tFxLw/FVJ2cGPr/Iyvf/snHuTVWpOSZhaP5uCG3Ayg42gPm36q4RcInI9b
saxFELd4lFwfITQxh8WPPjnGbaP60sQnhLBMkjWXoTrIODbC9TJiDEVDcTZpXkqW0M7aZFoTpwY
2E7Bh+0Q9wKRInkhUZnWFGxa8PEc=
X-Received: by 2002:a17:90a:cf88:b0:38e:fea2:df53 with SMTP id
98e67ed59e1d1-39aee9b4d19mr8604313a91.4.1788379643365;
Wed, 02 Sep 2026 13:07:23 -0700 (PDT)
X-Received: by 2002:a17:90a:cf88:b0:38e:fea2:df53 with SMTP id
98e67ed59e1d1-39aee9b4d19mr8604229a91.4.1788379642783;
Wed, 02 Sep 2026 13:07:22 -0700 (PDT)
Received: from hu-mojha-hyd.qualcomm.com ([202.46.23.25])
by smtp.gmail.com with ESMTPSA id
5a478bee46e88-33255f2981dsm434360eec.19.2026.09.02.13.07.13
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 02 Sep 2026 13:07:22 -0700 (PDT)
From: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
To: Daniel Scally <dan.scally@ideasonboard.com>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Eddie James <eajames@linux.ibm.com>, Joel Stanley <joel@jms.id.au>,
Andrew Jeffery <andrew@codeconstruct.com.au>,
Minghsiu Tsai <minghsiu.tsai@mediatek.com>,
Houlong Wei <houlong.wei@mediatek.com>,
Andrew-CT Chen <andrew-ct.chen@mediatek.com>,
Tiffany Lin <tiffany.lin@mediatek.com>,
Yunfei Dong <yunfei.dong@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>,
Joseph Liu <kwliu@nuvoton.com>, Marvin Lin <kflin@nuvoton.com>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
Maxime Ripard <mripard@kernel.org>,
Paul Kocialkowski <paulk@sys-base.io>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>
Cc: Ryan Chen <ryan_chen@aspeedtech.com>,
Billy Tsai <billy_tsai@aspeedtech.com>, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org,
linux-mediatek@lists.infradead.org, kernel@collabora.com,
linux-staging@lists.linux.dev, linux-sunxi@lists.linux.dev,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Subject: [PATCH v2 0/6] media: Use devm_of_reserved_mem_device_init()
Date: Thu, 3 Sep 2026 01:36:57 +0530
Message-ID: <20260902200703.2016410-1-mukesh.ojha@oss.qualcomm.com>
X-Mailer: git-send-email 2.55.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-Proofpoint-GUID: 97OpdADkYOaYzt4kM7g6ld5jV6UeePlX
X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTAyMDE3OCBTYWx0ZWRfX2grhiFEKLDyV
e1g/BQ2dhQUYCdnFwKHvRoB3o8NUPqeewJ4a/Sr3lWtn33fM61oaeLBhRqKyRnlBmKg7yxjPmsy
Bq0cjwRyEBJG5Sryc4Kxuktkr+OReFuhI68Iubc0FpK4GZtxfXh/Ae+gQMESPtsQnuDQhAXtNQm
X4qPSSu/7Px+Gd/sQJLYuQDydriXBM5rGLQGxYtC6Cdn6M4ZB0lGLWKrtTneXBY5rUkXtBk1S4n
7x1JlnTKNr3lauilZS0Y8sL3ko1YJwaMMk9ARIbqORi8QlBpwMPtbBsjBpXmh2ZxPKd53V6nuU+
lBpsmpVNfJl3WmhC3am9x6v0FYwCxMbRw9lx7bNV7tjjRNpRHJlZ+BZGwTJ3tvzf7UwRBSG8Xdh
a4RqCG8ANBPV35tYyVI0ce/Jiq3eCj8DmyEpjRbMTaFKPpBekw6mEEnu2QSPnhF4hYoV16DBfxH
Dw+kW13FxpUx/2fiKzA==
X-Proofpoint-Spam-Info: AW1haW4tMjYwOTAyMDE3OCBTYWx0ZWRfXwJzz5CgGDQCS
bJ99koSC0iOxCX9WDIavgRZBPDAEN/upT+BBJSMKPolPIFPlkjpYvg682RLe1tmBCCgiFsk4oIy
Rt9Dy/cdvLdnsJ+ZpaC8tJ5zYoyRoDU=
X-Authority-Analysis: v=2.4 cv=ErHiaycA c=1 sm=1 tr=0 ts=6a9881fc cx=c_pps
a=RP+M6JBNLl+fLTcSJhASfg==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17
a=VdqzKS8jKosA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22
a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=VwQbUJbxAAAA:8
a=EUspDBNiAAAA:8 a=5ojLyFQZJBwMi_iZTBgA:9 a=iS9zxrgQBfv6-_F4QbHw:22
X-Proofpoint-ORIG-GUID: 97OpdADkYOaYzt4kM7g6ld5jV6UeePlX
X-Proofpoint-Virus-Version: vendor=baseguard
engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49
definitions=2026-09-02_04,2026-09-02_04,2025-10-01_01
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
phishscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0
impostorscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0
clxscore=1011 classifier=typeunknown authscore=0 authtc= authcc=
route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000
definitions=main-2609020178
X-Rspamd-Server: rspamd-worker-8404
X-Spamd-Result: default: False [4.84 / 15.00];
RBL_SENDERSCORE(2.00)[172.234.253.10:from];
SUSPICIOUS_RECIPS(1.50)[];
MID_CONTAINS_FROM(1.00)[];
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)[];
FROM_HAS_DN(0.00)[];
R_DKIM_ALLOW(0.00)[qualcomm.com:s=qcppdkim1];
PRECEDENCE_BULK(0.00)[];
TAGGED_RCPT(0.00)[];
RCVD_VIA_SMTP_AUTH(0.00)[];
DBL_BLOCKED_OPENRESOLVER(0.00)[qualcomm.com:dkim,sea.lore.kernel.org:rdns,sea.lore.kernel.org:helo];
RCPT_COUNT_TWELVE(0.00)[34];
RCVD_COUNT_SEVEN(0.00)[8];
FROM_NEQ_ENVFROM(0.00)[mukesh.ojha@oss.qualcomm.com,linux-sunxi@lists.linux.dev];
ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1];
ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG];
TO_DN_SOME(0.00)[];
R_SPF_ALLOW(0.00)[+ip4:172.234.253.10];
RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[205.220.180.131:received,202.46.23.25:received,209.85.216.72:received,100.90.174.1:received];
FORGED_SENDER_MAILLIST(0.00)[];
TAGGED_FROM(0.00)[bounces-25505-noreply=patchwork.local];
DKIM_TRACE(0.00)[qualcomm.com:+];
FREEMAIL_TO(0.00)[ideasonboard.com,kernel.org,linux.ibm.com,jms.id.au,codeconstruct.com.au,mediatek.com,gmail.com,collabora.com,nuvoton.com,sys-base.io,linuxfoundation.org,sholland.org];
RCVD_TLS_LAST(0.00)[];
DMARC_POLICY_ALLOW(0.00)[qualcomm.com,reject];
MIME_TRACE(0.00)[0:+];
FORGED_RECIPIENTS_MAILLIST(0.00)[];
RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]
X-Rspamd-Queue-Id: 22CF71C1D7D
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: Use devm_of_reserved_mem_device_init()
|
|
Message
Mukesh Ojha
Sept. 2, 2026, 8:06 p.m. UTC
Several media drivers manually manage reserved memory lifetime by calling of_reserved_mem_device_init() in probe and of_reserved_mem_device_release() in remove. Drivers that fail to release on every error path between the two calls leak the reserved memory region until the driver is unloaded. devm_of_reserved_mem_device_init() was recently introduced to tie the release to the device's devres lifetime automatically. Convert the affected media drivers to use it, removing the manual release calls and any wrapper devres actions. Changes since v1: https://lore.kernel.org/lkml/20260703193855.110619-2-mukesh.ojha@oss.qualcomm.com/ - Carried R-b tag if any. - Rebased it. Mukesh Ojha (6): media: synopsys: hdmirx: Use devm_of_reserved_mem_device_init() media: aspeed: Use devm_of_reserved_mem_device_init() media: nuvoton: npcm-video: Use devm_of_reserved_mem_device_init() media: arm: mali-c55: Use devm_of_reserved_mem_device_init() media: mediatek: vpu: Use devm_of_reserved_mem_device_init() staging: media: cedrus: Use devm_of_reserved_mem_device_init() .../media/platform/arm/mali-c55/mali-c55-core.c | 12 +++--------- drivers/media/platform/aspeed/aspeed-video.c | 12 ++++-------- drivers/media/platform/mediatek/vpu/mtk_vpu.c | 3 +-- drivers/media/platform/nuvoton/npcm-video.c | 9 ++------- .../media/platform/synopsys/hdmirx/snps_hdmirx.c | 16 ++-------------- drivers/staging/media/sunxi/cedrus/cedrus_hw.c | 9 ++------- 6 files changed, 14 insertions(+), 47 deletions(-)
Comments
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: Pre-existing issues: - [High] Potential use-after-free of the driver's private `video` structure in the interrupt handler due to devres lifecycle mismatch. - [High] V4L2 lifecycle mismatch causes a use-after-free of the embedded `video_device` structure. - [High] Device-managed allocations are incorrectly attached to an external child device, causing memory leaks and preventing reprobing. -- commit 5d2eb460720d228622a94970ff2802d5f5591843 Author: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com> media: nuvoton: npcm-video: Use devm_of_reserved_mem_device_init() Switch to devm_of_reserved_mem_device_init() so the reserved memory region is released automatically on probe failure or device removal. Remove the four explicit of_reserved_mem_device_release() calls and collapse the now-empty err_release_mem label into err_free. > diff --git a/drivers/media/platform/nuvoton/npcm-video.c b/drivers/media/platform/nuvoton/npcm-video.c > index 52505af35c087..6786736c8f07c 100644 > --- a/drivers/media/platform/nuvoton/npcm-video.c > +++ b/drivers/media/platform/nuvoton/npcm-video.c > @@ -1715,17 +1715,15 @@ static int npcm_video_init(struct npcm_video *video) > return rc; > } > > - of_reserved_mem_device_init(dev); > + devm_of_reserved_mem_device_init(dev); > rc = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); > if (rc) { > dev_err(dev, "Failed to set DMA mask\n"); > - of_reserved_mem_device_release(dev); > return rc; > } > > rc = npcm_video_ece_init(video); [Severity: High] This is a pre-existing issue, but could this leak resources when the npcm-video driver is unloaded? In npcm_video_ece_init() in drivers/media/platform/nuvoton/npcm-video.c, the driver fetches the external device node ece_pdev and uses its device pointer for devres allocations: regs = devm_platform_ioremap_resource(ece_pdev, 0); ... video->ece.reset = devm_reset_control_get(ece_dev, NULL); Since these allocations are tied to the external nuvoton,ece device's lifecycle rather than the driver's device, the resources won't be released when the npcm-video driver unbinds. If the driver is re-probed, could the ioremap request fail with -EBUSY and permanently break the driver? > if (rc) { > - of_reserved_mem_device_release(dev); > dev_err(dev, "Failed to initialize ECE\n"); > return rc; > } [ ... ] > @@ -1789,13 +1787,11 @@ static int npcm_video_probe(struct platform_device *pdev) > > rc = npcm_video_setup_video(video); > if (rc) > - goto err_release_mem; > + goto err_free; > > dev_info(video->dev, "NPCM video driver probed\n"); > return 0; > > -err_release_mem: > - of_reserved_mem_device_release(&pdev->dev); > err_free: > kfree(video); [Severity: High] This is a pre-existing issue, but can this cause a use-after-free of the driver's private video structure in the interrupt handler? If npcm_video_probe() in drivers/media/platform/nuvoton/npcm-video.c fails here, the driver manually calls kfree(video). However, earlier in npcm_video_init(), the interrupt was registered using devm_request_threaded_irq(). Because devres cleanup happens after the probe function returns, the IRQ remains registered and capable of firing while the video structure has already been freed. If an interrupt fires during this window, won't the handler execute and access the freed structure? > return rc; > @@ -1814,7 +1810,6 @@ static void npcm_video_remove(struct platform_device *pdev) > if (video->ece.enable) > npcm_video_ece_stop(video); > kfree(video); [Severity: High] This is a pre-existing issue, but can this kfree() also trigger a use-after-free due to the devm-managed IRQ lifecycle, similar to the probe error path? In npcm_video_remove() in drivers/media/platform/nuvoton/npcm-video.c, the devres cleanup won't disable the interrupt until after the remove function finishes. This leaves a window where the IRQ can fire and access the freed video structure. [Severity: High] This isn't a bug introduced by this patch, but can this cause a use-after-free if userspace still has the V4L2 device open? In npcm_video_setup_video() in drivers/media/platform/nuvoton/npcm-video.c, the driver embeds struct video_device inside its dynamically allocated struct npcm_video and sets its .release callback to video_device_release_empty. Since video_unregister_device() in npcm_video_remove() does not wait for file descriptors to be closed, could subsequent userspace operations access the embedded vdev after this kfree() has freed the enclosing structure? > - of_reserved_mem_device_release(dev); > }
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: Pre-existing issues: - [High] Pre-existing race condition leading to a use-after-free. The driver uses `devm_request_irq()` to manage its interrupt, but manually destroys the workqueue (`vpu->wdt.wq`) in `mtk_vpu_remove()`. Because devres cleans up the IRQ only after `remove()` completes, the interrupt remains active while the workqueue is freed. -- commit 246438dea9de2810275787060608206f1c3a4872 Author: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com> media: mediatek: vpu: Use devm_of_reserved_mem_device_init() This patch simplifies the driver by replacing manual of_reserved_mem_device_init() and of_reserved_mem_device_release() calls with the managed devm_of_reserved_mem_device_init() equivalent. > diff --git a/drivers/media/platform/mediatek/vpu/mtk_vpu.c b/drivers/media/platform/mediatek/vpu/mtk_vpu.c > --- a/drivers/media/platform/mediatek/vpu/mtk_vpu.c > +++ b/drivers/media/platform/mediatek/vpu/mtk_vpu.c [ ... ] > @@ -930,7 +930,6 @@ static int mtk_vpu_probe(struct platform_device *pdev) > free_d_mem: > vpu_free_ext_mem(vpu, D_FW); > remove_debugfs: > - of_reserved_mem_device_release(dev); [Severity: High] This is a pre-existing issue, but while reviewing this devres conversion, I noticed a potential use-after-free race condition related to device teardown. In mtk_vpu_probe(), the interrupt is registered as managed using devm_request_irq(), meaning it will remain active until devres cleanup runs after mtk_vpu_remove() completes. However, the workqueue is manually destroyed during mtk_vpu_remove(): drivers/media/platform/mediatek/vpu/mtk_vpu.c:mtk_vpu_remove() { ... if (vpu->wdt.wq) destroy_workqueue(vpu->wdt.wq); ... } If a hardware interrupt fires after destroy_workqueue() executes but before the devres cleanup disables the IRQ, vpu_irq_handler() will attempt to access the freed workqueue structure: drivers/media/platform/mediatek/vpu/mtk_vpu.c:vpu_irq_handler() { ... queue_work(vpu->wdt.wq, &vpu->wdt.ws); ... } Can this sequence cause a use-after-free if the hardware triggers an interrupt late during the unbind process?
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: Pre-existing issues: - [High] Race condition between runtime PM autosuspend and manual power-off during device removal and probe error paths. - [High] The IRQ handler is never freed if the device is removed while in the active runtime PM state. - [High] Media nodes are registered and exposed to userspace before the device's IRQ is requested, breaking initial video capture. -- commit c75be1887c52469e855778c08a0a6679f1af97b0 Author: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com> media: arm: mali-c55: Use devm_of_reserved_mem_device_init() This commit refactors the driver to use the devres-managed devm_of_reserved_mem_device_init() instead of manual initialization and cleanup. > diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-core.c b/drivers/media/platform/arm/mali-c55/mali-c55-core.c > index f28e9f4354aca..3d37cd4465838 100644 > --- a/drivers/media/platform/arm/mali-c55/mali-c55-core.c > +++ b/drivers/media/platform/arm/mali-c55/mali-c55-core.c > @@ -803,14 +803,12 @@ static int mali_c55_probe(struct platform_device *pdev) > if (ret) > return dev_err_probe(dev, ret, "failed to acquire resets\n"); > > - of_reserved_mem_device_init(dev); > + devm_of_reserved_mem_device_init(dev); > vb2_dma_contig_set_max_seg_size(dev, UINT_MAX); > > ret = __mali_c55_power_on(mali_c55); [Severity: High] This is a pre-existing issue, but are the media nodes registered and exposed to userspace before the device's IRQ is requested? Later in mali_c55_probe(): ret = mali_c55_media_frameworks_init(mali_c55); if (ret) goto err_pm_runtime_disable; pm_runtime_idle(&pdev->dev); mali_c55->irqnum = platform_get_irq(pdev, 0); The device is explicitly set to RPM_ACTIVE during probe, but the IRQ handler is only requested inside mali_c55_runtime_resume(). If userspace opens the device and begins streaming before the autosuspend delay forces a suspend cycle, the device will process frames without an IRQ handler. Will this cause video streaming to hang indefinitely because the capture buffers are never completed? > - if (ret) { > - dev_err_probe(dev, ret, "failed to power on\n"); > - goto err_release_mem; > - } > + if (ret) > + return dev_err_probe(dev, ret, "failed to power on\n"); > > ret = mali_c55_check_hwcfg(mali_c55); > if (ret) [ ... ] > @@ -849,9 +847,6 @@ static int mali_c55_probe(struct platform_device *pdev) > kfree(mali_c55->context.registers); > err_power_off: > __mali_c55_power_off(mali_c55); [Severity: High] This is a pre-existing issue, but is there a risk of a double power-off here if the device successfully auto-suspended before pm_runtime_disable() is called? If the autosuspend timer triggered, calling __mali_c55_power_off() again could lead to imbalanced clock disables (calling clk_bulk_disable_unprepare() without a matching enable) and reset assertions, potentially causing kernel warnings in the clock and reset cores. > -err_release_mem: > - of_reserved_mem_device_release(dev); > - > return ret; > } > > @@ -866,7 +861,6 @@ static void mali_c55_remove(struct platform_device *pdev) > } [Severity: High] This is a pre-existing issue, but does this manual power-off in mali_c55_remove() create a race window with concurrent autosuspend? In mali_c55_remove(), if the device is not suspended: if (!pm_runtime_suspended(&pdev->dev)) { __mali_c55_power_off(mali_c55); pm_runtime_set_suspended(&pdev->dev); } Because pm_runtime_disable() is called after this check, an asynchronous autosuspend could execute concurrently. Could this result in both threads calling __mali_c55_power_off() at the same time? [Severity: High] This is a pre-existing issue, but is it possible that bypassing the runtime suspend callback here causes an IRQ resource leak? The driver dynamically registers its IRQ handler in mali_c55_runtime_resume() and frees it in mali_c55_runtime_suspend(). If the device is active during removal, open-coding the power-off with __mali_c55_power_off() bypasses the free_irq() call. Could a subsequent interrupt on this line (or shared IRQ) trigger the handler and cause a use-after-free when accessing the freed device context? > pm_runtime_disable(&pdev->dev); > kfree(mali_c55->context.registers); > - of_reserved_mem_device_release(&pdev->dev); > }