[PATCH 1/3] acpi: lib: add three helper functions

Colin Ian King colin.king at canonical.com
Fri Apr 9 08:28:47 UTC 2021


On 09/04/2021 03:27, Alex Hung wrote:
> Includes:
>   fwts_acpi_structure_length_zero_check
>   fwts_acpi_structure_range_check
>   fwts_acpi_structure_type_error
> 
> Signed-off-by: Alex Hung <alex.hung at canonical.com>
> ---
>  src/lib/include/fwts_acpi_tables.h |  3 ++
>  src/lib/src/fwts_acpi_tables.c     | 62 ++++++++++++++++++++++++++++++
>  2 files changed, 65 insertions(+)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index 56414730..7b62af8f 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -76,6 +76,9 @@ void fwts_acpi_reserved_bits_check_(fwts_framework *fw, const char *table, const
>  void fwts_acpi_reserved_type_check(fwts_framework *fw, const char *table, uint8_t value, uint8_t min, uint8_t reserved, bool *passed);
>  bool fwts_acpi_table_length_check(fwts_framework *fw, const char *table, uint32_t length, uint32_t size);
>  bool fwts_acpi_structure_length_check(fwts_framework *fw, const char *table, uint8_t subtable_type, uint32_t subtable_length, uint32_t size);
> +bool fwts_acpi_structure_length_zero_check(fwts_framework *fw, const char *table, uint16_t length, uint32_t offset);
> +bool fwts_acpi_structure_range_check(fwts_framework *fw, const char *table, uint32_t table_length, uint32_t offset);
> +void fwts_acpi_structure_type_error(fwts_framework *fw, const char *table, uint8_t max_type, uint8_t type);
>  void fwts_acpi_fixed_value_check(fwts_framework *fw, fwts_log_level level, const char *table, const char *field, uint8_t actual, uint8_t must_be, bool *passed);
>  void fwts_acpi_space_id_check(fwts_framework *fw, const char *table, const char *field, bool *passed, uint8_t actual, uint8_t num_type, ...);
>  
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index dc42a8bd..45908c28 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -1738,6 +1738,68 @@ bool fwts_acpi_structure_length_check(
>  	return true;
>  }
>  
> +/*
> + *  fwts_acpi_structure_length_zero_check()
> + *  verify whether sub structure length is outside table
> + */
> +bool fwts_acpi_structure_length_zero_check(
> +	fwts_framework *fw,
> +	const char *table,
> +	uint16_t length,
> +	uint32_t offset)

length and offset can be made const


> +{
> +	if (length == 0) {
> +		char label[30];

I'd appreciate a blank line between variable declarations and statements.

> +		strncpy(label, table, 4);	/* ACPI name is 4 char long */
> +		strncpy(label + 4, "StructLengthZero", sizeof(label) - 4);
> +		fwts_failed(fw, LOG_LEVEL_CRITICAL, label,
> +			"%4.4s structure (offset 0x%4.4" PRIx32 ") "
> +			"length cannot be 0", table, offset);
> +		return true;
> +	}
> +	return false;
> +}
> +
> +/*
> + *  fwts_acpi_structure_range_check()
> + *  verify whether sub structure length is zero
> + */
> +bool fwts_acpi_structure_range_check(
> +	fwts_framework *fw,
> +	const char *table,
> +	uint32_t table_length,
> +	uint32_t offset)

table_length and offset can be made const

> +{
> +	if (offset > table_length) {
> +		char label[30];

..and blank line here

> +		strncpy(label, table, 4);	/* ACPI name is 4 char long */
> +		strncpy(label + 4, "BadTableLength", sizeof(label) - 4);
> +		fwts_failed(fw, LOG_LEVEL_CRITICAL, label,
> +			"%4.4s has more subtypes than its size can handle", table);
> +
> +		return true;
> +	}
> +	return false;
> +}
> +
> +/*
> + *  fwts_acpi_structure_type_range()
> + *  output failure for out-of-range type
> + */
> +void fwts_acpi_structure_type_error(
> +	fwts_framework *fw,
> +	const char *table,
> +	uint8_t max_type,
> +	uint8_t type)

max_type and type can be made const

> +{
> +	char label[30];

..and blank line here

> +	strncpy(label, table, 4);	/* ACPI name is 4 char long */
> +	strncpy(label + 4, "BadSubtableType", sizeof(label) - 4);
> +	fwts_failed(fw, LOG_LEVEL_HIGH, label,
> +		"%4.4s must have subtable with Type 0..%" PRId8
> +		" got %" PRId8 " instead", table, max_type, type);
> +}
> +
>  static uint32_t acpi_version;
>  /*
>   *  fwts_get_acpi_version()
> 




More information about the fwts-devel mailing list