Skip to content

Commit 1053531

Browse files
shesselbaRob Herring
authored andcommitted
OF: base: match each node compatible against all given matches first
Currently, of_match_node compares each given match against all node's compatible strings with of_device_is_compatible. To achieve multiple compatible strings per node with ordering from specific to generic, this requires given matches to be ordered from specific to generic. For most of the drivers this is not true and also an alphabetical ordering is more sane there. Therefore, this patch modifies of_match_node to match each of the node's compatible strings against all given matches first, before checking the next compatible string. This implies that node's compatibles are ordered from specific to generic while given matches can be in any order. Signed-off-by: Sebastian Hesselbarth <[email protected]> Tested-by: Meelis Roos <[email protected]> Signed-off-by: Rob Herring <[email protected]>
1 parent 3ab72f9 commit 1053531

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

drivers/of/base.c

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -731,24 +731,42 @@ static
731731
const struct of_device_id *__of_match_node(const struct of_device_id *matches,
732732
const struct device_node *node)
733733
{
734+
const char *cp;
735+
int cplen, l;
736+
734737
if (!matches)
735738
return NULL;
736739

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

@@ -757,7 +775,10 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
757775
* @matches: array of of device match structures to search in
758776
* @node: the of device structure to match against
759777
*
760-
* Low level utility function used by device matching.
778+
* Low level utility function used by device matching. Matching order
779+
* is to compare each of the node's compatibles with all given matches
780+
* first. This implies node's compatible is sorted from specific to
781+
* generic while matches can be in any order.
761782
*/
762783
const struct of_device_id *of_match_node(const struct of_device_id *matches,
763784
const struct device_node *node)

0 commit comments

Comments
 (0)