diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-05-17 16:23:50 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-05-17 16:23:50 +0200 |
commit | c5e0e697de769d0e78a00b1cb47fe864fade9974 (patch) | |
tree | 1a9177fe4fb08156bee02cdd2df0dbed61f2a12a /pbl | |
parent | ec8f2fe6b1bc9e69a725863a61a6b84ab7a91989 (diff) | |
parent | b383d7739c355fee9f81986e6e8d030185373ca5 (diff) | |
download | barebox-c5e0e697de769d0e78a00b1cb47fe864fade9974.tar.gz |
Merge branch 'for-next/riscv'
Diffstat (limited to 'pbl')
-rw-r--r-- | pbl/fdt.c | 35 | ||||
-rw-r--r-- | pbl/string.c | 12 |
2 files changed, 47 insertions, 0 deletions
@@ -68,3 +68,38 @@ err: pr_err("No memory, cannot continue\n"); while (1); } + +const void *fdt_device_get_match_data(const void *fdt, const char *nodepath, + const struct fdt_device_id ids[]) +{ + int node, length; + const char *list, *end; + const struct fdt_device_id *id; + + node = fdt_path_offset(fdt, nodepath); + if (node < 0) + return NULL; + + list = fdt_getprop(fdt, node, "compatible", &length); + if (!list) + return NULL; + + end = list + length; + + while (list < end) { + length = strnlen(list, end - list) + 1; + + /* Abort if the last string isn't properly NUL-terminated. */ + if (list + length > end) + return NULL; + + for (id = ids; id->compatible; id++) { + if (!strcasecmp(list, id->compatible)) + return id->data; + } + + list += length; + } + + return NULL; +} diff --git a/pbl/string.c b/pbl/string.c index e6c0997ebc..e96eb99fc2 100644 --- a/pbl/string.c +++ b/pbl/string.c @@ -7,6 +7,7 @@ #include <linux/types.h> #include <linux/string.h> #include <linux/compiler.h> +#include <linux/ctype.h> void *memcpy(void *__dest, __const void *__src, size_t __n) { @@ -98,6 +99,17 @@ int strcmp(const char *cs, const char *ct) return res; } +int strcasecmp(const char *s1, const char *s2) +{ + int c1, c2; + + do { + c1 = tolower(*s1++); + c2 = tolower(*s2++); + } while (c1 == c2 && c1 != 0); + return c1 - c2; +} + void *memchr(const void *s, int c, size_t count) { const unsigned char *p = s; |