Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2321537imu; Wed, 21 Nov 2018 09:48:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/XAKfZLgUAeiJcldGiATXS7rREFfibfu31VvZh1MWM/+tI4jj1TjbP1JF91GUkutBuHReDE X-Received: by 2002:a17:902:8c91:: with SMTP id t17mr7538848plo.119.1542822515878; Wed, 21 Nov 2018 09:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542822515; cv=none; d=google.com; s=arc-20160816; b=veybP5W5JNgMYVWD2Nwf8xcmCChtXNcJB6IMWj3oJpqDQ6PZWk6ICm0l+ZaqiYUZWj 2SGvqiIlNxfDCUXtm9WaQFwcsn/U1PgP9srCbyxNuNQn0D2Bm4EioKXzSxRDkrOsoljh yc14PRoFWbY2JglsINI3zUSg1diwUI2D7RyF2nGgny6ckbbMsXKiRf3JXYmgoYG13Huo M/TlM/scckEixiAlACwWdj+Y0eczQQtHYwX+14dkdzI4o9QOsFgL+NEKp3RodZB1QwNz 8I3cjYEhAe55mYU2R4AqINmWeZ+OcXgNz3P8Cn9URXXCOEamgPJUR8R4xrLmhPMnYBcV BT2Q== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=DqZOsYSImtx/m4Mvs5BzR/wAix+gzzh1o9aws2BZZFw=; b=tS/bar6YevpGxTXC7Shka8MgDHrAGxvYabTbIoYTgpUkSCNTdAtBuGT9TeK4I9MrAa vabQrbtuVsVYH6jRNMfRz66crc1ioEsA93I/vgeE8xtenEId0Lw8DQbw3ENkvRuDNO9r fJnkDd1WvAtMDYHfXhz8o+RkLt8JU0/aVwMsA/oDXXTUjXJXLDXqNj4FIDUKGzXPTG74 o4DI+B3m8VXJuIU1aLue7UN3i2qItSQPhDkeFh5IlYgOwAxH+AApcdmY2+qBHuAkx9lF +QBcptLoe5gVjAt0xq7rJvAooH1mOf5fMSL9WgIHnh9EcdCLQqUWQ6JhbilSkInfpRyA I0vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Edlvv18f; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si13064855plr.127.2018.11.21.09.48.15; Wed, 21 Nov 2018 09:48:35 -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=@gmail.com header.s=20161025 header.b=Edlvv18f; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730066AbeKVBSG (ORCPT + 99 others); Wed, 21 Nov 2018 20:18:06 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:34615 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbeKVBSG (ORCPT ); Wed, 21 Nov 2018 20:18:06 -0500 Received: by mail-ed1-f65.google.com with SMTP id b3so5108384ede.1; Wed, 21 Nov 2018 06:43:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DqZOsYSImtx/m4Mvs5BzR/wAix+gzzh1o9aws2BZZFw=; b=Edlvv18f+gNBASfaOzMnOwuUQi4nF1wm1j6k1mOLH2DXAsQ1jRIoqmtNVPzHo4q9nX skRKXy2/7GUN0LiozMstz/38CS6amDLCvICKZzWp8ewMqltfSVGgjq441Gc/ermKUPj+ rQH5NDO7hoP3IjpDs5zMV6ZeDgq3oAvcwVCLPn/l6+CtZa+vEwVXj61AadofVc7UkSSJ 5yVFXhyWjVjkIHpIyzwDqXMTpnHOXX/46G+dFTfDGbivLnmuATROF6AERnCjq5L8Colu yZx1O55lq1aABik2yIsCvggxUu5cZR+5YuQPPMB18mnbutv8hWaZKsVrg4yEeT4asPSi /kNQ== 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:in-reply-to:user-agent; bh=DqZOsYSImtx/m4Mvs5BzR/wAix+gzzh1o9aws2BZZFw=; b=Iz4GJZcJmKAmjE1hJUjRtD1NhZamgDd9WscVOcJKVK17n+dCzi+eHyuVNcCH0gG46f Ff2z4TrKPy3y9VR3mUHoBryfdegSt/GlZcnctCcE7ohrtg3sNNaXKY6yhRMlmW/9x2/d duNNWeCWMhi6K1q9E+T7OXI+wqJx/9PMATqUfKqcqcs63WcpeZOoERPbLWa8p1UoiumQ hN3Fz4nv/iV4C6DaRm36C23UM/BEN5N/HvYDdCqmcuj4mDjJCmNiDC2a06fUfxKTq6A4 7VVbc/KdN4WGjyLz6umSoQKBgoy6r0papRk+zpBth4A4fFtzN3zjtb7Na74Wv6CgnvQM 7hjw== X-Gm-Message-State: AA+aEWYZ/R8EVshrFhhKPKwf/dvPtZlwtfIg7nIv+6+78anC9kTObZzi sTiL+Vy006pNidoF9/tArNw= X-Received: by 2002:aa7:d602:: with SMTP id c2mr5902437edr.203.1542811402130; Wed, 21 Nov 2018 06:43:22 -0800 (PST) Received: from localhost (pD9E511F8.dip0.t-ipconnect.de. [217.229.17.248]) by smtp.gmail.com with ESMTPSA id n34-v6sm13676159edc.34.2018.11.21.06.43.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 06:43:21 -0800 (PST) Date: Wed, 21 Nov 2018 15:43:20 +0100 From: Thierry Reding To: Jon Hunter Cc: Yangtao Li , linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] soc/tegra: refactor soc_is_tegra() Message-ID: <20181121144320.GA6446@ulmo> References: <20181121141204.22819-1-tiny.windzz@gmail.com> <2d534bbb-7b75-8521-bf88-36b52c918d19@nvidia.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="M9NhX3UHpAaciwkO" Content-Disposition: inline In-Reply-To: <2d534bbb-7b75-8521-bf88-36b52c918d19@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Nov 21, 2018 at 02:34:57PM +0000, Jon Hunter wrote: >=20 > On 21/11/2018 14:12, Yangtao Li wrote: > > of_find_node_by_path() acquires a reference to the node returned by > > it and that reference needs to be dropped by its caller.soc_is_tegra() > > doesn't do that, so fix it.Call of_machine_is_compatible() to refactor > > soc_is_tegra() whcih automatically manages the reference count. > >=20 > > Signed-off-by: Yangtao Li > > --- > > drivers/soc/tegra/common.c | 12 +++++++----- > > 1 file changed, 7 insertions(+), 5 deletions(-) > >=20 > > diff --git a/drivers/soc/tegra/common.c b/drivers/soc/tegra/common.c > > index cd8f41351add..0b40700b672a 100644 > > --- a/drivers/soc/tegra/common.c > > +++ b/drivers/soc/tegra/common.c > > @@ -22,11 +22,13 @@ static const struct of_device_id tegra_machine_matc= h[] =3D { > > =20 > > bool soc_is_tegra(void) > > { > > - struct device_node *root; > > + struct of_device_id *match =3D tegra_machine_match; > > =20 > > - root =3D of_find_node_by_path("/"); > > - if (!root) > > - return false; > > + while(match->compatible){ > > + if(of_machine_is_compatible(match->compatible)) > > + return true; > > + match++; > > + } > > =20 > > - return of_match_node(tegra_machine_match, root) !=3D NULL; > > + return false; > > } >=20 > Ugh ... sorry, I thought that of_machine_is_compatible() looped through > the matches. OK, let's stick with your initial fix. Actually I prefer this one. Even if it is slightly more verbose, I think it's much clearer what's actually going on. Also this hides all of the OF node reference counting in a core function, so it's worth the extra line, in my opinion. Thierry --M9NhX3UHpAaciwkO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAlv1bwUACgkQ3SOs138+ s6Eksg//TwuKgBqk1HtsPEhiWVFzTb5mDYtG8SXlwIO1sLcdML57mPszrfU9Og9J H+XTtiJobofywHxbEmkKBstNx+DOe5T4B8nnvVFpeyvraN+1Jsey2lkt04+rh7en UfAlPgtWdhif6BKObnvlBv7L1wkYOWQYfF3HNCafnjxMgLBsImjbpq90PU50ykgT bnfDI2ArcrwpbL+WIHmWETLGIHdNJ2BGQMweMdYTgZyh5J5VVkvBc/L5TqLkk06M aclKBhRCc1XgULqTmLmXpBFeAKtFakSjivqJyoowrAaGo0hoiAeaRe53pqknvGU9 j8T4pAT8RK5rC3luRjz7qTJrKAqVrarIVAZS+mh1Flv1c4Yl7gTmFUGVWCnn595v 0EACE8YSgxGKONXySC3Pmd2upWHbf+ZLg5RErkL9TYwqgHuG61RpyzaiMqNDLWlt 2cSz9MQw4VktnvFJwSqOBKCYEQKGPG5HlQsABQ//LSDpsHETyc/arj8kW+JKNzvd NgFs7SNWdlpeHb4BKIy34zMwaSL079MFIa772G4xmlMt1GLIdwEae4syMbvl/4c8 i8yCPyIe/Mni+n43GLpCx0cvrVUSJLMoNobWxW+BVW1HBHJp4zn9u1lICHYohxas SW9U0DrK2SBRyhXxnQP+px0uW3HriWYyzEXggKeTndseSWW4nds= =rH1v -----END PGP SIGNATURE----- --M9NhX3UHpAaciwkO--