ACK: [PATCH 4/4] acpi: method: check fixed package by fwts_method_package_elements_type

Colin Ian King colin.king at canonical.com
Thu Jan 21 17:42:48 UTC 2021


On 20/01/2021 23:23, Alex Hung wrote:
> Also include count check (fwts_method_package_count_equal) in
> fwts_method_package_elements_type
> 
> Signed-off-by: Alex Hung <alex.hung at canonical.com>
> ---
>  src/acpi/method/method.c            | 83 +++++++++++++++--------------
>  src/lib/src/fwts_acpi_object_eval.c | 23 ++++----
>  2 files changed, 52 insertions(+), 54 deletions(-)
> 
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index f4b24bb1..b018b733 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -1553,15 +1553,16 @@ static void method_test_PRR_return(
>  	ACPI_OBJECT *obj,
>  	void *private)
>  {
> +	static const fwts_package_element elements[] = {
> +		{ ACPI_TYPE_LOCAL_REFERENCE,	"Power Reset Resource" },
> +	};
> +
>  	FWTS_UNUSED(private);
>  
>  	if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_PACKAGE) != FWTS_OK)
>  		return;
>  
> -	if (fwts_method_package_count_equal(fw, name, obj, 1) != FWTS_OK)
> -		return;
> -
> -	if (fwts_method_package_elements_all_type(fw, name, obj, ACPI_TYPE_LOCAL_REFERENCE) != FWTS_OK)
> +	if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  		return;
>  
>  	fwts_method_passed_sane(fw, name, "package");
> @@ -2097,17 +2098,17 @@ static void method_test_PCT_return(
>  	ACPI_OBJECT *obj,
>  	void *private)
>  {
> +	static const fwts_package_element elements[] = {
> +		{ ACPI_TYPE_BUFFER,	"ControlRegister" },
> +		{ ACPI_TYPE_BUFFER,	"StatusRegister" },
> +	};
> +
>  	FWTS_UNUSED(private);
>  
>  	if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_PACKAGE) != FWTS_OK)
>  		return;
>  
> -	/* Something is really wrong if we don't have any elements in _PCT */
> -	if (fwts_method_package_count_min(fw, name, obj, 2) != FWTS_OK)
> -		return;
> -
> -	if (fwts_method_package_elements_all_type(fw, name,
> -		obj, ACPI_TYPE_BUFFER) != FWTS_OK)
> +	if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  		return;
>  
>  	fwts_method_passed_sane(fw, name, "package");
> @@ -3079,15 +3080,19 @@ static void method_test_UPC_return(
>  {
>  	uint32_t i, connector_type;
>  
> +	static const fwts_package_element elements[] = {
> +		{ ACPI_TYPE_INTEGER,	"Connectable" },
> +		{ ACPI_TYPE_INTEGER,	"Type" },
> +		{ ACPI_TYPE_INTEGER,	"Reserved0" },
> +		{ ACPI_TYPE_INTEGER,	"Reserved1" },
> +	};
> +
>  	FWTS_UNUSED(private);
>  
>  	if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_PACKAGE) != FWTS_OK)
>  		return;
>  
> -	if (fwts_method_package_count_equal(fw, name, obj, 4) != FWTS_OK)
> -		return;
> -
> -	if (fwts_method_package_elements_all_type(fw, name, obj, ACPI_TYPE_INTEGER) != FWTS_OK)
> +	if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  		return;
>  
>  	connector_type = obj->Package.Elements[1].Integer.Value;
> @@ -3612,38 +3617,34 @@ static void method_test_PMC_return(
>  	ACPI_OBJECT *obj,
>  	void *private)
>  {
> -	uint32_t i;
>  	bool failed = false;
>  	ACPI_OBJECT *element;
>  
> +	static const fwts_package_element elements[] = {
> +		{ ACPI_TYPE_INTEGER,	"Supported Capabilities" },
> +		{ ACPI_TYPE_INTEGER,	"Measurement" },
> +		{ ACPI_TYPE_INTEGER,	"Measurement Type" },
> +		{ ACPI_TYPE_INTEGER,	"Measurement Accuracy" },
> +		{ ACPI_TYPE_INTEGER,	"Measurement Sampling Time" },
> +		{ ACPI_TYPE_INTEGER,	"Minimum Averaging Interval" },
> +		{ ACPI_TYPE_INTEGER,	"Maximum Averaging Interval" },
> +		{ ACPI_TYPE_INTEGER,	"Hysteresis Margin" },
> +		{ ACPI_TYPE_INTEGER,	"Hardware Limit Is Configurable" },
> +		{ ACPI_TYPE_INTEGER,	"Min Configurable Hardware Limit" },
> +		{ ACPI_TYPE_INTEGER,	"Max Configurable Hardware Limit" },
> +		{ ACPI_TYPE_STRING,	"Model Number" },
> +		{ ACPI_TYPE_STRING,	"Serial Number" },
> +		{ ACPI_TYPE_STRING,	"OEM Information" },
> +	};
> +
>  	FWTS_UNUSED(private);
>  
>  	if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_PACKAGE) != FWTS_OK)
>  		return;
>  
> -	if (fwts_method_package_count_equal(fw, name, obj, 14) != FWTS_OK)
> +	if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  		return;
>  
> -	/* check element types */
> -	for (i = 0; i < 14; i++) {
> -		element = &obj->Package.Elements[i];
> -		if (i > 10) {
> -			if (element->Type != ACPI_TYPE_STRING) {
> -				fwts_failed(fw, LOG_LEVEL_MEDIUM,
> -					"Method_PMCBadElementType",
> -					"%s element %" PRIu32 " is not a string.", name, i);
> -				failed = true;
> -			}
> -		} else {
> -				if (element->Type != ACPI_TYPE_INTEGER) {
> -					fwts_failed(fw, LOG_LEVEL_MEDIUM,
> -						"Method_PMCBadElementType",
> -						"%s element %" PRIu32 " is not an integer.", name, i);
> -					failed = true;
> -				}
> -		}
> -	}
> -
>  	/* check element's constraints */
>  	element = &obj->Package.Elements[0];
>  	if (element->Integer.Value & 0xFFFFFEF0) {
> @@ -4356,15 +4357,17 @@ static void method_test_WAK_return(
>  	ACPI_OBJECT *obj,
>  	void *private)
>  {
> +	static const fwts_package_element elements[] = {
> +		{ ACPI_TYPE_INTEGER,	"Wake Signal" },
> +		{ ACPI_TYPE_INTEGER,	"Power Supply S-state" },
> +	};
> +
>  	FWTS_UNUSED(private);
>  	FWTS_UNUSED(buf);
>  
>  	switch (obj->Type) {
>  	case ACPI_TYPE_PACKAGE:
> -		if (fwts_method_package_count_equal(fw, name, obj, 2) != FWTS_OK)
> -			return;
> -
> -		if (fwts_method_package_elements_all_type(fw, name, obj, ACPI_TYPE_INTEGER) != FWTS_OK)
> +		if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  			return;
>  
>  		fwts_method_passed_sane(fw, name, "package");
> diff --git a/src/lib/src/fwts_acpi_object_eval.c b/src/lib/src/fwts_acpi_object_eval.c
> index fbca0d46..74ce9429 100644
> --- a/src/lib/src/fwts_acpi_object_eval.c
> +++ b/src/lib/src/fwts_acpi_object_eval.c
> @@ -799,7 +799,7 @@ int fwts_method_package_elements_type__(
>  	bool failed = false;
>  	char tmp[128];
>  
> -	if (obj->Package.Count != count)
> +	if (fwts_method_package_count_equal(fw, name, obj, count) != FWTS_OK)
>  		return FWTS_ERROR;
>  
>  	for (i = 0; i < obj->Package.Count; i++) {
> @@ -2709,9 +2709,6 @@ void fwts_method_test_BIF_return(
>  	if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_PACKAGE) != FWTS_OK)
>  		return;
>  
> -	if (fwts_method_package_count_equal(fw, name, obj, 13) != FWTS_OK)
> -		return;
> -
>  	if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  		return;
>  
> @@ -2872,16 +2869,10 @@ void fwts_method_test_BIX_return(
>  
>  	switch (revision) {
>  	case 0:
> -		if (fwts_method_package_count_equal(fw, name, obj, 20) != FWTS_OK)
> -			return;
> -
>  		if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  			return;
>  		break;
>  	case 1:
> -		if (fwts_method_package_count_equal(fw, name, obj, 21) != FWTS_OK)
> -			return;
> -
>  		if (fwts_method_package_elements_type(fw, name, obj, elements_v1) != FWTS_OK)
>  			return;
>  		break;
> @@ -3024,15 +3015,19 @@ void fwts_method_test_BST_return(
>  {
>  	bool failed = false;
>  
> +	static const fwts_package_element elements[] = {
> +		{ ACPI_TYPE_INTEGER,	"Battery State" },
> +		{ ACPI_TYPE_INTEGER,	"Battery Rate" },
> +		{ ACPI_TYPE_INTEGER,	"Battery Remaining Capacity" },
> +		{ ACPI_TYPE_INTEGER,	"Battery Present Voltage" },
> +	};
> +
>  	FWTS_UNUSED(private);
>  
>  	if (fwts_method_check_type(fw, name, buf, ACPI_TYPE_PACKAGE) != FWTS_OK)
>  		return;
>  
> -	if (fwts_method_package_count_equal(fw, name, obj, 4) != FWTS_OK)
> -		return;
> -
> -	if (fwts_method_package_elements_all_type(fw, name, obj, ACPI_TYPE_INTEGER) != FWTS_OK)
> +	if (fwts_method_package_elements_type(fw, name, obj, elements) != FWTS_OK)
>  		return;
>  
>  	/* Sanity check each field */
> 
Acked-by: Colin Ian King <colin.king at canonical.com>



More information about the fwts-devel mailing list