From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Huth Subject: Re: [kvm-unit-tests PATCH 1/2] devicetree: search up tree in dt_get_nr_cells Date: Wed, 11 May 2016 11:28:36 +0200 Message-ID: <5732FB44.3080408@redhat.com> References: <1462901526-11013-1-git-send-email-drjones@redhat.com> <1462901526-11013-2-git-send-email-drjones@redhat.com> <5732D90F.3080902@redhat.com> <20160511090445.uc56nehmipxnshdz@hawk.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, lvivier@redhat.com, pbonzini@redhat.com To: Andrew Jones Return-path: Received: from mx1.redhat.com ([209.132.183.28]:38528 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932230AbcEKJ2j (ORCPT ); Wed, 11 May 2016 05:28:39 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BBB2C05B1C7 for ; Wed, 11 May 2016 09:28:39 +0000 (UTC) In-Reply-To: <20160511090445.uc56nehmipxnshdz@hawk.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On 11.05.2016 11:04, Andrew Jones wrote: > On Wed, May 11, 2016 at 09:02:39AM +0200, Thomas Huth wrote: >> On 10.05.2016 19:32, Andrew Jones wrote: >>> Search up the tree until we find #address-cells/#size-cells. >>> Also only assign outputs if both address and size are found. >>> >>> Signed-off-by: Andrew Jones >>> --- >>> lib/devicetree.c | 17 +++++++++++++---- >>> lib/devicetree.h | 3 ++- >>> 2 files changed, 15 insertions(+), 5 deletions(-) >>> >>> diff --git a/lib/devicetree.c b/lib/devicetree.c >>> index a5c7f7c69ddfd..d3751e2b7e7f9 100644 >>> --- a/lib/devicetree.c >>> +++ b/lib/devicetree.c >>> @@ -24,21 +24,30 @@ int dt_get_nr_cells(int fdtnode, u32 *nr_address_cells, u32 *nr_size_cells) >>> { >>> const struct fdt_property *prop; >>> u32 *nr_cells; >>> - int len; >>> + int len, nac, nsc; >>> + >>> + while (1) { >>> + prop = fdt_get_property(fdt, fdtnode, "#address-cells", &len); >>> + if (prop != NULL || len != -FDT_ERR_NOTFOUND) >>> + break; >>> + fdtnode = fdt_parent_offset(fdt, fdtnode); >>> + } >> >> Why do you need this search? ePAPR clearly states: >> >> "The #address-cells and #size-cells properties are not inherited from >> ancestors in the device tree. They shall be explicitly defined." > > You are right. > > My skimming of Documentation/devicetree/booting-without-of.txt was > sloppy and I missed basically the same quote > > "Note that the parent's parent definitions of #address-cells and > #size-cells are not inherited so every node with children must > specify them." > >> >> So as far as I can see, it should always be enough to look up the >> properties in the parent of the node, no need for a recursion here? > > So, yes, I should look in the current node, and then the parent, and > then just assert. AFAIK the #address-cells and #size-cells properties of the current node only apply to the _children_ of the current node, but not to itself. I think you always have to look at the parent to find out the correct value for the current node. Thomas