From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CFC65288C06 for ; Mon, 21 Jul 2025 08:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753086356; cv=none; b=HARJLNjrOpkuAKjL5jAhdAJEXsQEL3WQq9SYC/ASrke/dSS7QxYM9LP3dMnloUQYIFXhDGO1av31IA+QEfOZBR0v/vNaQhL3SKXL3KdAv3OrkduT2cOD7g7ry4YRPSgnsEnnQgLZdFt/CGDHRTxvErffo2C4g0T0lwr7TA42MKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753086356; c=relaxed/simple; bh=1xwau8tZQNCQ6zAdZiqQOjzdqF7mb5vqd77ulzdkHoE=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=IPXK3p7N3hDA7vp41G19mCyITRpvFqxjVQwHUsPJK7OePBezcYyCbYNhQHlW1cMCaJpc2Nj5rhEkjsuBuIJ1IDGZWdc7+Zuo82rcyHiCoEVEHUHJEqKlj9DwW6PEC2CeLe4f0tiKzrE/uCUDhF3KOCVotCPyZbcg1d+Exthej2g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JrmO9zqk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JrmO9zqk" 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.