Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6426561imb; Fri, 8 Mar 2019 18:19:56 -0800 (PST) X-Google-Smtp-Source: APXvYqzqkLoi+hqwIgMmqwGxeOWcKZ0IGKPq3TEsLnRDBb8/1bxFbCBWWflEtit02WSGdj1x1cpR X-Received: by 2002:aa7:8a81:: with SMTP id a1mr21670504pfc.246.1552097996473; Fri, 08 Mar 2019 18:19:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552097996; cv=none; d=google.com; s=arc-20160816; b=vmN0GdH1dNJ+Pxa0WjA3dv0LotpNwcKVErzrp2RoxhTQgb9x74UGB9FzRyp150bNyi vce17gRV573NGsZkDHEKb8coNSO4X2OPSocp1W/ucCNF7Xad66qjEOMpuWy/kmo5R34B zmlYca2sxdgxk/Sxzm4QbyXCRozaIR5Kxg+WJeaWmgKbq56c5EXiZNCWNYshYkdDOmQ6 iP2uuS0GbrVw3d7y83Rni/2pqxS0dvHhcclI7KEwPxukUdTB9J5LwObvYSqmhQzg4G4E hyHnMbm+igGUINtqzv6VEpcYWEQL7PxRZRHLmG7exyujfh0mp/TSrDJSV9OzcG8LvnzN zryA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LWU1MdRnb2VUKD0yC9of3vgG/47n3sRrwmND8NfGd4s=; b=xRJac5Pmuk+FqbJPDpacIzLC3cmXn4FyDVnM/L1tfN0qZF1t1meKryQ653wOx2xWce WmNqnvWtFOGkQNOfYpiOh/vrINYdYB4Smsu/uztDjT4JRGXhLeB4I/lewVSPXRIj+2Vj ewZm0ZscI2ONiyEIcbTtf9jFVNiX0B4v0GSgsHYTst0v+CmpQpWS9ZJXt11m1l+yOiHx B72VikSoktyYc6ycn0F6DNY82qtiifTJc7ofBGs3IiURZV3CQoDLRxos8e1P4dlG8tjU RN+q3AxloQjd6SOSzzgpRceuQ+e6ey5oDZUCDWTzyzDtJs7WeKUrkuwThl14lInjhPPk JDbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yz+3dqmK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si8878688plh.91.2019.03.08.18.19.40; Fri, 08 Mar 2019 18:19:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yz+3dqmK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbfCICRu (ORCPT + 99 others); Fri, 8 Mar 2019 21:17:50 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36394 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbfCICRu (ORCPT ); Fri, 8 Mar 2019 21:17:50 -0500 Received: by mail-pf1-f194.google.com with SMTP id n22so15440533pfa.3 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=Rk5Ic8gh+xXF5L/bPaY6/HioseIMk7bJbGRR1hmD46P9bAdVlX9KEKEEKsg5rvKDWV mGjWJjf8o3+GeWSrhtkuxPonRa9vJAdgaf1EHokvyNxj++S8PwTfISkh4e9UDSQ422gl N1G3hMwQV3UQFCtN38CseEfLA/xoCSQ4QhBKEfR0NIJFi0pxxtaMr9tnLGq5Wyuzlt58 iIEGGXcpCDEGq0swZELJecmYFt9QWuJo6/qV5M6RIQ2GzxVFf3p0b6pWAb9A8tcVv9R+ PsxK9dMAtLj2iZ33DWWxIUuc3KKHuwCpStrcuckOvBtPxe7SbJyPfbop1QaIeEKh6P9B GAjQ== X-Gm-Message-State: APjAAAUdBEd2tiZgH4q96yb86uDVCvtG1sk8AKTlwaQB8GDxD2PlMDgR cRhE9C6JbVDLhP1J1sjhb3Du 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 Cc: Wen Yang , linux-kernel@vger.kernel.org, wang.yi59@zte.com.cn, Andreas =?iso-8859-1?Q?F=E4rber?= , linux-arm-kernel@lists.infradead.org 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-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190305114048.egpbeddy4pqbwl5b@shell.armlinux.org.uk> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Russel, On Tue, Mar 05, 2019 at 11:40:48AM +0000, Russell King - ARM Linux admin wrote: > 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?rber" > > 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/platsmp.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 int max_cpus) > > } > > > > timer_base_addr = 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 int max_cpus) > > } > > > > sps_base_addr = 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 int max_cpus) > > } > > > > scu_base_addr = 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 622kbps up > According to speedtest.net: 11.9Mbps down 500kbps up