Skip to contentSkip to conversation

of: fix device compatibility scoring

PATCH In review Reza Arbab 2 participants 3 messages May 5, 2016 – May 6, 2016 Device tree

lore
Share & tools
lore

Reza Arbab

author
#0 lore raw

PATCH 1/1 of: fix device compatibility scoring

If a constraint given to __of_device_is_compatible() does not match, we should just move to the next constraint without adding to the compatibility score. Instead, the function immediately returns 0.

Do not return from __of_device_is_compatible() until a complete score has been calculated.

---
 drivers/of/base.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/of/base.c +4 -8
index 017dd94..942a60e 100644
@@ -455,22 +455,18 @@ static int __of_device_is_compatible(const struct device_node *device,
 				break;
 			}
 		}
-		if (!score)
-			return 0;
 	}
 
 	/* Matching type is better than matching name */
 	if (type && type[0]) {
-		if (!device->type || of_node_cmp(type, device->type))
-			return 0;
-		score += 2;
+		if (device->type && !of_node_cmp(type, device->type))
+			score += 2;
 	}
 
 	/* Matching name is a bit better than not */
 	if (name && name[0]) {
-		if (!device->name || of_node_cmp(name, device->name))
-			return 0;
-		score++;
+		if (device->name && !of_node_cmp(name, device->name))
+			score++;
 	}
 
 	return score;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · Reza Arbab

If a constraint given to __of_device_is_compatible() does not match, we should just move to the next constraint without adding to the compatibility score. Instead, the function immediately returns 0.

Do not return from __of_device_is_compatible() until a complete score has been calculated.

This matching is very sensitive to changes. Can you please describe what conditions don't work for you and add a test case for that condition to the unit test.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#2 lore raw
Quoted 3 lines · Rob Herring

This matching is very sensitive to changes. Can you please describe what conditions don't work for you and add a test case for that condition to the unit test.

Ah, thanks for pointing out the unit test.

Looking at the test cases there cleared up the misunderstanding I had which led me to suggest the patch. It does seem that the short-circuiting in __of_device_is_compatible() is intentional.

Please disregard. Sorry for the noise.

Signature · 1 line
Reza Arbab