bootwrapper: Add dt_is_compatible().
In-Reply-To: <[email protected]>
Quoted 6 lines · Scott Wood
(quoted diff) +6
-0+int dt_is_compatible(void *node, const char *compat) +{ + char *buf = (char *)prop_buf; + int compat_len = strlen(compat); + int len, pos; +
Review
Quoted 10 lines
(quoted diff) +10
-0+ len = getprop(node, "compatible", buf, MAX_PROP_LEN); + if (len < 0) + return 0; + + for (pos = 0; pos + compat_len < len; pos++) { + if (!strcmp(buf + pos, compat)) + return 1; + + while (buf[pos] && pos + compat_len < len) + pos++;
This is buggy: if you are searching for "ns16550" and the compatable is "fsl,1234\0commons16550" this code will incorrectly says its compatable.
Comparing pos < len instead will do the right thing, at the cost of a few iterations of the loop.
Review
Quoted 3 lines
(quoted diff) +3
-0+ } + + return 0;
milton