[PATCH 1/2] fwts_acpi_object_eval: add a function to check buffer size
Alex Hung
alex.hung at canonical.com
Fri May 15 20:15:35 UTC 2020
Signed-off-by: Alex Hung <alex.hung at canonical.com>
---
src/lib/include/fwts_acpi_object_eval.h | 1 +
src/lib/src/fwts_acpi_object_eval.c | 23 ++++++++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/lib/include/fwts_acpi_object_eval.h b/src/lib/include/fwts_acpi_object_eval.h
index b13b5239..a8acec78 100644
--- a/src/lib/include/fwts_acpi_object_eval.h
+++ b/src/lib/include/fwts_acpi_object_eval.h
@@ -115,6 +115,7 @@ void fwts_method_passed_sane(fwts_framework *fw, const char *name, const char *t
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 char *objname, const ACPI_OBJECT *obj, const uint32_t min);
int fwts_method_package_count_equal(fwts_framework *fw, const char *name, const char *objname, const ACPI_OBJECT *obj, const uint32_t count);
int fwts_method_package_elements_all_type(fwts_framework *fw, const char *name, const char *objname, const ACPI_OBJECT *obj, const ACPI_OBJECT_TYPE type);
diff --git a/src/lib/src/fwts_acpi_object_eval.c b/src/lib/src/fwts_acpi_object_eval.c
index 12165b53..7f41fa52 100644
--- a/src/lib/src/fwts_acpi_object_eval.c
+++ b/src/lib/src/fwts_acpi_object_eval.c
@@ -575,7 +575,28 @@ bool fwts_method_type_matches(ACPI_OBJECT_TYPE t1, ACPI_OBJECT_TYPE t2)
}
/*
- * method_package_count_min()
+ * fwts_method_buffer_size()
+ * check whether buffer size is matched
+ */
+int fwts_method_buffer_size(
+ fwts_framework *fw,
+ const char *name,
+ ACPI_OBJECT *obj,
+ size_t buf_size)
+{
+ if (obj->Buffer.Length != buf_size) {
+ fwts_failed(fw, LOG_LEVEL_CRITICAL,
+ "MethodBadBufferSize",
+ "%s should return a buffer of %" PRIu64 " bytes, "
+ "but instead returned %" PRIu32 " bytes.",
+ name, buf_size, obj->Buffer.Length);
+ return FWTS_ERROR;
+ }
+ return FWTS_OK;
+}
+
+/*
+ * fwts_method_package_count_min()
* check that an ACPI package has at least 'min' elements
*/
int fwts_method_package_count_min(
--
2.25.1
More information about the fwts-devel
mailing list