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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB5D4C001DE for ; Fri, 14 Jul 2023 08:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235007AbjGNIJO (ORCPT ); Fri, 14 Jul 2023 04:09:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234942AbjGNIIr (ORCPT ); Fri, 14 Jul 2023 04:08:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBBBE46AC for ; Fri, 14 Jul 2023 01:06:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 78F5661C50 for ; Fri, 14 Jul 2023 08:06:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD84EC433C8; Fri, 14 Jul 2023 08:06:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689321985; bh=8fkv5Z3JDvK51lTR1yWQV4fSQJNMTls7B4SFTYDOZX4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MWwSI981GhhulKk6IfWArGkWpGleBKhJkY51q/UpyViAI5DtQrGP2cjBTLJUvR9X1 ksXy4VA9G1izcLDHoT20QYUkLWogqjz7cDEHOrQzqmd/bDPKefFku3aLiAVANB2sGh Litd2VHp/+trk0jDaBnv6AcSbaySwYDv9jUubS/8qXcXrOUaWgU1EJK7b654lRbGEO C6EVty2fw8AOfND5lMrRyCt0GDzCx6oZe9gg+u48BgCSh5+PcGxSUtP0rrrJtoMKSl lwMw8uy3oyKWa4NjBgmVZ2u9YGHl89bZMy1zKAM4QxFBP71OZhVQ2LU4MKyj5tLQEb KoXC734GWS6SA== 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 1qKDol-00D1q4-Po; Fri, 14 Jul 2023 09:06:23 +0100 Date: Fri, 14 Jul 2023 09:06:23 +0100 Message-ID: <86mszyvrwg.wl-maz@kernel.org> From: Marc Zyngier To: liubin001@208suo.com Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: Re: Fwd: [PATCH] irqchip:Use the "put_device" function to release the memory after calling the of_find_device_by_node function. In-Reply-To: <66d48e6ce0db4f89737172a2963195a9@208suo.com> References: <66d48e6ce0db4f89737172a2963195a9@208suo.com> 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/28.2 (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: liubin001@208suo.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, geert@linux-m68k.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please don't forward emails like this. If you've missed a recipient, repost it. +Geert for the Renesas stuff. On Fri, 14 Jul 2023 04:43:28 +0100, liubin001@208suo.com wrote: > > Write the put_device function before return Why? What is wrong with the current code? What does it affect? > > Signed-off-by: Liu Bin > --- > drivers/irqchip/irq-renesas-rzg2l.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-renesas-rzg2l.c > b/drivers/irqchip/irq-renesas-rzg2l.c > index 4bbfa2b0a4df..a9d75135ba24 100644 > --- a/drivers/irqchip/irq-renesas-rzg2l.c > +++ b/drivers/irqchip/irq-renesas-rzg2l.c > @@ -325,35 +325,42 @@ static int rzg2l_irqc_init(struct device_node > *node, struct device_node *parent) > > pdev = of_find_device_by_node(node); > if (!pdev) > + put_device(pdev); > return -ENODEV; > > parent_domain = irq_find_host(parent); > if (!parent_domain) { > dev_err(&pdev->dev, "cannot find parent domain\n"); > + put_device(pdev); > return -ENODEV; > } > > priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > if (!priv) > + put_device(pdev); > return -ENOMEM; > > priv->base = devm_of_iomap(&pdev->dev, pdev->dev.of_node, 0, NULL); > if (IS_ERR(priv->base)) > + put_device(pdev); > return PTR_ERR(priv->base); > > ret = rzg2l_irqc_parse_interrupts(priv, node); > if (ret) { > dev_err(&pdev->dev, "cannot parse interrupts: %d\n", ret); > + put_device(pdev); > return ret; > } > > resetn = devm_reset_control_get_exclusive(&pdev->dev, NULL); > if (IS_ERR(resetn)) > + put_device(pdev); > return PTR_ERR(resetn); > > ret = reset_control_deassert(resetn); > if (ret) { > dev_err(&pdev->dev, "failed to deassert resetn pin, %d\n", > ret); > + put_device(pdev); > return ret; > } > > @@ -374,7 +381,7 @@ static int rzg2l_irqc_init(struct device_node > *node, struct device_node *parent) > ret = -ENOMEM; > goto pm_put; > } > - > + put_device(pdev); > return 0; > > pm_put: > @@ -382,6 +389,7 @@ static int rzg2l_irqc_init(struct device_node > *node, struct device_node *parent) > pm_disable: > pm_runtime_disable(&pdev->dev); > reset_control_assert(resetn); > + put_device(pdev); > return ret; > } Can't you spot an easy way to make the whole thing more readable and less error prone? Such as having a *single* exit point to the function, doing the put_device() and returning the error code? M. -- Without deviation from the norm, progress is not possible.