[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fwts-devel
Subject:    [PATCH v2 1/3] devicetree/dt_sysinfo: clean up logic in stringlist_contains_last
From:       Jeremy Kerr <jk () ozlabs ! org>
Date:       2016-06-30 7:17:39
Message-ID: 1467271061-16212-2-git-send-email-jk () ozlabs ! org
[Download RAW message or body]

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@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


-- 
fwts-devel mailing list
fwts-devel@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/fwts-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic