diff mbox

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

Message ID 1467271061-16212-3-git-send-email-jk@ozlabs.org
State Accepted
Headers show

Commit Message

Jeremy Kerr June 30, 2016, 7:17 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 check should only fail if the compatible 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 it 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(-)

Comments

Colin Ian King June 30, 2016, 9:12 a.m. UTC | #1
On 30/06/16 08:17, Jeremy Kerr wrote:
> 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 check should only fail if the compatible 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 it 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 --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)
> 
Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung July 1, 2016, 1:30 a.m. UTC | #2
On 2016-06-30 03:17 PM, Jeremy Kerr wrote:
> 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 check should only fail if the compatible 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 it 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 --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)
>


Acked-by: Alex Hung <alex.hung@canonical.com>
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)