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 4BBA2C43334 for ; Tue, 28 Jun 2022 16:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231923AbiF1QZE (ORCPT ); Tue, 28 Jun 2022 12:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231864AbiF1QYM (ORCPT ); Tue, 28 Jun 2022 12:24:12 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7234238D9E; Tue, 28 Jun 2022 09:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SY2DY9vW4n9MM8I0vn912TfMcNbEdcHbfEm8uHHbcro=; b=Yym22sGHypQQgdds1PkV606rHC 0nk0KC34UHLaVZjrS1LcfMAC1c1o5Usn3AyA64++lH1PUcRR4YgCVRLvHzFf5VxwH4Rc7WQbtMQj2 zDdPA0RVoDqz6Y1pGMJttTKlrLRntJR0B+/8a0bJqBYDiqYlSXAf5QrMZ83llpe+Z0ggiDaHDI8kO Orwf1ezdkBa81BWIKw9KXtoR4IBbK5xEtk8BFj9Cd0p5PB2WLjZievHKbcbZa98HRTy92dNNMIGCe cgoY030p2Zd6Ar14ncAKEHtgWotgfXrFR5kVT2de56KZv5DnwQzq4Xn7n8M7F2PbU0JJQ/+p55AQ7 pthTVh4g==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:33064) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1o6Dsm-0001oz-Lz; Tue, 28 Jun 2022 17:16:08 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1o6Dsi-00051r-2I; Tue, 28 Jun 2022 17:16:04 +0100 Date: Tue, 28 Jun 2022 17:16:04 +0100 From: "Russell King (Oracle)" To: Tony Lindgren Cc: Liang He , andre.przywara@arm.com, thierry.reding@gmail.com, jonathanh@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-tegra@vger.kernel.org, Krzysztof Kozlowski Subject: Re: [PATCH] arm/mach: Hold reference returned by of_find_xxx APIs Message-ID: References: <20220621091937.4082422-1-windhl@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org On Tue, Jun 28, 2022 at 06:59:45AM +0300, Tony Lindgren wrote: > * Liang He [220621 12:14]: > > diff --git a/arch/arm/mach-omap2/pmic-cpcap.c b/arch/arm/mach-omap2/pmic-cpcap.c > > index 668dc84fd31e..a7368d657aa8 100644 > > --- a/arch/arm/mach-omap2/pmic-cpcap.c > > +++ b/arch/arm/mach-omap2/pmic-cpcap.c > > @@ -238,8 +238,11 @@ static struct omap_voltdm_pmic omap4_fan_iva = { > > int __init omap4_cpcap_init(void) > > { > > struct voltagedomain *voltdm; > > + struct device_node *np; > > > > - if (!of_find_compatible_node(NULL, NULL, "motorola,cpcap")) > > + np = of_find_compatible_node(NULL, NULL, "motorola,cpcap"); > > + of_node_put(np); > > + if (!np) > > return -ENODEV; > > Hmm so here you are checking for !np after of_node_put()? This is permissible, because the value of the _pointer_ is being checked without dereferencing the pointer. So the fact that the node may have been freed is actually immaterial. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! 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 E6471C43334 for ; Tue, 28 Jun 2022 16:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VGmGZnVsEAGOlVxdhr5euapSzuUSveivapgRM592vd4=; b=wNT8C7Y1pcMLqu KmgF3lhCnXDGn9x76PYKAL9OFL66dcFcFF+p7A/PaKplxlr+Fe5IuiCgwycSECOrPfujiWWG6xPUA UyTldW1+vWi4Jc9evg9tc1710coAnqI162OE8F/yJdJL2hfJVKsj3WaVwlRc9W68VWGzXOtaIf/dU DsYIbPf5WUPQ+0rORZuQDTuUSqxjQsQZYXp+uXghysPCk4NeU1RTBlj+JhJKZNuvGq5Tb2bHxoF1U TvH8oz+DBEM+hn4bsNu4PlXb8UnLndUKiT34wyyGs2TlG/oBXEUyqk+tW5t9xj9M2o3azL1Q4OS/O G2Ac5aRUDObTtCVng9zQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6Duy-007A37-9q; Tue, 28 Jun 2022 16:18:24 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6Dus-0079ZK-O3 for linux-arm-kernel@lists.infradead.org; Tue, 28 Jun 2022 16:18:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SY2DY9vW4n9MM8I0vn912TfMcNbEdcHbfEm8uHHbcro=; b=Yym22sGHypQQgdds1PkV606rHC 0nk0KC34UHLaVZjrS1LcfMAC1c1o5Usn3AyA64++lH1PUcRR4YgCVRLvHzFf5VxwH4Rc7WQbtMQj2 zDdPA0RVoDqz6Y1pGMJttTKlrLRntJR0B+/8a0bJqBYDiqYlSXAf5QrMZ83llpe+Z0ggiDaHDI8kO Orwf1ezdkBa81BWIKw9KXtoR4IBbK5xEtk8BFj9Cd0p5PB2WLjZievHKbcbZa98HRTy92dNNMIGCe cgoY030p2Zd6Ar14ncAKEHtgWotgfXrFR5kVT2de56KZv5DnwQzq4Xn7n8M7F2PbU0JJQ/+p55AQ7 pthTVh4g==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:33064) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1o6Dsm-0001oz-Lz; Tue, 28 Jun 2022 17:16:08 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1o6Dsi-00051r-2I; Tue, 28 Jun 2022 17:16:04 +0100 Date: Tue, 28 Jun 2022 17:16:04 +0100 From: "Russell King (Oracle)" To: Tony Lindgren Cc: Liang He , andre.przywara@arm.com, thierry.reding@gmail.com, jonathanh@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-tegra@vger.kernel.org, Krzysztof Kozlowski Subject: Re: [PATCH] arm/mach: Hold reference returned by of_find_xxx APIs Message-ID: References: <20220621091937.4082422-1-windhl@126.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220628_091819_650471_6B06DF07 X-CRM114-Status: GOOD ( 15.12 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jun 28, 2022 at 06:59:45AM +0300, Tony Lindgren wrote: > * Liang He [220621 12:14]: > > diff --git a/arch/arm/mach-omap2/pmic-cpcap.c b/arch/arm/mach-omap2/pmic-cpcap.c > > index 668dc84fd31e..a7368d657aa8 100644 > > --- a/arch/arm/mach-omap2/pmic-cpcap.c > > +++ b/arch/arm/mach-omap2/pmic-cpcap.c > > @@ -238,8 +238,11 @@ static struct omap_voltdm_pmic omap4_fan_iva = { > > int __init omap4_cpcap_init(void) > > { > > struct voltagedomain *voltdm; > > + struct device_node *np; > > > > - if (!of_find_compatible_node(NULL, NULL, "motorola,cpcap")) > > + np = of_find_compatible_node(NULL, NULL, "motorola,cpcap"); > > + of_node_put(np); > > + if (!np) > > return -ENODEV; > > Hmm so here you are checking for !np after of_node_put()? This is permissible, because the value of the _pointer_ is being checked without dereferencing the pointer. So the fact that the node may have been freed is actually immaterial. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel