[V2] lib: fwts_acpi_tables: add a new function to check Reserved field

Message ID 1504831492-16508-1-git-send-email-alex.hung@canonical.com
State Accepted
Headers show
Series
  • [V2] lib: fwts_acpi_tables: add a new function to check Reserved field
Related show

Commit Message

Alex Hung Sept. 8, 2017, 12:44 a.m.
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/lib/include/fwts_acpi_tables.h |  2 ++
 src/lib/src/fwts_acpi_tables.c     | 43 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

Comments

Colin King Sept. 8, 2017, 7:50 a.m. | #1
On 08/09/17 01:44, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/lib/include/fwts_acpi_tables.h |  2 ++
>  src/lib/src/fwts_acpi_tables.c     | 43 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index 2527984..d478d99 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -53,6 +53,8 @@ bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
>  
>  fwts_bool fwts_acpi_is_reduced_hardware(const fwts_acpi_table_fadt *fadt);
>  
> +void fwts_acpi_reserved_zero_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
> +
>  #endif
>  
>  #endif
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 3c3a63a..4ac70f8 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -1383,4 +1383,47 @@ bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name)
>  	return found;
>  }
>  
> +/*
> + *  fwts_acpi_reserved_zero_check()
> + *  verify whether the reserved field is zero
> + */
> +void fwts_acpi_reserved_zero_check(
> +	fwts_framework *fw,
> +	const char *table,
> +	const char *field,
> +	uint64_t value,
> +	uint8_t size,
> +	bool *passed)
> +{
> +	if (value != 0) {
> +		char label[20];
> +		strncpy(label, table, 4);	/* ACPI table name is 4 char long */
> +		strncpy(label + 4, "ReservedNonZero", sizeof(label) - 4);
> +
> +		switch (size) {
> +		case sizeof(uint8_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%2.2" PRIx8 " instead", table, field, (uint8_t)value);
> +			break;
> +		case sizeof(uint16_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%4.4" PRIx16 " instead", table, field, (uint16_t)value);
> +			break;
> +		case sizeof(uint32_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%8.8" PRIx32 " instead", table, field, (uint32_t)value);
> +			break;
> +		case sizeof(uint64_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%16.16" PRIx64 " instead", table, field, value);
> +			break;
> +		}
> +		*passed = false;
> +	}
> +}
> +
>  #endif
> 

Thanks Alex.

Acked-by: Colin Ian King <colin.king@canonical.com>
ivanhu Sept. 21, 2017, 8:24 a.m. | #2
On 09/08/2017 08:44 AM, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>   src/lib/include/fwts_acpi_tables.h |  2 ++
>   src/lib/src/fwts_acpi_tables.c     | 43 ++++++++++++++++++++++++++++++++++++++
>   2 files changed, 45 insertions(+)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index 2527984..d478d99 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -53,6 +53,8 @@ bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
>   
>   fwts_bool fwts_acpi_is_reduced_hardware(const fwts_acpi_table_fadt *fadt);
>   
> +void fwts_acpi_reserved_zero_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
> +
>   #endif
>   
>   #endif
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 3c3a63a..4ac70f8 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -1383,4 +1383,47 @@ bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name)
>   	return found;
>   }
>   
> +/*
> + *  fwts_acpi_reserved_zero_check()
> + *  verify whether the reserved field is zero
> + */
> +void fwts_acpi_reserved_zero_check(
> +	fwts_framework *fw,
> +	const char *table,
> +	const char *field,
> +	uint64_t value,
> +	uint8_t size,
> +	bool *passed)
> +{
> +	if (value != 0) {
> +		char label[20];
> +		strncpy(label, table, 4);	/* ACPI table name is 4 char long */
> +		strncpy(label + 4, "ReservedNonZero", sizeof(label) - 4);
> +
> +		switch (size) {
> +		case sizeof(uint8_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%2.2" PRIx8 " instead", table, field, (uint8_t)value);
> +			break;
> +		case sizeof(uint16_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%4.4" PRIx16 " instead", table, field, (uint16_t)value);
> +			break;
> +		case sizeof(uint32_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%8.8" PRIx32 " instead", table, field, (uint32_t)value);
> +			break;
> +		case sizeof(uint64_t):
> +			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
> +				"%4.4s %s field must be zero, got "
> +				"0x%16.16" PRIx64 " instead", table, field, value);
> +			break;
> +		}
> +		*passed = false;
> +	}
> +}
> +
>   #endif
> 

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

Patch

diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
index 2527984..d478d99 100644
--- a/src/lib/include/fwts_acpi_tables.h
+++ b/src/lib/include/fwts_acpi_tables.h
@@ -53,6 +53,8 @@  bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
 
 fwts_bool fwts_acpi_is_reduced_hardware(const fwts_acpi_table_fadt *fadt);
 
+void fwts_acpi_reserved_zero_check(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
+
 #endif
 
 #endif
diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 3c3a63a..4ac70f8 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -1383,4 +1383,47 @@  bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name)
 	return found;
 }
 
+/*
+ *  fwts_acpi_reserved_zero_check()
+ *  verify whether the reserved field is zero
+ */
+void fwts_acpi_reserved_zero_check(
+	fwts_framework *fw,
+	const char *table,
+	const char *field,
+	uint64_t value,
+	uint8_t size,
+	bool *passed)
+{
+	if (value != 0) {
+		char label[20];
+		strncpy(label, table, 4);	/* ACPI table name is 4 char long */
+		strncpy(label + 4, "ReservedNonZero", sizeof(label) - 4);
+
+		switch (size) {
+		case sizeof(uint8_t):
+			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
+				"%4.4s %s field must be zero, got "
+				"0x%2.2" PRIx8 " instead", table, field, (uint8_t)value);
+			break;
+		case sizeof(uint16_t):
+			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
+				"%4.4s %s field must be zero, got "
+				"0x%4.4" PRIx16 " instead", table, field, (uint16_t)value);
+			break;
+		case sizeof(uint32_t):
+			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
+				"%4.4s %s field must be zero, got "
+				"0x%8.8" PRIx32 " instead", table, field, (uint32_t)value);
+			break;
+		case sizeof(uint64_t):
+			fwts_failed(fw, LOG_LEVEL_MEDIUM, label,
+				"%4.4s %s field must be zero, got "
+				"0x%16.16" PRIx64 " instead", table, field, value);
+			break;
+		}
+		*passed = false;
+	}
+}
+
 #endif