diff mbox

[2/3] devicetree/dt_sysinfo: fix reference platform compatible vs. model check

Message ID 1467270565-15426-2-git-send-email-jk@ozlabs.org
State Superseded
Headers show

Commit Message

Jeremy Kerr June 30, 2016, 7:09 a.m. UTC
The logic in machine_matches_reference_model is slightly incorrect; if
we're *not* running on a reference platform, then we don't want to fail.

The failure condition is only true is the compatble string reports a
reference platform, but the model number does not.

This change reworks the logic in machine_matches_reference model to
reflect this, allowing us to simplify the logic a little.

Reported-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
---
 src/devicetree/dt_sysinfo/dt_sysinfo.c | 56 +++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 24 deletions(-)
diff mbox

Patch

diff --git a/src/devicetree/dt_sysinfo/dt_sysinfo.c b/src/devicetree/dt_sysinfo/dt_sysinfo.c
index d08cf5c..07cbbe0 100644
--- a/src/devicetree/dt_sysinfo/dt_sysinfo.c
+++ b/src/devicetree/dt_sysinfo/dt_sysinfo.c
@@ -171,34 +171,42 @@  static bool machine_matches_reference_model(fwts_framework *fw,
 	int compat_len,
 	const char *model)
 {
-	int i, j;
-	bool found = false;
-
-	for (i = 0;
-		i < (int)FWTS_ARRAY_LEN(openpower_reference_platforms);
-		i++) {
-		struct reference_platform *plat =
-			&openpower_reference_platforms[i];
+	bool compatible_is_reference = false, model_is_reference = false;
+	struct reference_platform *plat;
+	int i;
+
+	for (i = 0; i < (int)FWTS_ARRAY_LEN(openpower_reference_platforms);
+			i++) {
+		plat = &openpower_reference_platforms[i];
 		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])) {
-					fwts_log_info_verbatim(fw,
-			"Matched reference model, "
-			"device tree \"compatible\" is \"%s\" and "
-			"\"model\" is \"%s\"",
-			plat->compatible, model);
-					found = true;
-					break;
-				}
-			}
-		} else {
-			continue;
+				compat_len, plat->compatible)) {
+			compatible_is_reference = true;
+			break;
 		}
-		if (found)
+	}
+
+	/* Not a reference platform, nothing to check */
+	if (!compatible_is_reference)
+		return true;
+
+	/* Since we're on a reference platform, ensure that the model is also
+	 * one of the reference model numbers */
+	for (i = 0; i < plat->n_models; i++) {
+		if (!strcmp(model, plat->models[i])) {
+			model_is_reference = true;
 			break;
+		}
+	}
+
+	if (model_is_reference) {
+		fwts_log_info_verbatim(fw,
+			"Matched reference model, device tree "
+			"\"compatible\" is \"%s\" and \"model\" is "
+			"\"%s\"",
+			plat->compatible, model);
 	}
-	return found;
+
+	return model_is_reference;
 }
 
 static int dt_sysinfo_check_ref_plat_compatible(fwts_framework *fw)