From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C3EEC87FC5 for ; Mon, 21 Jul 2025 08:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=F2Ib1tKEF1yuS4FANf1IbHCg9VHWr9HAnvrBLZTSSnk=; b=f6svzB7U9oEj6Yj8T0bBhko5Mu JGWpbh2RBUp4jvXPdMDsFbGf88p91WS3JCBQEFHE+xeqatf9uU4OIbCNYa6h7aTcqA7LO01eWLtah nh4edmBx6TkLxrkv3o5KwaHMzF6G0t7f2R4GA7DTMLk9LcdaMeYaaFRQL3jhUShl3sa8i0VQJkIdD G0x8zDlD4olwUf4AA9L+n/S/MJe4j86So16OUYpc1cRxOdslOn+xFta2N4uurN5shwZa5Ig6YB6N8 8iJfpuQ5dC5+/UzQOKID1XXVvzadQNc610sbdFT2dUVkRCUJjWu/JAdSHqB2+HFiy6emAbooMrJWf L1CeY4Gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1udmCA-0000000GiPC-3QM6; Mon, 21 Jul 2025 08:48:26 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1udlqP-0000000Ge6t-1YY8 for linux-arm-kernel@lists.infradead.org; Mon, 21 Jul 2025 08:25:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id AF852A52862; Mon, 21 Jul 2025 08:25:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58622C4CEED; Mon, 21 Jul 2025 08:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753086356; bh=1xwau8tZQNCQ6zAdZiqQOjzdqF7mb5vqd77ulzdkHoE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JrmO9zqkBaTc4aRnCXRvZSInVD5DIWDpADJWNVSmAhZErhp1CfOa5yy5VyKdQ7PcE 3/57fV2WXUqvPoQ4s4d8SJZNOZ5YyimwH5G6J6y/8aCr+OB9bWn+Q3viRfAyyzBWLo XqQifRC+oy3RnGWKf4MsAZ7yC5Q74bOYXAZfmmbCYSCIlHsrYyMBkPSJMpHpVVN7VV QXgHY7z6oqLEGL8ygMjQhYPup8qY29ku9jbHW41mh0dxWGSPk3KwipFlLoO1sMxsp7 DCBDi9YVdDdUJClsTVXnypR20wKxgAXdkVch2BSBgxzvRL4wiR9HgOK7hAcjsJ/XHE ujwflBDUInqyg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1udlqM-00HXQo-27; Mon, 21 Jul 2025 09:25:54 +0100 Date: Mon, 21 Jul 2025 09:25:53 +0100 Message-ID: <86qzya7xwu.wl-maz@kernel.org> From: Marc Zyngier To: jackysliu <1972843537@qq.com> Cc: tglx@linutronix.de, herve.codina@bootlin.com, antonio.borneo@foss.st.com, anup@brainfault.org, jirislaby@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] irqchip/gic-v3: fix resource leak in partition_domain_translate() In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: 1972843537@qq.com, tglx@linutronix.de, herve.codina@bootlin.com, antonio.borneo@foss.st.com, anup@brainfault.org, jirislaby@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250721_012557_539085_173DECD3 X-CRM114-Status: GOOD ( 28.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 21 Jul 2025 08:28:04 +0100, jackysliu <1972843537@qq.com> wrote: > > There is a device node reference leak in partition_domain_translate(). > After the function obtains the device node np via of_find_node_by_phandle, > it does not call of_node_put(np) to release the node reference > in both the error path and the normal return path. > This causes the node reference count to increase each time > the function is called, causing a resource leak. > > This issue was detected by rule based static tools > developed by Tencent. > > Fixes: 87228532e7e9 ("irqchip: Switch to of_fwnode_handle()") > > Signed-off-by: jackysliu <1972843537@qq.com> Drop the spurious blank line. > --- > drivers/irqchip/irq-gic-v3.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c > index efc791c43d44..61c1d404b726 100644 > --- a/drivers/irqchip/irq-gic-v3.c > +++ b/drivers/irqchip/irq-gic-v3.c > @@ -1821,12 +1821,16 @@ static int partition_domain_translate(struct irq_domain *d, > return -EINVAL; > > ret = gic_irq_domain_translate(d, fwspec, &ppi_intid, type); > - if (WARN_ON_ONCE(ret)) > + if (WARN_ON_ONCE(ret)) { > + of_node_put(np); > return 0; > + } > > ppi_idx = __gic_get_ppi_index(ppi_intid); > ret = partition_translate_id(gic_data.ppi_descs[ppi_idx], > of_fwnode_handle(np)); > + of_node_put(np); > + > if (ret < 0) > return ret; > Frankly, this looks awful, and we have much better ways to solve this whole class of problems. Why can't the (untested) patch below do the right thing, without the ugliness? M. diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index efc791c43d441..c4839032ce8d0 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -1808,8 +1808,8 @@ static int partition_domain_translate(struct irq_domain *d, unsigned long *hwirq, unsigned int *type) { + struct device_node *np __free(device_node) = NULL; unsigned long ppi_intid; - struct device_node *np; unsigned int ppi_idx; int ret; -- Without deviation from the norm, progress is not possible.