[PATCH] of: match by compatible property first

Thierry Reding thierry.reding at avionic-design.de
Fri Apr 20 23:28:40 EST 2012


* Rob Herring wrote:
> On 04/20/2012 05:21 AM, Thierry Reding wrote:
[...]
> > +const struct of_device_id *of_match_compat(const struct of_device_id *matches,
> > +					   const char *compat)
> > +{
> > +	while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
> 
> You are not using name or type here, so you can remove.

They are still required so we don't stop early. A match table could well have
a first entry that has name and/or type set but not compatible, followed by a
second entry with only compatible set.

> >  	while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
> 
> You don't need to check compatible ptr here.

For similar reasons as above this check needs to stay in.

> 
> >  		int match = 1;
> >  		if (matches->name[0])
> > @@ -532,10 +558,7 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
> >  		if (matches->type[0])
> >  			match &= node->type
> >  				&& !strcmp(matches->type, node->type);
> > -		if (matches->compatible[0])
> > -			match &= of_device_is_compatible(node,
> > -						matches->compatible);
> > -		if (match)
> > +		if (match && !matches->compatible[0])
> >  			return matches;
> >  		matches++;
> >  	}
> > diff --git a/include/linux/of.h b/include/linux/of.h
> > index bd52d83..23b5061 100644
> > --- a/include/linux/of.h
> > +++ b/include/linux/of.h
> > @@ -231,6 +231,8 @@ extern const void *of_get_property(const struct device_node *node,
> >  
> >  extern int of_n_addr_cells(struct device_node *np);
> >  extern int of_n_size_cells(struct device_node *np);
> > +extern const struct of_device_id *of_match_compat(
> > +	const struct of_device_id *matches, const char *compat);
> 
> Why does this need to be a public function?

It doesn't. I just thought it might be handy to have. I can make it static if
you don't think it's useful generally.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/devicetree-discuss/attachments/20120420/0bc847fa/attachment.sig>


More information about the devicetree-discuss mailing list