Skip to content

Commit 4e8ca6e

Browse files
haokexinrobherring
authored andcommitted
Revert "OF: base: match each node compatible against all given matches first"
This reverts commit 1053531. Stephen Chivers reported this is broken as we will get a match entry '.type = "serial"' instead of the '.compatible = "ns16550"' in the following scenario: serial0: serial@4500 { compatible = "fsl,ns16550", "ns16550"; } struct of_device_id of_platform_serial_table[] = { { .compatible = "ns8250", .data = (void *)PORT_8250, }, { .compatible = "ns16450", .data = (void *)PORT_16450, }, { .compatible = "ns16550a", .data = (void *)PORT_16550A, }, { .compatible = "ns16550", .data = (void *)PORT_16550, }, { .compatible = "ns16750", .data = (void *)PORT_16750, }, { .compatible = "ns16850", .data = (void *)PORT_16850, }, ... { .type = "serial", .data = (void *)PORT_UNKNOWN, }, { /* end of list */ }, }; So just revert this patch, we will use another implementation to find the best compatible match in a follow-on patch. Reported-by: Stephen N Chivers <[email protected]> Cc: Sebastian Hesselbarth <[email protected]> Signed-off-by: Kevin Hao <[email protected]> Signed-off-by: Rob Herring <[email protected]>
1 parent 860a445 commit 4e8ca6e

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

drivers/of/base.c

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -734,42 +734,24 @@ static
734734
const struct of_device_id *__of_match_node(const struct of_device_id *matches,
735735
const struct device_node *node)
736736
{
737-
const char *cp;
738-
int cplen, l;
739-
740737
if (!matches)
741738
return NULL;
742739

743-
cp = __of_get_property(node, "compatible", &cplen);
744-
do {
745-
const struct of_device_id *m = matches;
746-
747-
/* Check against matches with current compatible string */
748-
while (m->name[0] || m->type[0] || m->compatible[0]) {
749-
int match = 1;
750-
if (m->name[0])
751-
match &= node->name
752-
&& !strcmp(m->name, node->name);
753-
if (m->type[0])
754-
match &= node->type
755-
&& !strcmp(m->type, node->type);
756-
if (m->compatible[0])
757-
match &= cp
758-
&& !of_compat_cmp(m->compatible, cp,
759-
strlen(m->compatible));
760-
if (match)
761-
return m;
762-
m++;
763-
}
764-
765-
/* Get node's next compatible string */
766-
if (cp) {
767-
l = strlen(cp) + 1;
768-
cp += l;
769-
cplen -= l;
770-
}
771-
} while (cp && (cplen > 0));
772-
740+
while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
741+
int match = 1;
742+
if (matches->name[0])
743+
match &= node->name
744+
&& !strcmp(matches->name, node->name);
745+
if (matches->type[0])
746+
match &= node->type
747+
&& !strcmp(matches->type, node->type);
748+
if (matches->compatible[0])
749+
match &= __of_device_is_compatible(node,
750+
matches->compatible);
751+
if (match)
752+
return matches;
753+
matches++;
754+
}
773755
return NULL;
774756
}
775757

@@ -778,10 +760,7 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
778760
* @matches: array of of device match structures to search in
779761
* @node: the of device structure to match against
780762
*
781-
* Low level utility function used by device matching. Matching order
782-
* is to compare each of the node's compatibles with all given matches
783-
* first. This implies node's compatible is sorted from specific to
784-
* generic while matches can be in any order.
763+
* Low level utility function used by device matching.
785764
*/
786765
const struct of_device_id *of_match_node(const struct of_device_id *matches,
787766
const struct device_node *node)

0 commit comments

Comments
 (0)