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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 7D03AC433EF for ; Fri, 17 Jun 2022 04:30:02 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LPR0S6z8Fz3ch8 for ; Fri, 17 Jun 2022 14:30:00 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=EQKkqpQ2; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4LPQzP6nx5z3btp for ; Fri, 17 Jun 2022 14:29:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=EQKkqpQ2; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4LPQzM4nZmz4xYY; Fri, 17 Jun 2022 14:29:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1655440145; bh=lP6N1TsPiYTYOxkSYd2WUCrvJTyVTHU9T746fkYXgbE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=EQKkqpQ2DaafVrQ3kwoNK9C0ey0d8exJsQ2v9MjkKl5n8y8PFnAgMViqN6othvPKE 27RmgCbkGmwpicXuqQeysgkEBK89K6aupDRabOyNQVGwenQxiFTfdFcSGCt63Hqk8e IGlNRtuXLI/sUvTwlSX1uy+/HBMt/xtuUyS+C0aYlx5iJZf9Xyvnmgv2eBIweFKzMT I9um+KVNa/13qXITXudfeI5qcdsb7l96WV5w0ajNN5W2dMJHH7qb3XEIQ2ZajBCavk gi9N9nwjhUWUc+nJJHIb1MLWdPiuJEv9eCnJNOvKuLyrLbtURxCRYJtvau3Rd4T03q ecIaHufYn51Tw== From: Michael Ellerman To: Liang He Subject: Re:Re: [PATCH v2] arch: powerpc: platforms: 85xx: Add missing of_node_put in sgy_cts1000.c In-Reply-To: <6af17369.1d3d.1816f7a9707.Coremail.windhl@126.com> References: <20220616151901.3989078-1-windhl@126.com> <87o7ysb2ot.fsf@mpe.ellerman.id.au> <6af17369.1d3d.1816f7a9707.Coremail.windhl@126.com> Date: Fri, 17 Jun 2022 14:29:02 +1000 Message-ID: <87ilozc3qp.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nixiaoming@huawei.com, linux-kernel@vger.kernel.org, oss@buserror.net, paulus@samba.org, Christophe JAILLET , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" "Liang He" writes: > At 2022-06-17 07:37:06, "Michael Ellerman" wrote: >>Christophe JAILLET writes: >>> Le 16/06/2022 =C3=A0 17:19, Liang He a =C3=A9crit=C2=A0: >>>> In gpio_halt_probe(), of_find_matching_node() will return a node point= er with >>>> refcount incremented. We should use of_node_put() in each fail path or= when it >>>> is not used anymore. >>>>=20 >>>> Signed-off-by: Liang He >>>> --- >>>> changelog: >>>>=20 >>>> v2: use goto-label patch style advised by Christophe. >>>> v1: add of_node_put() before each exit. >>>>=20 >>>> arch/powerpc/platforms/85xx/sgy_cts1000.c | 27 +++++++++++++++------= -- >>>> 1 file changed, 18 insertions(+), 9 deletions(-) >>>>=20 >>>> diff --git a/arch/powerpc/platforms/85xx/sgy_cts1000.c b/arch/powerpc/= platforms/85xx/sgy_cts1000.c >>>> index 98ae64075193..e280f963d88c 100644 >>>> --- a/arch/powerpc/platforms/85xx/sgy_cts1000.c >>>> +++ b/arch/powerpc/platforms/85xx/sgy_cts1000.c >>>> @@ -73,6 +73,7 @@ static int gpio_halt_probe(struct platform_device *p= dev) >>... >>>> @@ -122,8 +127,12 @@ static int gpio_halt_probe(struct platform_device= *pdev) >>>>=20=20=20 >>>> printk(KERN_INFO "gpio-halt: registered GPIO %d (%d trigger, %d" >>>> " irq).\n", gpio, trigger, irq); >>>> + ret =3D 0; >>>>=20=20=20 >>>> - return 0; >>>> +err_put: >>>> + of_node_put(halt_node); >>>> + halt_node =3D NULL; >>> >>> Hi, >>> so now we set 'halt_node' to NULL even in the normal case. >>> This is really spurious. >>> >>> Look at gpio_halt_cb(), but I think that this is just wrong and badly=20 >>> breaks this driver. >> >>I agree, thanks for reviewing. >> >>I think the cleanest solution is to use a local variable for the node in >>the body of gpio_halt_probe(), and only assign to halt_node once all the >>checks have passed. >> >>So something like: >> >> struct device_node *child_node; >> >> child_node =3D of_find_matching_node(node, child_match); >> ... >> >> printk(KERN_INFO "gpio-halt: registered GPIO %d (%d trigger, %d" >> " irq).\n", gpio, trigger, irq); >> ret =3D 0; >> halt_node =3D of_node_get(child_node); >> >>out_put: >> of_node_put(child_node); >>=20=20=20=20=20=20=20=20 >> return ret; >>} >> >> >>cheers > > Hi, Michael and Christophe, > > I am writing the new patch based on Michael's advice. However, I wonder i= f there is > any place to call of_node_put(halt_node)? As I do not exactly know if gp= io_halt_remove() > or anyother place can correctly release this global reference=EF=BC=9F > If not, it is correct that I add a of_node_put(halt_node) in gpio_halt_re= move(), right? Yes I think so, just before it's set to NULL, eg: diff --git a/arch/powerpc/platforms/85xx/sgy_cts1000.c b/arch/powerpc/platf= orms/85xx/sgy_cts1000.c index 98ae64075193..7beb3cd420ba 100644 --- a/arch/powerpc/platforms/85xx/sgy_cts1000.c +++ b/arch/powerpc/platforms/85xx/sgy_cts1000.c @@ -139,6 +139,7 @@ static int gpio_halt_remove(struct platform_device *pde= v) =20 gpio_free(gpio); =20 + of_node_put(halt_node); halt_node =3D NULL; } =20 cheers