All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] of: match by compatible property first
@ 2012-04-20 10:21 Thierry Reding
       [not found] ` <1334917312-21192-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Reding @ 2012-04-20 10:21 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ; +Cc: Rob Herring

When matching devices against an OF device ID table, the first string of
the compatible property that is listed in the table should match,
regardless of its position in the table.

Signed-off-by: Thierry Reding <thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
---
 drivers/of/base.c  |   31 +++++++++++++++++++++++++++----
 include/linux/of.h |    3 +++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d9bfd49..db355b7 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -511,6 +511,23 @@ out:
 }
 EXPORT_SYMBOL(of_find_node_with_property);
 
+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]) {
+		const char *cp = matches->compatible;
+		int len = strlen(cp);
+
+		if (len > 0 && of_compat_cmp(compat, cp, len) == 0)
+			return matches;
+
+		matches++;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_match_compat);
+
 /**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *	@matches:	array of of device match structures to search in
@@ -521,9 +538,18 @@ EXPORT_SYMBOL(of_find_node_with_property);
 const struct of_device_id *of_match_node(const struct of_device_id *matches,
 					 const struct device_node *node)
 {
+	struct property *prop;
+	const char *cp;
+
 	if (!matches)
 		return NULL;
 
+	of_property_for_each_string(node, "compatible", prop, cp) {
+		const struct of_device_id *match = of_match_compat(matches, cp);
+		if (match)
+			return match;
+	}
+
 	while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
 		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);
 extern const struct of_device_id *of_match_node(
 	const struct of_device_id *matches, const struct device_node *node);
 extern int of_modalias_node(struct device_node *node, char *modalias, int len);
@@ -395,6 +397,7 @@ static inline int of_machine_is_compatible(const char *compat)
 }
 
 #define of_match_ptr(_ptr)	NULL
+#define of_match_compat(_matches, _compat)	NULL
 #define of_match_node(_matches, _node)	NULL
 #define of_property_for_each_u32(np, propname, prop, p, u) \
 	while (0)
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] of: match by compatible property first
       [not found] ` <1334917312-21192-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
@ 2012-04-20 13:13   ` Rob Herring
       [not found]     ` <4F9160DF.70308-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Rob Herring @ 2012-04-20 13:13 UTC (permalink / raw)
  To: Thierry Reding; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On 04/20/2012 05:21 AM, Thierry Reding wrote:
> When matching devices against an OF device ID table, the first string of
> the compatible property that is listed in the table should match,
> regardless of its position in the table.
> 
> Signed-off-by: Thierry Reding <thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
> ---
>  drivers/of/base.c  |   31 +++++++++++++++++++++++++++----
>  include/linux/of.h |    3 +++
>  2 files changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index d9bfd49..db355b7 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -511,6 +511,23 @@ out:
>  }
>  EXPORT_SYMBOL(of_find_node_with_property);
>  
> +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.

> +		const char *cp = matches->compatible;
> +		int len = strlen(cp);
> +
> +		if (len > 0 && of_compat_cmp(compat, cp, len) == 0)
> +			return matches;
> +
> +		matches++;
> +	}
> +
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_match_compat);
> +
>  /**
>   * of_match_node - Tell if an device_node has a matching of_match structure
>   *	@matches:	array of of device match structures to search in
> @@ -521,9 +538,18 @@ EXPORT_SYMBOL(of_find_node_with_property);
>  const struct of_device_id *of_match_node(const struct of_device_id *matches,
>  					 const struct device_node *node)
>  {
> +	struct property *prop;
> +	const char *cp;
> +
>  	if (!matches)
>  		return NULL;
>  
> +	of_property_for_each_string(node, "compatible", prop, cp) {
> +		const struct of_device_id *match = of_match_compat(matches, cp);
> +		if (match)
> +			return match;
> +	}
> +
>  	while (matches->name[0] || matches->type[0] || matches->compatible[0]) {

You don't need to check compatible ptr here.

>  		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?

>  extern const struct of_device_id *of_match_node(
>  	const struct of_device_id *matches, const struct device_node *node);
>  extern int of_modalias_node(struct device_node *node, char *modalias, int len);
> @@ -395,6 +397,7 @@ static inline int of_machine_is_compatible(const char *compat)
>  }
>  
>  #define of_match_ptr(_ptr)	NULL
> +#define of_match_compat(_matches, _compat)	NULL
>  #define of_match_node(_matches, _node)	NULL
>  #define of_property_for_each_u32(np, propname, prop, p, u) \
>  	while (0)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] of: match by compatible property first
       [not found]     ` <4F9160DF.70308-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2012-04-20 13:28       ` Thierry Reding
       [not found]         ` <20120420132839.GB25662-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Reding @ 2012-04-20 13:28 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ


[-- Attachment #1.1: Type: text/plain, Size: 1921 bytes --]

* 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

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] of: match by compatible property first
       [not found]         ` <20120420132839.GB25662-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org>
@ 2012-06-13  7:01           ` Thierry Reding
       [not found]             ` <20120613070138.GA5670-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Reding @ 2012-06-13  7:01 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ


[-- Attachment #1.1: Type: text/plain, Size: 2150 bytes --]

On Fri, Apr 20, 2012 at 03:28:40PM +0200, Thierry Reding wrote:
> * 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

Rob,

Do you have further comments on this?

Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] of: match by compatible property first
       [not found]             ` <20120613070138.GA5670-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
@ 2012-06-13 15:37               ` Rob Herring
       [not found]                 ` <4FD8B3D1.1090706-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Rob Herring @ 2012-06-13 15:37 UTC (permalink / raw)
  To: Thierry Reding; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On 06/13/2012 02:01 AM, Thierry Reding wrote:
> On Fri, Apr 20, 2012 at 03:28:40PM +0200, Thierry Reding wrote:
>> * 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.

Yes, you're right.

>>
>>>
>>>>  		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
> 
> Rob,
> 
> Do you have further comments on this?

Only that I still think of_match_compat should be static. Please respin
and I'll apply it.

Rob

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] of: match by compatible property first
       [not found]                 ` <4FD8B3D1.1090706-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2012-06-13 16:58                   ` Thierry Reding
  0 siblings, 0 replies; 6+ messages in thread
From: Thierry Reding @ 2012-06-13 16:58 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ


[-- Attachment #1.1: Type: text/plain, Size: 286 bytes --]

On Wed, Jun 13, 2012 at 10:37:53AM -0500, Rob Herring wrote:
> On 06/13/2012 02:01 AM, Thierry Reding wrote:
> > Do you have further comments on this?
> 
> Only that I still think of_match_compat should be static. Please respin
> and I'll apply it.

Will do, thanks.

Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-13 16:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-20 10:21 [PATCH] of: match by compatible property first Thierry Reding
     [not found] ` <1334917312-21192-1-git-send-email-thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
2012-04-20 13:13   ` Rob Herring
     [not found]     ` <4F9160DF.70308-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-04-20 13:28       ` Thierry Reding
     [not found]         ` <20120420132839.GB25662-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org>
2012-06-13  7:01           ` Thierry Reding
     [not found]             ` <20120613070138.GA5670-RM9K5IK7kjIQXX3q8xo1gnVAuStQJXxyR5q1nwbD4aMs9pC9oP6+/A@public.gmane.org>
2012-06-13 15:37               ` Rob Herring
     [not found]                 ` <4FD8B3D1.1090706-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-06-13 16:58                   ` Thierry Reding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.