From: Ian Campbell Subject: Re: [PATCH v3 6/8] xen/device_tree: introduce find_compatible_node Date: Wed, 19 Dec 2012 14:06:37 +0000 Message-ID: <1355925997.14620.415.camel@zakaz.uk.xensource.com> References: <1355856402-26614-6-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1355856402-26614-6-git-send-email-stefano.stabellini@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: "xen-devel@lists.xensource.com" , "Tim (Xen.org)" List-Id: xen-devel@lists.xenproject.org On Tue, 2012-12-18 at 18:46 +0000, Stefano Stabellini wrote: > Introduce a find_compatible_node function that can be used by device > +static int _find_compatible_node(const void *fdt, > + int node, const char *name, int depth, > + u32 address_cells, u32 size_cells, > + void *data) > +{ > + struct find_compat *c = (struct find_compat *) data; > + > + if ( c->found ) > + return 0; It'd be nice if returning e.g. 1 would cause device_tree_for_each_node to stop walking the DTB and return immediately. Would make this function cleaner and avoid pointlessly parsing the rest of the DTB. > + > + if ( device_tree_node_compatible(fdt, node, c->compatible) ) > + { > + c->found = 1; > + c->node = node; > + c->depth = depth; > + c->address_cells = address_cells; > + c->size_cells = size_cells; > + } > + return 0; > +} > + > +int find_compatible_node(const char *compatible, int *node, int *depth, > + u32 *address_cells, u32 *size_cells) > +{ > + int ret; > + struct find_compat c; > + c.compatible = compatible; > + c.found = 0; > + > + ret = device_tree_for_each_node(device_tree_flattened, _find_compatible_node, &c); > + if ( !c.found ) > + return ret;