devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: give priority to the compatible match in __of_match_node()
@ 2014-02-12 11:38 Kevin Hao
  2014-02-12 20:42 ` Stephen N Chivers
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Kevin Hao @ 2014-02-12 11:38 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ
  Cc: Sebastian Hesselbarth, Stephen N Chivers, Chris Proctor,
	Arnd Bergmann, Scott Wood, Grant Likely, Rob Herring

When the device node do have a compatible property, we definitely
prefer the compatible match besides the type and name. Only if
there is no such a match, we then consider the candidate which
doesn't have compatible entry but do match the type or name with
the device node.

This is based on a patch from Sebastian Hesselbarth.
  http://patchwork.ozlabs.org/patch/319434/

I did some code refactoring and also fixed a bug in the original patch.

Cc: Sebastian Hesselbarth <sebastian.hesselbarth-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Kevin Hao <haokexin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/of/base.c | 55 +++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 37 insertions(+), 18 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ff85450d5683..9d655df458bd 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -730,32 +730,45 @@ out:
 }
 EXPORT_SYMBOL(of_find_node_with_property);
 
+static int of_match_type_or_name(const struct device_node *node,
+				const struct of_device_id *m)
+{
+	int match = 1;
+
+	if (m->name[0])
+		match &= node->name && !strcmp(m->name, node->name);
+
+	if (m->type[0])
+		match &= node->type && !strcmp(m->type, node->type);
+
+	return match;
+}
+
 static
 const struct of_device_id *__of_match_node(const struct of_device_id *matches,
 					   const struct device_node *node)
 {
 	const char *cp;
 	int cplen, l;
+	const struct of_device_id *m;
+	int match;
 
 	if (!matches)
 		return NULL;
 
 	cp = __of_get_property(node, "compatible", &cplen);
-	do {
-		const struct of_device_id *m = matches;
+	while (cp && (cplen > 0)) {
+		m = matches;
 
 		/* Check against matches with current compatible string */
 		while (m->name[0] || m->type[0] || m->compatible[0]) {
-			int match = 1;
-			if (m->name[0])
-				match &= node->name
-					&& !strcmp(m->name, node->name);
-			if (m->type[0])
-				match &= node->type
-					&& !strcmp(m->type, node->type);
-			if (m->compatible[0])
-				match &= cp
-					&& !of_compat_cmp(m->compatible, cp,
+			if (!m->compatible[0]) {
+				m++;
+				continue;
+			}
+
+			match = of_match_type_or_name(node, m);
+			match &= cp && !of_compat_cmp(m->compatible, cp,
 							strlen(m->compatible));
 			if (match)
 				return m;
@@ -763,12 +776,18 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
 		}
 
 		/* Get node's next compatible string */ 
-		if (cp) {
-			l = strlen(cp) + 1;
-			cp += l;
-			cplen -= l;
-		}
-	} while (cp && (cplen > 0));
+		l = strlen(cp) + 1;
+		cp += l;
+		cplen -= l;
+	}
+
+	m = matches;
+	/* Check against matches without compatible string */
+	while (m->name[0] || m->type[0] || m->compatible[0]) {
+		if (!m->compatible[0] && of_match_type_or_name(node, m))
+			return m;
+		m++;
+	}
 
 	return NULL;
 }
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2014-02-20  2:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-12 11:38 [PATCH] of: give priority to the compatible match in __of_match_node() Kevin Hao
2014-02-12 20:42 ` Stephen N Chivers
     [not found] ` <1392205084-2351-1-git-send-email-haokexin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-02-13 19:01   ` Rob Herring
     [not found]     ` <CAL_JsqKMi2H=vwoxrOt8QRA2xJeiLqBKKfLtt4QRCRoFk6JUHg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-02-14  1:20       ` Kevin Hao
2014-02-17 18:06       ` Grant Likely
2014-02-19 18:25       ` Paul Gortmaker
     [not found]         ` <CAP=VYLr7hqnzW2HLS4GCMFeghCgPmrQZHYst+AUfZc_WNT-Wog-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-02-19 18:57           ` Scott Wood
2014-02-19 20:41           ` Grant Likely
     [not found]             ` <20140219204134.E4A2DC4088D-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-02-19 21:23               ` Paul Gortmaker
2014-02-20  2:05             ` Stephen N Chivers
     [not found] ` < CAL_JsqKMi2H=vwoxrOt8QRA2xJeiLqBKKfLtt4QRCRoFk6JUHg@mail.gmail.com>
     [not found]   ` < CAP=VYLr7hqnzW2HLS4GCMFeghCgPmrQZHYst+AUfZc_WNT-Wog@mail.gmail.com>
     [not found]     ` < 20140219204134.E4A2DC4088D@trevor.secretlab.ca>
     [not found]       ` <530520B6.8050205@windriver .com>
     [not found]         ` <530520B6.8050205-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>
2014-02-19 22:40           ` Grant Likely
     [not found]             ` <20140219224051.65BB7C4077A-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-02-19 22:44               ` Paul Gortmaker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).