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 09:02:39 +0200 Message-ID: <5732D90F.3080902@redhat.com> References: <1462901526-11013-1-git-send-email-drjones@redhat.com> <1462901526-11013-2-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: lvivier@redhat.com, pbonzini@redhat.com To: Andrew Jones , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:54173 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751275AbcEKHCn (ORCPT ); Wed, 11 May 2016 03:02:43 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 787607F6A7 for ; Wed, 11 May 2016 07:02:42 +0000 (UTC) In-Reply-To: <1462901526-11013-2-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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." 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? Thomas