[PATCH] fwts_devicetree: Add function for common usage

Deb McLemore debmc at linux.vnet.ibm.com
Wed Sep 14 15:59:14 UTC 2016


Move the check_property_printable to the library for common usage.

Signed-off-by: Deb McLemore <debmc at linux.vnet.ibm.com>
---
 src/devicetree/dt_sysinfo/dt_sysinfo.c | 47 ---------------------------------
 src/lib/include/fwts_devicetree.h      |  5 ++++
 src/lib/src/fwts_devicetree.c          | 48 ++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/src/devicetree/dt_sysinfo/dt_sysinfo.c b/src/devicetree/dt_sysinfo/dt_sysinfo.c
index 159dfc6..0565979 100644
--- a/src/devicetree/dt_sysinfo/dt_sysinfo.c
+++ b/src/devicetree/dt_sysinfo/dt_sysinfo.c
@@ -49,53 +49,6 @@ static struct reference_platform {
 		FWTS_ARRAY_LEN(garrison_models)},
 };
 
-static int check_property_printable(fwts_framework *fw,
-	const char *name,
-	const char *buf,
-	size_t len)
-{
-	bool printable = true;
-	unsigned int i;
-
-	/* we need at least one character plus a nul */
-	if (len < 2) {
-		fwts_failed(fw, LOG_LEVEL_LOW,
-			"DTPrintablePropertyShort",
-			"property %s is too short", name);
-		return FWTS_ERROR;
-	}
-
-	/* check all characters are printable */
-	for (i = 0; i < len - 1; i++) {
-		printable = printable && isprint(buf[i]);
-		if (!printable)
-			break;
-	}
-
-	if (!printable) {
-		fwts_failed(fw, LOG_LEVEL_LOW,
-			"DTPrintablePropertyInvalid",
-			"property %s contains unprintable characters",
-			name);
-		return FWTS_ERROR;
-	}
-
-	/* check for a trailing nul */
-	if (buf[len-1] != '\0') {
-		fwts_failed(fw, LOG_LEVEL_LOW,
-			"DTPrintablePropertyNoNul",
-			"property %s isn't nul-terminated", name);
-		return FWTS_ERROR;
-	}
-
-	fwts_log_info_verbatim(fw,
-		"DTPrintableProperty with a string"
-		" value of \"%s\" passed",
-		buf);
-
-	return FWTS_OK;
-}
-
 static int dt_sysinfo_check_root_property(
 	fwts_framework *fw,
 	const char *name,
diff --git a/src/lib/include/fwts_devicetree.h b/src/lib/include/fwts_devicetree.h
index 355c0ee..a0ea9d0 100644
--- a/src/lib/include/fwts_devicetree.h
+++ b/src/lib/include/fwts_devicetree.h
@@ -50,4 +50,9 @@ static inline int fwts_devicetree_read(fwts_framework *fwts
 }
 #endif
 
+int check_property_printable(fwts_framework *fw,
+			const char *name,
+			const char *buf,
+			size_t len);
+
 #endif
diff --git a/src/lib/src/fwts_devicetree.c b/src/lib/src/fwts_devicetree.c
index 94367de..d7facb0 100644
--- a/src/lib/src/fwts_devicetree.c
+++ b/src/lib/src/fwts_devicetree.c
@@ -20,6 +20,7 @@
 #define _GNU_SOURCE
 
 #include <stdio.h>
+#include <ctype.h>
 
 #include "fwts.h"
 
@@ -63,3 +64,50 @@ int fwts_devicetree_read(fwts_framework *fwts)
 	return FWTS_OK;
 }
 
+int check_property_printable(fwts_framework *fw,
+	const char *name,
+	const char *buf,
+	size_t len)
+{
+	bool printable = true;
+	unsigned int i;
+
+	/* we need at least one character plus a nul */
+	if (len < 2) {
+		fwts_failed(fw, LOG_LEVEL_LOW,
+			"DTPrintablePropertyShort",
+			"property \"%s\" is too short", name);
+		return FWTS_ERROR;
+	}
+
+	/* check all characters are printable */
+	for (i = 0; i < len - 1; i++) {
+		printable = printable && isprint(buf[i]);
+		if (!printable)
+			break;
+	}
+
+	if (!printable) {
+		fwts_failed(fw, LOG_LEVEL_LOW,
+			"DTPrintablePropertyInvalid",
+			"property \"%s\" contains unprintable characters",
+			name);
+		return FWTS_ERROR;
+	}
+
+	/* check for a trailing nul */
+	if (buf[len-1] != '\0') {
+		fwts_failed(fw, LOG_LEVEL_LOW,
+			"DTPrintablePropertyNoNul",
+			"property \"%s\" isn't nul-terminated", name);
+		return FWTS_ERROR;
+	}
+
+	fwts_log_info_verbatim(fw,
+		"DTPrintableProperty \"%s\" with a string"
+		" value of \"%s\" passed",
+		name,
+		buf);
+
+	return FWTS_OK;
+}
-- 
2.7.4




More information about the fwts-devel mailing list