[PATCH 2/2] of: search the best compatible match first in __of_match_node()

Kevin Hao haokexin at gmail.com
Tue Feb 18 16:41:45 EST 2014


On Mon, Feb 17, 2014 at 05:58:34PM +0000, Grant Likely wrote:
> This seems wrong also. The compatible order should be checked for even
> when m->name or m->type are set.  You actually need to score the entries
> to do this properly. The pseudo-code should look like this:
> 
> uint best_score = ~0;
> of_device_id *best_match = NULL;
> for_each(matches) {
> 	uint score = ~0;
> 	for_each_compatible(index) {
> 		if (match->compatible == compatible[index])
> 			score = index * 10;
> 	}
> 
> 	/* Matching name is a bit better than not */
> 	if (match->name == node->name)
> 		score--;
> 
> 	/* Matching type is better than matching name */
> 	/* (but matching both is even better than that */
> 	if (match->type == node->type)
> 		score -= 2;
> 
> 	if (score < best_score)
> 		best_match = match;
> }
> return best_match;
> 
> This is actually very similar to the original code. It is an easy
> modification. This is very similar to how the of_fdt_is_compatible()
> function works.

I like this idea and will make a new patch based on this.

Thanks,
Kevin
> 
> g.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20140218/786eba89/attachment.sig>


More information about the Linuxppc-dev mailing list