This reverts commit 105353145eafb3ea919f5cdeb652a9d8f270228e. 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.
Unified · Split
| @@ -734,42 +734,24 @@ static · 733 unmodified lines | ||
| 734 | 734 | const struct of_device_id *__of_match_node(const struct of_device_id *matches, |
| 735 | 735 | const struct device_node *node) |
| 736 | 736 | { |
| 737 | − const char *cp; | |
| 738 | − int cplen, l; | |
| 739 | − | |
| 740 | 737 | if (!matches) |
| 741 | 738 | return NULL; |
| 742 | 739 | |
| 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 | + } | |
| 773 | 755 | return NULL; |
| 774 | 756 | } |
| 775 | 757 | |
| @@ -778,10 +760,7 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches, · 2 unmodified lines | ||
| 778 | 760 | * @matches: array of of device match structures to search in |
| 779 | 761 | * @node: the of device structure to match against |
| 780 | 762 | * |
| 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. | |
| 785 | 764 | */ |
| 786 | 765 | const struct of_device_id *of_match_node(const struct of_device_id *matches, |
| 787 | 766 | const struct device_node *node) |