From patchwork Sat Apr 10 23:09:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 1464717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FHrLb1CKTz9sW1 for ; Sun, 11 Apr 2021 09:09:58 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1lVMji-00075m-9t; Sat, 10 Apr 2021 23:09:54 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lVMjd-00075g-UW for fwts-devel@lists.ubuntu.com; Sat, 10 Apr 2021 23:09:49 +0000 Received: from cpc154979-craw9-2-0-cust193.16-3.cable.virginm.net ([80.193.200.194] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lVMjd-00040d-KK; Sat, 10 Apr 2021 23:09:49 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] fwts_acpi_object_eval.h: constify read-only function arguments Date: Sun, 11 Apr 2021 00:09:49 +0100 Message-Id: <20210410230949.1125552-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" From: Colin Ian King Make read-only function arguments const. Also re-format prototypes in header file fit into 80 columns. Clean up some macro indentations. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- src/lib/include/fwts_acpi_object_eval.h | 181 ++++++++++++++++-------- src/lib/src/fwts_acpi_object_eval.c | 33 +++-- 2 files changed, 140 insertions(+), 74 deletions(-) diff --git a/src/lib/include/fwts_acpi_object_eval.h b/src/lib/include/fwts_acpi_object_eval.h index 32c8f6bf..b818146e 100644 --- a/src/lib/include/fwts_acpi_object_eval.h +++ b/src/lib/include/fwts_acpi_object_eval.h @@ -32,12 +32,14 @@ int fwts_acpi_deinit(fwts_framework *fw); char *fwts_acpi_object_exists(const char *name); fwts_list *fwts_acpi_object_get_names(void); void fwts_acpi_object_dump(fwts_framework *fw, const ACPI_OBJECT *obj); -void fwts_acpi_object_evaluate_report_error(fwts_framework *fw, const char *name, const ACPI_STATUS status); -ACPI_STATUS fwts_acpi_object_evaluate(fwts_framework *fw, char *name, ACPI_OBJECT_LIST *arg_list, ACPI_BUFFER *buf); +void fwts_acpi_object_evaluate_report_error(fwts_framework *fw, + const char *name, const ACPI_STATUS status); +ACPI_STATUS fwts_acpi_object_evaluate(fwts_framework *fw, char *name, + ACPI_OBJECT_LIST *arg_list, ACPI_BUFFER *buf); /* Test types */ #define METHOD_MANDATORY 1 -#define METHOD_OPTIONAL 2 +#define METHOD_OPTIONAL 2 #define METHOD_MOBILE 4 #define METHOD_SILENT 8 @@ -112,43 +114,83 @@ typedef struct { #define fwts_method_package_elements_type(fw, name, obj, info) \ fwts_method_package_elements_type__(fw, name, obj, info, FWTS_ARRAY_SIZE(info)) -int fwts_method_check_type__(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT_TYPE type, char *type_name); -int fwts_method_check_element_type(fwts_framework *fw, const char *name, ACPI_OBJECT *obj, uint32_t subpkg, uint32_t element, ACPI_OBJECT_TYPE type); +int fwts_method_check_type__(fwts_framework *fw, const char *name, + const ACPI_BUFFER *buf, const ACPI_OBJECT_TYPE type, + const char *type_name); +int fwts_method_check_element_type(fwts_framework *fw, const char *name, + const ACPI_OBJECT *obj, const uint32_t subpkg, + const uint32_t element, const ACPI_OBJECT_TYPE type); const char *fwts_method_type_name(const ACPI_OBJECT_TYPE type); -void fwts_method_passed_sane(fwts_framework *fw, const char *name, const char *type); -void fwts_method_passed_sane_uint64(fwts_framework *fw, const char *name, const uint64_t value); -void fwts_method_failed_null_object(fwts_framework *fw, const char *name, const char *type); -bool fwts_method_type_matches(ACPI_OBJECT_TYPE t1, ACPI_OBJECT_TYPE t2); -int fwts_method_buffer_size(fwts_framework *fw, const char *name, ACPI_OBJECT *obj, size_t buf_size); -int fwts_method_package_count_min(fwts_framework *fw, const char *name, const ACPI_OBJECT *obj, const uint32_t min); -int fwts_method_package_count_equal(fwts_framework *fw, const char *name, const ACPI_OBJECT *obj, const uint32_t count); -int fwts_method_subpackage_count_equal(fwts_framework *fw, const char *name, const ACPI_OBJECT *obj, const uint32_t sub, const uint32_t count); -int fwts_method_package_elements_all_type(fwts_framework *fw, const char *name, const ACPI_OBJECT *obj, const ACPI_OBJECT_TYPE type); -int fwts_method_package_elements_type__(fwts_framework *fw, const char *name, const ACPI_OBJECT *obj, const fwts_package_element *info, const uint32_t count); -int fwts_method_test_revision(fwts_framework *fw, const char *name, const uint32_t cur_revision, const uint32_t spec_revision); - -void fwts_method_test_integer_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_string_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_reference_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_NULL_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_buffer_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj,void *private); -void fwts_method_test_all_reference_package_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_integer_reserved_bits_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_integer_max_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_package_integer_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_passed_failed_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_polling_return( fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); - -void method_evaluate_found_method(fwts_framework *fw, char *name, fwts_method_return check_func, void *private, ACPI_OBJECT_LIST *arg_list); -void fwts_evaluate_found_method(fwts_framework *fw, ACPI_HANDLE *parent, char *name, fwts_method_return check_func, void *private, ACPI_OBJECT_LIST *arg_list); -int fwts_evaluate_method(fwts_framework *fw, uint32_t test_type, ACPI_HANDLE *parent, char *name, ACPI_OBJECT *args, uint32_t num_args, fwts_method_return check_func, void *private); - -bool fwts_method_valid_HID_string(char *str); -bool fwts_method_valid_EISA_ID(uint32_t id, char *buf, size_t buf_len); - -void fwts_method_test_CRS_large_size( fwts_framework *fw, const char *name, const char *objname, const uint8_t *data, const size_t crs_length, const size_t min, const size_t max, bool *passed); -void fwts_method_test_CRS_large_resource_items(fwts_framework *fw, const char *name, const char *objname, const uint8_t *data, const uint64_t length, bool *passed, const char **tag); -void fwts_method_test_CRS_small_resource_items(fwts_framework *fw, const char *name, const char *objname, const uint8_t *data, const size_t length, bool *passed, const char **tag) ; +void fwts_method_passed_sane(fwts_framework *fw, const char *name, + const char *type); +void fwts_method_passed_sane_uint64(fwts_framework *fw, const char *name, + const uint64_t value); +void fwts_method_failed_null_object(fwts_framework *fw, const char *name, + const char *type); +bool fwts_method_type_matches(const ACPI_OBJECT_TYPE t1, + const ACPI_OBJECT_TYPE t2); +int fwts_method_buffer_size(fwts_framework *fw, const char *name, + const ACPI_OBJECT *obj, const size_t buf_size); +int fwts_method_package_count_min(fwts_framework *fw, const char *name, + const ACPI_OBJECT *obj, const uint32_t min); +int fwts_method_package_count_equal(fwts_framework *fw, const char *name, + const ACPI_OBJECT *obj, const uint32_t count); +int fwts_method_subpackage_count_equal(fwts_framework *fw, const char *name, + const ACPI_OBJECT *obj, const uint32_t sub, const uint32_t count); +int fwts_method_package_elements_all_type(fwts_framework *fw, + const char *name, const ACPI_OBJECT *obj, const ACPI_OBJECT_TYPE type); +int fwts_method_package_elements_type__(fwts_framework *fw, const char *name, + const ACPI_OBJECT *obj, const fwts_package_element *info, + const uint32_t count); +int fwts_method_test_revision(fwts_framework *fw, const char *name, + const uint32_t cur_revision, const uint32_t spec_revision); + +void fwts_method_test_integer_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_string_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_reference_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_NULL_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_buffer_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj,void *private); +void fwts_method_test_all_reference_package_return(fwts_framework *fw, + char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_integer_reserved_bits_return(fwts_framework *fw, + char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_integer_max_return(fwts_framework *fw, + char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_package_integer_return(fwts_framework *fw, + char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_passed_failed_return(fwts_framework *fw, + char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_polling_return( fwts_framework *fw, + char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); + +void method_evaluate_found_method(fwts_framework *fw, + char *name, fwts_method_return check_func, void *private, + ACPI_OBJECT_LIST *arg_list); +void fwts_evaluate_found_method(fwts_framework *fw, ACPI_HANDLE *parent, + char *name, fwts_method_return check_func, void *private, + ACPI_OBJECT_LIST *arg_list); +int fwts_evaluate_method(fwts_framework *fw, const uint32_t test_type, + ACPI_HANDLE *parent, char *name, ACPI_OBJECT *args, + uint32_t num_args, fwts_method_return check_func, void *private); + +bool fwts_method_valid_HID_string(const char *str); +bool fwts_method_valid_EISA_ID(const uint32_t id, char *buf, + const size_t buf_len); + +void fwts_method_test_CRS_large_size(fwts_framework *fw, const char *name, + const char *objname, const uint8_t *data, const size_t crs_length, + const size_t min, const size_t max, bool *passed); +void fwts_method_test_CRS_large_resource_items(fwts_framework *fw, + const char *name, const char *objname, const uint8_t *data, + const uint64_t length, bool *passed, const char **tag); +void fwts_method_test_CRS_small_resource_items(fwts_framework *fw, + const char *name, const char *objname, const uint8_t *data, + const size_t length, bool *passed, const char **tag) ; /* Device Identification Objects - see Section 6 Device Configuration */ int fwts_method_test_ADR(fwts_framework *fw, ACPI_HANDLE *device); @@ -164,26 +206,45 @@ int fwts_method_test_SUN(fwts_framework *fw, ACPI_HANDLE *device); int fwts_method_test_STR(fwts_framework *fw, ACPI_HANDLE *device); int fwts_method_test_UID(fwts_framework *fw, ACPI_HANDLE *device); -void fwts_method_test_BMD_return(fwts_framework *fw, char *name,ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_BPC_return(fwts_framework *fw, char *name,ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_BPS_return(fwts_framework *fw, char *name,ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_valid_CID_Type(fwts_framework *fw, char *name, ACPI_OBJECT *obj); -void fwts_method_test_CID_return(fwts_framework *fw, char *name,ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_HID_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_MLS_return( fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_PLD_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_SUB_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_UID_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); - -void fwts_method_test_NBS_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_NCH_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_NIC_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_NIH_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_NIG_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); - -void fwts_method_test_STA_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_BIF_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_BIX_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); -void fwts_method_test_BST_return(fwts_framework *fw, char *name, ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_BMD_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_BPC_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_BPS_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_valid_CID_Type(fwts_framework *fw, char *name, + ACPI_OBJECT *obj); +void fwts_method_test_CID_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_HID_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_MLS_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_PLD_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_SUB_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_UID_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); + +void fwts_method_test_NBS_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_NCH_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_NIC_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_NIH_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_NIG_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); + +void fwts_method_test_STA_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_BIF_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_BIX_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); +void fwts_method_test_BST_return(fwts_framework *fw, char *name, + ACPI_BUFFER *buf, ACPI_OBJECT *obj, void *private); #endif diff --git a/src/lib/src/fwts_acpi_object_eval.c b/src/lib/src/fwts_acpi_object_eval.c index 020ff3c5..36b92734 100644 --- a/src/lib/src/fwts_acpi_object_eval.c +++ b/src/lib/src/fwts_acpi_object_eval.c @@ -474,10 +474,10 @@ ACPI_STATUS fwts_acpi_object_evaluate(fwts_framework *fw, int fwts_method_check_type__( fwts_framework *fw, - char *name, - ACPI_BUFFER *buf, - ACPI_OBJECT_TYPE type, - char *type_name) + const char *name, + const ACPI_BUFFER *buf, + const ACPI_OBJECT_TYPE type, + const char *type_name) { ACPI_OBJECT *obj; @@ -548,10 +548,10 @@ static const char *acpi_object_names[] = { int fwts_method_check_element_type( fwts_framework *fw, const char *name, - ACPI_OBJECT *obj, - uint32_t subpkg, - uint32_t element, - ACPI_OBJECT_TYPE type) + const ACPI_OBJECT *obj, + const uint32_t subpkg, + const uint32_t element, + const ACPI_OBJECT_TYPE type) { if (obj->Package.Elements[element].Type != type) { char obj_name[5] = "_XYZ"; @@ -642,7 +642,9 @@ void fwts_method_failed_null_object( "return %s.", name, type); } -bool fwts_method_type_matches(ACPI_OBJECT_TYPE t1, ACPI_OBJECT_TYPE t2) +bool fwts_method_type_matches( + const ACPI_OBJECT_TYPE t1, + const ACPI_OBJECT_TYPE t2) { if (t1 == ACPI_TYPE_INTBUF && (t2 == ACPI_TYPE_INTEGER || t2 == ACPI_TYPE_BUFFER)) @@ -662,8 +664,8 @@ bool fwts_method_type_matches(ACPI_OBJECT_TYPE t1, ACPI_OBJECT_TYPE t2) int fwts_method_buffer_size( fwts_framework *fw, const char *name, - ACPI_OBJECT *obj, - size_t buf_size) + const ACPI_OBJECT *obj, + const size_t buf_size) { if (obj->Buffer.Length != buf_size) { fwts_failed(fw, LOG_LEVEL_CRITICAL, @@ -1176,7 +1178,7 @@ void fwts_evaluate_found_method( } int fwts_evaluate_method(fwts_framework *fw, - uint32_t test_type, /* Manditory or optional */ + const uint32_t test_type, /* Manditory or optional */ ACPI_HANDLE *parent, char *name, ACPI_OBJECT *args, @@ -1210,7 +1212,7 @@ int fwts_evaluate_method(fwts_framework *fw, return FWTS_OK; } -bool fwts_method_valid_HID_string(char *str) +bool fwts_method_valid_HID_string(const char *str) { if (strlen(str) == 7) { /* PNP ID, must be 3 capitals followed by 4 hex */ @@ -1240,7 +1242,10 @@ bool fwts_method_valid_HID_string(char *str) return false; } -bool fwts_method_valid_EISA_ID(uint32_t id, char *buf, size_t buf_len) +bool fwts_method_valid_EISA_ID( + const uint32_t id, + char *buf, + const size_t buf_len) { snprintf(buf, buf_len, "%c%c%c%02" PRIX32 "%02" PRIX32, 0x40 + ((id >> 2) & 0x1f),