diff mbox series

[2/2] acpi: refactor by fwts_acpi_reserved_type_check

Message ID 20210513192036.1692916-2-alex.hung@canonical.com
State Accepted
Headers show
Series [1/2] acpi: refactor by fwts_acpi_structure_range_check | expand

Commit Message

Alex Hung May 13, 2021, 7:20 p.m. UTC
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/acpi/hmat/hmat.c        | 6 +-----
 src/acpi/nfit/nfit.c        | 8 ++------
 src/acpi/pptt/pptt.c        | 6 +-----
 src/lib/include/fwts_acpi.h | 2 ++
 4 files changed, 6 insertions(+), 16 deletions(-)

Comments

Colin Ian King May 13, 2021, 7:33 p.m. UTC | #1
On 13/05/2021 20:20, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/acpi/hmat/hmat.c        | 6 +-----
>  src/acpi/nfit/nfit.c        | 8 ++------
>  src/acpi/pptt/pptt.c        | 6 +-----
>  src/lib/include/fwts_acpi.h | 2 ++
>  4 files changed, 6 insertions(+), 16 deletions(-)
> 
> diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c
> index c2efdc93..e1105481 100644
> --- a/src/acpi/hmat/hmat.c
> +++ b/src/acpi/hmat/hmat.c
> @@ -181,11 +181,7 @@ static int hmat_test1(fwts_framework *fw)
>  			type_length = sizeof(fwts_acpi_table_hmat_cache) +
>  			              ((fwts_acpi_table_hmat_cache *) entry)->num_smbios * 2;
>  		} else {
> -			passed = false;
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"HMATBadSubtableType",
> -				"HMAT must have subtable with Type 0..2, got "
> -				"0x%2.2" PRIx8 " instead", entry->type);
> +			fwts_acpi_reserved_type_check(fw, "HMAT", entry->type, 0, FWTS_ACPI_HMAT_TYPE_RESERVED - 1, &passed);
>  			break;
>  		}
>  
> diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c
> index 7e250aba..6eba2058 100644
> --- a/src/acpi/nfit/nfit.c
> +++ b/src/acpi/nfit/nfit.c
> @@ -506,12 +506,8 @@ static int nfit_test1(fwts_framework *fw)
>  				reserved_passed = nfit_struct->reserved2;
>  
>  		} else {
> -			passed = false;
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"NFITBadSubType",
> -				"NFIT Structure supports type 0..%" PRId8 ", got "
> -				"0x%4.4" PRIx16 " instead", FWTS_ACPI_NFIT_TYPE_RESERVED - 1,
> -				entry->type);
> +			fwts_acpi_reserved_type_check(fw, "NFIT", entry->type, 0, FWTS_ACPI_NFIT_TYPE_RESERVED - 1, &passed);
> +			break;
>  		}
>  
>  		fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed);
> diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c
> index 2a4513a6..54eef4a2 100644
> --- a/src/acpi/pptt/pptt.c
> +++ b/src/acpi/pptt/pptt.c
> @@ -145,11 +145,7 @@ static int pptt_test1(fwts_framework *fw)
>  			pptt_id_test(fw, (fwts_acpi_table_pptt_id *) entry, &passed);
>  			type_length = sizeof(fwts_acpi_table_pptt_id);
>  		} else {
> -			passed = false;
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"PPTTBadSubtableType",
> -				"PPTT must have subtable with Type 0..2, got "
> -				"0x%2.2" PRIx8 " instead", entry->type);
> +			fwts_acpi_reserved_type_check(fw, "PPTT", entry->type, 0, FWTS_ACPI_PPTT_RESERVED - 1, &passed);
>  			break;
>  		}
>  
> diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
> index 24a58d81..0bad5452 100644
> --- a/src/lib/include/fwts_acpi.h
> +++ b/src/lib/include/fwts_acpi.h
> @@ -1393,6 +1393,7 @@ typedef enum {
>  	FWTS_ACPI_HMAT_TYPE_PROXIMITY_DOMAIN	= 0,
>  	FWTS_ACPI_HMAT_TYPE_LOCALITY		= 1,
>  	FWTS_ACPI_HMAT_TYPE_CACHE		= 2,
> +	FWTS_ACPI_HMAT_TYPE_RESERVED
>  } fwts_acpi_hmat_type;
>  
>  typedef struct {
> @@ -1460,6 +1461,7 @@ typedef enum {
>  	FWTS_ACPI_PPTT_PROCESSOR	= 0,
>  	FWTS_ACPI_PPTT_CACHE		= 1,
>  	FWTS_ACPI_PPTT_ID		= 2,
> +	FWTS_ACPI_PPTT_RESERVED
>  } fwts_acpi_pptt_type;
>  
>  typedef struct {
> 

Acked-by: Colin Ian King <colin.king@canonical.com>
Ivan Hu May 17, 2021, 6:03 a.m. UTC | #2
On 5/14/21 3:20 AM, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/acpi/hmat/hmat.c        | 6 +-----
>  src/acpi/nfit/nfit.c        | 8 ++------
>  src/acpi/pptt/pptt.c        | 6 +-----
>  src/lib/include/fwts_acpi.h | 2 ++
>  4 files changed, 6 insertions(+), 16 deletions(-)
> 
> diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c
> index c2efdc93..e1105481 100644
> --- a/src/acpi/hmat/hmat.c
> +++ b/src/acpi/hmat/hmat.c
> @@ -181,11 +181,7 @@ static int hmat_test1(fwts_framework *fw)
>  			type_length = sizeof(fwts_acpi_table_hmat_cache) +
>  			              ((fwts_acpi_table_hmat_cache *) entry)->num_smbios * 2;
>  		} else {
> -			passed = false;
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"HMATBadSubtableType",
> -				"HMAT must have subtable with Type 0..2, got "
> -				"0x%2.2" PRIx8 " instead", entry->type);
> +			fwts_acpi_reserved_type_check(fw, "HMAT", entry->type, 0, FWTS_ACPI_HMAT_TYPE_RESERVED - 1, &passed);
>  			break;
>  		}
>  
> diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c
> index 7e250aba..6eba2058 100644
> --- a/src/acpi/nfit/nfit.c
> +++ b/src/acpi/nfit/nfit.c
> @@ -506,12 +506,8 @@ static int nfit_test1(fwts_framework *fw)
>  				reserved_passed = nfit_struct->reserved2;
>  
>  		} else {
> -			passed = false;
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"NFITBadSubType",
> -				"NFIT Structure supports type 0..%" PRId8 ", got "
> -				"0x%4.4" PRIx16 " instead", FWTS_ACPI_NFIT_TYPE_RESERVED - 1,
> -				entry->type);
> +			fwts_acpi_reserved_type_check(fw, "NFIT", entry->type, 0, FWTS_ACPI_NFIT_TYPE_RESERVED - 1, &passed);
> +			break;
>  		}
>  
>  		fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed);
> diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c
> index 2a4513a6..54eef4a2 100644
> --- a/src/acpi/pptt/pptt.c
> +++ b/src/acpi/pptt/pptt.c
> @@ -145,11 +145,7 @@ static int pptt_test1(fwts_framework *fw)
>  			pptt_id_test(fw, (fwts_acpi_table_pptt_id *) entry, &passed);
>  			type_length = sizeof(fwts_acpi_table_pptt_id);
>  		} else {
> -			passed = false;
> -			fwts_failed(fw, LOG_LEVEL_HIGH,
> -				"PPTTBadSubtableType",
> -				"PPTT must have subtable with Type 0..2, got "
> -				"0x%2.2" PRIx8 " instead", entry->type);
> +			fwts_acpi_reserved_type_check(fw, "PPTT", entry->type, 0, FWTS_ACPI_PPTT_RESERVED - 1, &passed);
>  			break;
>  		}
>  
> diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
> index 24a58d81..0bad5452 100644
> --- a/src/lib/include/fwts_acpi.h
> +++ b/src/lib/include/fwts_acpi.h
> @@ -1393,6 +1393,7 @@ typedef enum {
>  	FWTS_ACPI_HMAT_TYPE_PROXIMITY_DOMAIN	= 0,
>  	FWTS_ACPI_HMAT_TYPE_LOCALITY		= 1,
>  	FWTS_ACPI_HMAT_TYPE_CACHE		= 2,
> +	FWTS_ACPI_HMAT_TYPE_RESERVED
>  } fwts_acpi_hmat_type;
>  
>  typedef struct {
> @@ -1460,6 +1461,7 @@ typedef enum {
>  	FWTS_ACPI_PPTT_PROCESSOR	= 0,
>  	FWTS_ACPI_PPTT_CACHE		= 1,
>  	FWTS_ACPI_PPTT_ID		= 2,
> +	FWTS_ACPI_PPTT_RESERVED
>  } fwts_acpi_pptt_type;
>  
>  typedef struct {
> 


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c
index c2efdc93..e1105481 100644
--- a/src/acpi/hmat/hmat.c
+++ b/src/acpi/hmat/hmat.c
@@ -181,11 +181,7 @@  static int hmat_test1(fwts_framework *fw)
 			type_length = sizeof(fwts_acpi_table_hmat_cache) +
 			              ((fwts_acpi_table_hmat_cache *) entry)->num_smbios * 2;
 		} else {
-			passed = false;
-			fwts_failed(fw, LOG_LEVEL_HIGH,
-				"HMATBadSubtableType",
-				"HMAT must have subtable with Type 0..2, got "
-				"0x%2.2" PRIx8 " instead", entry->type);
+			fwts_acpi_reserved_type_check(fw, "HMAT", entry->type, 0, FWTS_ACPI_HMAT_TYPE_RESERVED - 1, &passed);
 			break;
 		}
 
diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c
index 7e250aba..6eba2058 100644
--- a/src/acpi/nfit/nfit.c
+++ b/src/acpi/nfit/nfit.c
@@ -506,12 +506,8 @@  static int nfit_test1(fwts_framework *fw)
 				reserved_passed = nfit_struct->reserved2;
 
 		} else {
-			passed = false;
-			fwts_failed(fw, LOG_LEVEL_HIGH,
-				"NFITBadSubType",
-				"NFIT Structure supports type 0..%" PRId8 ", got "
-				"0x%4.4" PRIx16 " instead", FWTS_ACPI_NFIT_TYPE_RESERVED - 1,
-				entry->type);
+			fwts_acpi_reserved_type_check(fw, "NFIT", entry->type, 0, FWTS_ACPI_NFIT_TYPE_RESERVED - 1, &passed);
+			break;
 		}
 
 		fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed);
diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c
index 2a4513a6..54eef4a2 100644
--- a/src/acpi/pptt/pptt.c
+++ b/src/acpi/pptt/pptt.c
@@ -145,11 +145,7 @@  static int pptt_test1(fwts_framework *fw)
 			pptt_id_test(fw, (fwts_acpi_table_pptt_id *) entry, &passed);
 			type_length = sizeof(fwts_acpi_table_pptt_id);
 		} else {
-			passed = false;
-			fwts_failed(fw, LOG_LEVEL_HIGH,
-				"PPTTBadSubtableType",
-				"PPTT must have subtable with Type 0..2, got "
-				"0x%2.2" PRIx8 " instead", entry->type);
+			fwts_acpi_reserved_type_check(fw, "PPTT", entry->type, 0, FWTS_ACPI_PPTT_RESERVED - 1, &passed);
 			break;
 		}
 
diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h
index 24a58d81..0bad5452 100644
--- a/src/lib/include/fwts_acpi.h
+++ b/src/lib/include/fwts_acpi.h
@@ -1393,6 +1393,7 @@  typedef enum {
 	FWTS_ACPI_HMAT_TYPE_PROXIMITY_DOMAIN	= 0,
 	FWTS_ACPI_HMAT_TYPE_LOCALITY		= 1,
 	FWTS_ACPI_HMAT_TYPE_CACHE		= 2,
+	FWTS_ACPI_HMAT_TYPE_RESERVED
 } fwts_acpi_hmat_type;
 
 typedef struct {
@@ -1460,6 +1461,7 @@  typedef enum {
 	FWTS_ACPI_PPTT_PROCESSOR	= 0,
 	FWTS_ACPI_PPTT_CACHE		= 1,
 	FWTS_ACPI_PPTT_ID		= 2,
+	FWTS_ACPI_PPTT_RESERVED
 } fwts_acpi_pptt_type;
 
 typedef struct {