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 B49D3C43334 for ; Wed, 29 Jun 2022 08:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230416AbiF2Ihn (ORCPT ); Wed, 29 Jun 2022 04:37:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232823AbiF2Ihm (ORCPT ); Wed, 29 Jun 2022 04:37:42 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 56AEE3CA5B; Wed, 29 Jun 2022 01:37:40 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTPS id 2E19F80CD; Wed, 29 Jun 2022 08:32:25 +0000 (UTC) Date: Wed, 29 Jun 2022 11:37:38 +0300 From: Tony Lindgren To: "Russell King (Oracle)" 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: Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org * Russell King (Oracle) [220628 16:11]: > 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. OK yeah. This is several lines of code to check if something exists. Maybe we should just add bool of_compatible_node_exists() to simplify cases like this that does not keep the kfef. Regards, Tony 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 31B24CCA47C for ; Wed, 29 Jun 2022 08:38:45 +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=pdxCLNuf4ZhB4uOREHgHMiGuq8vCdyfxohsdTQvnmMY=; b=FvM29MjZmDEAPv /9I1oPKQHWJhk5RPxkApjqaIWHgYGvHKZ8DVOO95MYKbjQ8Q5/V1K3uSBlR7gDBrfPBjsHPMVyr4z xOg71BdSgOksosr3lj8HQHxbExCyHReATTubQAeNvEBNJwiCMXfzbBpCmRjrNIs6aa7B6JGTBNU7Q SNmQe4yh/9YpTCt+u5rFuPsyDHUhW24DpBjzZSlu3Bk1/wMLsvuDJBsWWhYjDDqj7WAaD5sSk9s5A duyg8L4GKIRPQPNxZZx1mhTqGZds84eQ8eRloHV6LdOF0B3D2nvUVcSln7y3NrLVOxrdpPQlt2J3m oyfn1VvtJh0OIfA2y/7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6TCl-00ARqw-Ae; Wed, 29 Jun 2022 08:37:47 +0000 Received: from muru.com ([72.249.23.125]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6TCh-00ARpU-T9 for linux-arm-kernel@lists.infradead.org; Wed, 29 Jun 2022 08:37:45 +0000 Received: from localhost (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTPS id 2E19F80CD; Wed, 29 Jun 2022 08:32:25 +0000 (UTC) Date: Wed, 29 Jun 2022 11:37:38 +0300 From: Tony Lindgren To: "Russell King (Oracle)" 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-20220629_013744_035041_1F0EC6A1 X-CRM114-Status: GOOD ( 17.04 ) 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 * Russell King (Oracle) [220628 16:11]: > 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. OK yeah. This is several lines of code to check if something exists. Maybe we should just add bool of_compatible_node_exists() to simplify cases like this that does not keep the kfef. Regards, Tony _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel