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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26141C43381 for ; Sat, 9 Mar 2019 02:18:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E55D120857 for ; Sat, 9 Mar 2019 02:18:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OggTUURA"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Yz+3dqmK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E55D120857 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject: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=sUHZ8cKlt0PZC95pJjL2QZZUAmNCM9Wz8d8jaKNS5h8=; b=OggTUURAiWaVj7 ZeoMJSsTkbHwQTOlX+4G3isT1TExWYZBqR//6HdJv712doObXC6elIRi2FP4wXZPQ5/DkwpiyfmpS 9k/aCSW3/qOFzQn46vXzRZVbNe947gzysn9UpWNnVmZSC2BQFwryDWUSp8FzT7IRvOlJH/I7bd/1b z8owaGK0EerX153OeK6DPKRdcTTlxSVOSrkpfZtn9Y7lVBl+SPFaywdJQ5Er1FCrofZNGBusA60u2 r1dEF1ra+wblNxu4m1vxpPB+9RRDH31weTviPwopDnccK3aBSSVmaZNaI3ZzGpi8ZjHv26tGLvsia 1pYeSR/Uq/q6ffM5iF7w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h2RYh-0008PC-7y; Sat, 09 Mar 2019 02:17:55 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h2RYb-0008Op-Qw for linux-arm-kernel@lists.infradead.org; Sat, 09 Mar 2019 02:17:53 +0000 Received: by mail-pf1-x442.google.com with SMTP id u9so15443402pfn.1 for ; Fri, 08 Mar 2019 18:17:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=LWU1MdRnb2VUKD0yC9of3vgG/47n3sRrwmND8NfGd4s=; b=Yz+3dqmK+1R/fURhktJmOoxzwAUcrBhy7kMqISUG5NtCqpr4VSgzvLPf4v7jZIYikG Wqrvp1KDkrkVoqB3smHhNazFSKQClohchIo7dLj+gmuUB1itb0YaD6KVU/9VqTZBsgIy x9+pYq72aLQHBQ4jEnR8IZXzyZaKJ0ZNoYqnTWirjvxBUR3NRIoD/bXouNOYrvzv5FGC klHmOnfwNf68iKTMPo9XcVVjXotobrZnGEadi2soiOL3+GsTzT+upTlp8dMo7974b4R6 i53tdSPNtChpi3eOU1I95usMMWWp9E7gFN7C0oK6O31ZdQ4icN300uTg/f3GbkSjg7+Q sKMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=LWU1MdRnb2VUKD0yC9of3vgG/47n3sRrwmND8NfGd4s=; b=DHEjpnJYAkw1UD/Yhv9i+j97M7v8P5b+pvb/vwRixRu95rAX8O4K6HcavChloRLlYJ Pa8GtyCKHZxENhRIWFqI3W3AHLSKEAHCK8bK1uUTovzQRNvaICZKO0C10G+2e0Bvwzdp t9iHCDmtw7buzbPu+ErJGRmiJGm29D1Z629Xh7N6QdEis+G2cDlHE8YHUMWTvoov2ao2 cCE60a+sgXfb1ylmJpiSfCk5UajNF1xyURpam7Lone80I3dNQcqBtEq3igZDJKmN730n TKxvVV0ORpbbDzB2myU181tF/VevSOdV8A6vJBXz1oPl0mJmAkdDO0ss+BBWLp3pvHXZ pjsA== X-Gm-Message-State: APjAAAXU7iF3nf/+OtX+xUUN6V7/d41NYTKAFCgFpXWh/N2SYo1p9xiH ZwQ7OuiFLVxhB2yiJwW8eD5P X-Google-Smtp-Source: APXvYqya9UDjiu9GHaX8oUU1TI6Q1dLRENXsEsRyjnjD1vW2yH9mOdY/a1jn9HH1gjvGsmvAh7yvrg== X-Received: by 2002:aa7:81d7:: with SMTP id c23mr22326689pfn.146.1552097869215; Fri, 08 Mar 2019 18:17:49 -0800 (PST) Received: from Mani-XPS-13-9360 ([2405:204:730b:185a:e100:cbb9:245b:912c]) by smtp.gmail.com with ESMTPSA id p11sm30212941pfi.10.2019.03.08.18.17.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Mar 2019 18:17:48 -0800 (PST) Date: Sat, 9 Mar 2019 07:47:42 +0530 From: Manivannan Sadhasivam To: Russell King - ARM Linux admin Subject: Re: [PATCH v2 01/15] ARM: actions: fix a leaked reference by adding missing of_node_put Message-ID: <20190309021742.GA5664@Mani-XPS-13-9360> References: <1551785646-46173-1-git-send-email-wen.yang99@zte.com.cn> <20190305114048.egpbeddy4pqbwl5b@shell.armlinux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190305114048.egpbeddy4pqbwl5b@shell.armlinux.org.uk> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190308_181749_905224_1920226F X-CRM114-Status: GOOD ( 29.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wang.yi59@zte.com.cn, linux-arm-kernel@lists.infradead.org, Wen Yang , Andreas =?iso-8859-1?Q?F=E4rber?= , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Russel, On Tue, Mar 05, 2019 at 11:40:48AM +0000, Russell King - ARM Linux admin wr= ote: > On Tue, Mar 05, 2019 at 07:33:52PM +0800, Wen Yang wrote: > > The call to of_get_next_child returns a node pointer with refcount > > incremented thus it must be explicitly decremented after the last > > usage. > > = > > Detected by coccinelle with the following warnings: > > ./arch/arm/mach-actions/platsmp.c:112:2-8: ERROR: missing of_node_put; = acquired a node pointer with refcount incremented on line 103, but without = a corresponding object release within this function. > > ./arch/arm/mach-actions/platsmp.c:124:2-8: ERROR: missing of_node_put; = acquired a node pointer with refcount incremented on line 115, but without = a corresponding object release within this function. > > ./arch/arm/mach-actions/platsmp.c:137:3-9: ERROR: missing of_node_put; = acquired a node pointer with refcount incremented on line 128, but without = a corresponding object release within this function. > = > I question this. Your reasoning is that the node is no longer used > so the reference count needs to be put. > = > However, in all these cases, data is read from the nodes properties > and the device remains in-use for the life of the kernel. There is > a big difference here. > = > With normal drivers, each device is bound to their associated device > node associated with the device. When the device node goes away, then > the corresponding device goes away too, which causes the driver to be > unbound from the device. > = > However, there is another class of "driver" which are the ones below, > where they are "permanent" devices. These can never go away, even if > the device node refcount hits zero and the device node is freed - the > device is still present and in-use in the system. So, having the > device node refcount hit zero is actually a bug: what that's saying > is the system device (eg, SCU) has gone away. If you somehow were to > remove the SCU from the system, you'd end up severing the connection > between the CPU cores and the rest of the system - obviously resulting > in a dead system! > = > So, what is the point of dropping these refcounts for devices that can > never go away - and thus their associated device_node should also never > go away? > = Yes, practically we would never hit this case but theoretically we should decrement the refcount for nodes/properties whenever we are done with it. As you know, there are 'n' number of places in kernel where we can see the refcount not being put after use. So I would welcome these kind of patches to set an example for someone who tries to use the of_* calls in future. IMO, DT should've handled the refcount internally without exposing the pointers to external world. Thanks, Mani > > = > > Signed-off-by: Wen Yang > > Reviewed-by: Florian Fainelli > > Cc: "Andreas F=E4rber" > > Cc: Manivannan Sadhasivam > > Cc: Russell King > > Cc: linux-arm-kernel@lists.infradead.org > > Cc: linux-kernel@vger.kernel.org > > --- > > v2->v1: add a missing space between "adding" and "missing" > > = > > arch/arm/mach-actions/platsmp.c | 3 +++ > > 1 file changed, 3 insertions(+) > > = > > diff --git a/arch/arm/mach-actions/platsmp.c b/arch/arm/mach-actions/pl= atsmp.c > > index 4fd479c..1a8e078 100644 > > --- a/arch/arm/mach-actions/platsmp.c > > +++ b/arch/arm/mach-actions/platsmp.c > > @@ -107,6 +107,7 @@ static void __init s500_smp_prepare_cpus(unsigned i= nt max_cpus) > > } > > = > > timer_base_addr =3D of_iomap(node, 0); > > + of_node_put(node); > > if (!timer_base_addr) { > > pr_err("%s: could not map timer registers\n", __func__); > > return; > > @@ -119,6 +120,7 @@ static void __init s500_smp_prepare_cpus(unsigned i= nt max_cpus) > > } > > = > > sps_base_addr =3D of_iomap(node, 0); > > + of_node_put(node); > > if (!sps_base_addr) { > > pr_err("%s: could not map sps registers\n", __func__); > > return; > > @@ -132,6 +134,7 @@ static void __init s500_smp_prepare_cpus(unsigned i= nt max_cpus) > > } > > = > > scu_base_addr =3D of_iomap(node, 0); > > + of_node_put(node); > > if (!scu_base_addr) { > > pr_err("%s: could not map scu registers\n", __func__); > > return; > > -- = > > 2.9.5 > > = > > = > = > -- = > RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ > FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbp= s up > According to speedtest.net: 11.9Mbps down 500kbps up _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel