Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2163752rwp; Fri, 14 Jul 2023 01:35:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlEabtuxRdbUi5yex6wPvU7n7YuvLQij6E4gNL8CWbIXdHjuAxM/INknBcdbpGbS7F1XLHVe X-Received: by 2002:a17:906:54:b0:993:f349:c989 with SMTP id 20-20020a170906005400b00993f349c989mr3171122ejg.7.1689323700776; Fri, 14 Jul 2023 01:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689323700; cv=none; d=google.com; s=arc-20160816; b=gwcWxKnwm+vR7oSe2ItsRZI8ov9KkvGsI9o0GKsueAlERrQPOBL55m1n2y1fyPpTxp b967pRwy0+fc4LovLv0+MHP6r8LS3V7DThrdJVhAgphWwOogfeEb6PB0GDEqFHr0I3/V 2hEO8oVQDKIdeN3xxFcJTd2+6Bk7A1tsxNCsidsnjvO/uYrWMlmbeCE4uq1by+4hcEf+ Yro5JH30qrk4B/kHuTmLpc/CFHE+fzoUyQsuGDeUzSp7j8mMVDogsff8yhEps+MGDJmF KyD1hvrOyDbLMvSecPdtZqpIEtkZg0Lfp2ltphYa7z2CdXCT8nW+50bnWL69oe2zdzBx AWGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=kDWNQqt9RcBYngpimpJ3lBn2yh5IYYQccowdH1kcXIs=; fh=0SrmjPlC8FkRWjK4e+bI18qwG1QDmr1ILiqWqju/vAw=; b=HkNLMJ424kaiMF2l4bEm7tG224tuygR3VnBqAgyl2wckjp2Id/LGd07JvzXuVoTpqu PJ+YR74qZSFLf3FQyIEsFpj1HbtYS2g6RLAPmQ0cxkVJsEbipnQmKWYIQ4sKPD420/Y2 kyB3rerlHtF0fcmX5eBT2lW0u3/ZwXu6AVlc5eGcvPFcB78cVwkRcWTcKFJ6zDmf7c02 IvvFau0jBU+wVF1DJ5DlCdDk2ME2RChlZJATEJYh9Yy6uaKf+4MiI216vXwzSJqKDUyk t6mQVd8bkYOIQDukxAyypct3/PvDXA4ITH/fdn9w4BNRYh11I/vjoPZMnl4Tayp1Pt9U WyjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MWwSI981; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a170906409000b00991b7749bd5si2327522ejj.779.2023.07.14.01.34.37; Fri, 14 Jul 2023 01:35:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MWwSI981; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235119AbjGNIJN (ORCPT + 99 others); Fri, 14 Jul 2023 04:09:13 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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.