@@ -756,7 +756,7 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
if (!matches)
return NULL;
- while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
+ for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) {
int score = 0;
/*
@@ -764,11 +764,10 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
* and the specific compatible is better than the general.
*/
if (matches->compatible[0]) {
- if (__of_device_is_compatible_score(node,
+ if (!__of_device_is_compatible_score(node,
matches->compatible, &score))
- score = INT_MAX - 4 * score;
- else
- score = INT_MIN;
+ continue;
+ score = INT_MAX - 4 * score;
}
/*
@@ -776,26 +775,22 @@ const struct of_device_id *__of_match_node(const struct of_device_id *matches,
* both is even better than that.
*/
if (matches->type[0]) {
- if (node->type && !strcmp(matches->type, node->type))
- score += 2;
- else
- score = INT_MIN;
+ if (!node->type || strcmp(matches->type, node->type))
+ continue;
+ score += 2;
}
/* Matching name is a bit better than not */
if (matches->name[0]) {
- if (node->name && !strcmp(matches->name, node->name))
- score++;
- else
- score = INT_MIN;
+ if (!node->name || strcmp(matches->name, node->name))
+ continue;
+ score++;
}
if (score > best_score) {
best_match = matches;
best_score = score;
}
-
- matches++;
}
return best_match;