[PATCH v2 1/3] devicetree/dt_sysinfo: clean up logic in stringlist_contains_last
Jeremy Kerr
jk at ozlabs.org
Thu Jun 30 07:17:39 UTC 2016
This change is a little cleanup of dt_fdt_stringlist_contains_last, but
retains the same functional semantics.
We remove the duplicated calls to memcmp, instead only changing the
arguments if !p. Also, we return a bool instead of an int, and change
the prefix from prd_ to dt_, as this is a device-tree helper (and not a
prd one).
Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
---
src/devicetree/dt_sysinfo/dt_sysinfo.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/devicetree/dt_sysinfo/dt_sysinfo.c b/src/devicetree/dt_sysinfo/dt_sysinfo.c
index 477210a..d08cf5c 100644
--- a/src/devicetree/dt_sysinfo/dt_sysinfo.c
+++ b/src/devicetree/dt_sysinfo/dt_sysinfo.c
@@ -145,7 +145,7 @@ static int dt_sysinfo_check_system_id(fwts_framework *fw)
return dt_sysinfo_check_root_property(fw, "system-id", true);
}
-static int prd_fdt_stringlist_contains_last(const char *strlist,
+static bool dt_fdt_stringlist_contains_last(const char *strlist,
int listlen,
const char *str)
{
@@ -153,19 +153,17 @@ static int prd_fdt_stringlist_contains_last(const char *strlist,
const char *p;
/* checking for either str only or last in string */
- if (listlen < 2 ) /* need at least one byte plus nul */
- return 0;
+ if (listlen < 2) /* need at least one byte plus nul */
+ return false;
p = memrchr(strlist, '\0', listlen-1);
- if (!p) {
- if (memcmp(str, strlist, len+1) == 0)
- return 1;
+ if (p) {
+ p++;
} else {
- if (memcmp(str, p+1, len+1) == 0)
- return 1;
+ p = strlist;
}
- return 0;
+ return !memcmp(str, p, len+1);
}
static bool machine_matches_reference_model(fwts_framework *fw,
@@ -181,7 +179,7 @@ static bool machine_matches_reference_model(fwts_framework *fw,
i++) {
struct reference_platform *plat =
&openpower_reference_platforms[i];
- if (prd_fdt_stringlist_contains_last(compatible,
+ if (dt_fdt_stringlist_contains_last(compatible,
compat_len, plat->compatible)) {
for (j = 0; j < plat->n_models; j++) {
if (!strcmp(model, plat->models[j])) {
--
2.7.4
More information about the fwts-devel
mailing list