diff mbox series

fwts_acpi_tables.h: constify read-only function arguments

Message ID 20210410222945.1089244-1-colin.king@canonical.com
State Superseded
Headers show
Series fwts_acpi_tables.h: constify read-only function arguments | expand

Commit Message

Colin Ian King April 10, 2021, 10:29 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Make read-only function arguments const. Also re-format prototypes in
header file fit into 80 columns.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/include/fwts_acpi_tables.h | 54 +++++++++++++++++++---------
 src/lib/src/fwts_acpi_tables.c     | 56 +++++++++++++++---------------
 2 files changed, 66 insertions(+), 44 deletions(-)

Comments

Alex Hung April 11, 2021, 8:50 p.m. UTC | #1
On 2021-04-10 4:29 p.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Make read-only function arguments const. Also re-format prototypes in
> header file fit into 80 columns.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts_acpi_tables.h | 54 +++++++++++++++++++---------
>  src/lib/src/fwts_acpi_tables.c     | 56 +++++++++++++++---------------
>  2 files changed, 66 insertions(+), 44 deletions(-)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index 7b62af8f..767f661f 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -52,7 +52,8 @@ typedef struct {
>  	fwts_acpi_table_provenance provenance;
>  } fwts_acpi_table_info;
>  
> -int acpi_table_generic_init(fwts_framework *fw, char *name, fwts_acpi_table_info **table);
> +int acpi_table_generic_init(fwts_framework *fw, const char *name,
> +	fwts_acpi_table_info **table);
>  
>  #define acpi_table_init(name, table)				\
>  static int name ## _init (fwts_framework *fw)			\
> @@ -63,25 +64,46 @@ static int name ## _init (fwts_framework *fw)			\
>  int fwts_acpi_load_tables(fwts_framework *fw);
>  int fwts_acpi_free_tables(void);
>  
> -int fwts_acpi_find_table(fwts_framework *fw, const char *name, const uint32_t which, fwts_acpi_table_info **info);
> -int fwts_acpi_find_table_by_addr(fwts_framework *fw, const uint64_t addr, fwts_acpi_table_info **info);
> -int fwts_acpi_get_table(fwts_framework *fw, const uint32_t index, fwts_acpi_table_info **info);
> +int fwts_acpi_find_table(fwts_framework *fw, const char *name,
> +	const uint32_t which, fwts_acpi_table_info **info);
> +int fwts_acpi_find_table_by_addr(fwts_framework *fw, const uint64_t addr,
> +	fwts_acpi_table_info **info);
> +int fwts_acpi_get_table(fwts_framework *fw, const uint32_t index,
> +	fwts_acpi_table_info **info);
>  bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
>  
>  fwts_bool fwts_acpi_is_reduced_hardware(fwts_framework *fw);
>  
> -void fwts_acpi_reserved_zero_check_(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
> -void fwts_acpi_reserved_zero_array_check(fwts_framework *fw, const char *table, const char *field, uint8_t* data, uint8_t length, bool *passed);
> -void fwts_acpi_reserved_bits_check_(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, uint8_t min, uint8_t max, bool *passed);
> -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, ...);
> -
> +void fwts_acpi_reserved_zero_check_(fwts_framework *fw, const char *table,
> +	const char *field, const uint64_t value, const uint8_t size,
> +	bool *passed);
> +void fwts_acpi_reserved_zero_array_check(fwts_framework *fw,
> +	const char *table, const char *field, const uint8_t* data,
> +	const uint8_t length, bool *passed);
> +void fwts_acpi_reserved_bits_check_(fwts_framework *fw, const char *table,
> +	const char *field, const uint64_t value, const uint8_t size,
> +	const uint8_t min, const uint8_t max, bool *passed);
> +void fwts_acpi_reserved_type_check(fwts_framework *fw, const char *table,
> +	const uint8_t value, const uint8_t min, const uint8_t reserved,
> +	bool *passed);
> +bool fwts_acpi_table_length_check(fwts_framework *fw, const char *table,
> +	const uint32_t length, const uint32_t size);
> +bool fwts_acpi_structure_length_check(fwts_framework *fw, const char *table,
> +	const uint8_t subtable_type, const uint32_t subtable_length,
> +	const uint32_t size);
> +bool fwts_acpi_structure_length_zero_check(fwts_framework *fw,
> +	const char *table, const uint16_t length, const uint32_t offset);
> +bool fwts_acpi_structure_range_check(fwts_framework *fw,
> +	const char *table, const uint32_t table_length, const uint32_t offset);
> +void fwts_acpi_structure_type_error(fwts_framework *fw,
> +	const char *table, const uint8_t max_type, const uint8_t type);

This patch won't apply because this "fwts_acpi_structure_type_error" was
in my previous patch "acpi: lib: add three helper functions".

I realized it is no needed and I am going to remove it in my V2 patch.


> +void fwts_acpi_fixed_value_check(fwts_framework *fw,
> +	const fwts_log_level level, const char *table,
> +	const char *field, const uint8_t actual, const uint8_t must_be,
> +	bool *passed);
> +void fwts_acpi_space_id_check(fwts_framework *fw, const char *table,
> +	const char *field, bool *passed, const uint8_t actual,
> +	const uint8_t num_type, ...);
>  uint32_t fwts_get_acpi_version(fwts_framework *fw);
>  
>  #endif
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 45908c28..ac3b9890 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -58,7 +58,7 @@ static acpi_table_load_state acpi_tables_loaded = ACPI_TABLES_NOT_LOADED;
>   *  acpi_table_generic_init()
>   *  	Generic ACPI table init function
>   */
> -int acpi_table_generic_init(fwts_framework *fw, char *name, fwts_acpi_table_info **table)
> +int acpi_table_generic_init(fwts_framework *fw, const char *name, fwts_acpi_table_info **table)
>  {
>  	if (fwts_acpi_find_table(fw, name, 0, table) != FWTS_OK) {
>  		fwts_log_error(fw, "Cannot read ACPI tables.");
> @@ -1431,8 +1431,8 @@ void fwts_acpi_reserved_zero_check_(
>  	fwts_framework *fw,
>  	const char *table,
>  	const char *field,
> -	uint64_t value,
> -	uint8_t size,
> +	const uint64_t value,
> +	const uint8_t size,
>  	bool *passed)
>  {
>  	if (value != 0) {
> @@ -1474,8 +1474,8 @@ void fwts_acpi_reserved_zero_array_check(
>  	fwts_framework *fw,
>  	const char *table,
>  	const char *field,
> -	uint8_t* data,
> -	uint8_t length,
> +	const uint8_t *data,
> +	const uint8_t length,
>  	bool *passed)
>  {
>  	uint32_t value = 0;
> @@ -1505,11 +1505,11 @@ void fwts_acpi_reserved_zero_array_check(
>   */
>  void fwts_acpi_fixed_value_check(
>  	fwts_framework *fw,
> -	fwts_log_level level,
> +	const fwts_log_level level,
>  	const char *table,
>  	const char *field,
> -	uint8_t actual,
> -	uint8_t must_be,
> +	const uint8_t actual,
> +	const uint8_t must_be,
>  	bool *passed)
>  {
>  	char label[20];
> @@ -1533,10 +1533,10 @@ void fwts_acpi_reserved_bits_check_(
>  	fwts_framework *fw,
>  	const char *table,
>  	const char *field,
> -	uint64_t value,
> -	uint8_t size,
> -	uint8_t min,
> -	uint8_t max,
> +	const uint64_t value,
> +	const uint8_t size,
> +	const uint8_t min,
> +	const uint8_t max,
>  	bool *passed)
>  {
>  	uint64_t mask = 0;
> @@ -1584,9 +1584,9 @@ void fwts_acpi_reserved_bits_check_(
>  void fwts_acpi_reserved_type_check(
>  	fwts_framework *fw,
>  	const char *table,
> -	uint8_t value,
> -	uint8_t min,
> -	uint8_t reserved,
> +	const uint8_t value,
> +	const uint8_t min,
> +	const uint8_t reserved,
>  	bool *passed)
>  {
>  	if (value < min || value >= reserved) {
> @@ -1641,8 +1641,8 @@ void fwts_acpi_space_id_check(
>  	const char *table,
>  	const char *field,
>  	bool *passed,
> -	uint8_t actual,
> -	uint8_t num_type,
> +	const uint8_t actual,
> +	const uint8_t num_type,
>  	...)
>  {
>  	bool matched = false;
> @@ -1698,8 +1698,8 @@ void fwts_acpi_space_id_check(
>  bool fwts_acpi_table_length_check(
>  	fwts_framework *fw,
>  	const char *table,
> -	uint32_t length,
> -	uint32_t size)
> +	const uint32_t length,
> +	const uint32_t size)
>  {
>  	if (length < size) {
>  		char label[30];
> @@ -1721,9 +1721,9 @@ bool fwts_acpi_table_length_check(
>  bool fwts_acpi_structure_length_check(
>  	fwts_framework *fw,
>  	const char *table,
> -	uint8_t type,
> -	uint32_t length,
> -	uint32_t size)
> +	const uint8_t type,
> +	const uint32_t length,
> +	const uint32_t size)
>  {
>  	if (length != size) {
>  		char label[30];
> @@ -1745,8 +1745,8 @@ bool fwts_acpi_structure_length_check(
>  bool fwts_acpi_structure_length_zero_check(
>  	fwts_framework *fw,
>  	const char *table,
> -	uint16_t length,
> -	uint32_t offset)
> +	const uint16_t length,
> +	const uint32_t offset)
>  {
>  	if (length == 0) {
>  		char label[30];
> @@ -1767,8 +1767,8 @@ bool fwts_acpi_structure_length_zero_check(
>  bool fwts_acpi_structure_range_check(
>  	fwts_framework *fw,
>  	const char *table,
> -	uint32_t table_length,
> -	uint32_t offset)
> +	const uint32_t table_length,
> +	const uint32_t offset)
>  {
>  	if (offset > table_length) {
>  		char label[30];
> @@ -1789,8 +1789,8 @@ bool fwts_acpi_structure_range_check(
>  void fwts_acpi_structure_type_error(
>  	fwts_framework *fw,
>  	const char *table,
> -	uint8_t max_type,
> -	uint8_t type)
> +	const uint8_t max_type,
> +	const uint8_t type)
>  {
>  	char label[30];
>  	strncpy(label, table, 4);	/* ACPI name is 4 char long */
>
diff mbox series

Patch

diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
index 7b62af8f..767f661f 100644
--- a/src/lib/include/fwts_acpi_tables.h
+++ b/src/lib/include/fwts_acpi_tables.h
@@ -52,7 +52,8 @@  typedef struct {
 	fwts_acpi_table_provenance provenance;
 } fwts_acpi_table_info;
 
-int acpi_table_generic_init(fwts_framework *fw, char *name, fwts_acpi_table_info **table);
+int acpi_table_generic_init(fwts_framework *fw, const char *name,
+	fwts_acpi_table_info **table);
 
 #define acpi_table_init(name, table)				\
 static int name ## _init (fwts_framework *fw)			\
@@ -63,25 +64,46 @@  static int name ## _init (fwts_framework *fw)			\
 int fwts_acpi_load_tables(fwts_framework *fw);
 int fwts_acpi_free_tables(void);
 
-int fwts_acpi_find_table(fwts_framework *fw, const char *name, const uint32_t which, fwts_acpi_table_info **info);
-int fwts_acpi_find_table_by_addr(fwts_framework *fw, const uint64_t addr, fwts_acpi_table_info **info);
-int fwts_acpi_get_table(fwts_framework *fw, const uint32_t index, fwts_acpi_table_info **info);
+int fwts_acpi_find_table(fwts_framework *fw, const char *name,
+	const uint32_t which, fwts_acpi_table_info **info);
+int fwts_acpi_find_table_by_addr(fwts_framework *fw, const uint64_t addr,
+	fwts_acpi_table_info **info);
+int fwts_acpi_get_table(fwts_framework *fw, const uint32_t index,
+	fwts_acpi_table_info **info);
 bool fwts_acpi_obj_find(fwts_framework *fw, const char *obj_name);
 
 fwts_bool fwts_acpi_is_reduced_hardware(fwts_framework *fw);
 
-void fwts_acpi_reserved_zero_check_(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, bool *passed);
-void fwts_acpi_reserved_zero_array_check(fwts_framework *fw, const char *table, const char *field, uint8_t* data, uint8_t length, bool *passed);
-void fwts_acpi_reserved_bits_check_(fwts_framework *fw, const char *table, const char *field, uint64_t value, uint8_t size, uint8_t min, uint8_t max, bool *passed);
-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, ...);
-
+void fwts_acpi_reserved_zero_check_(fwts_framework *fw, const char *table,
+	const char *field, const uint64_t value, const uint8_t size,
+	bool *passed);
+void fwts_acpi_reserved_zero_array_check(fwts_framework *fw,
+	const char *table, const char *field, const uint8_t* data,
+	const uint8_t length, bool *passed);
+void fwts_acpi_reserved_bits_check_(fwts_framework *fw, const char *table,
+	const char *field, const uint64_t value, const uint8_t size,
+	const uint8_t min, const uint8_t max, bool *passed);
+void fwts_acpi_reserved_type_check(fwts_framework *fw, const char *table,
+	const uint8_t value, const uint8_t min, const uint8_t reserved,
+	bool *passed);
+bool fwts_acpi_table_length_check(fwts_framework *fw, const char *table,
+	const uint32_t length, const uint32_t size);
+bool fwts_acpi_structure_length_check(fwts_framework *fw, const char *table,
+	const uint8_t subtable_type, const uint32_t subtable_length,
+	const uint32_t size);
+bool fwts_acpi_structure_length_zero_check(fwts_framework *fw,
+	const char *table, const uint16_t length, const uint32_t offset);
+bool fwts_acpi_structure_range_check(fwts_framework *fw,
+	const char *table, const uint32_t table_length, const uint32_t offset);
+void fwts_acpi_structure_type_error(fwts_framework *fw,
+	const char *table, const uint8_t max_type, const uint8_t type);
+void fwts_acpi_fixed_value_check(fwts_framework *fw,
+	const fwts_log_level level, const char *table,
+	const char *field, const uint8_t actual, const uint8_t must_be,
+	bool *passed);
+void fwts_acpi_space_id_check(fwts_framework *fw, const char *table,
+	const char *field, bool *passed, const uint8_t actual,
+	const uint8_t num_type, ...);
 uint32_t fwts_get_acpi_version(fwts_framework *fw);
 
 #endif
diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 45908c28..ac3b9890 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -58,7 +58,7 @@  static acpi_table_load_state acpi_tables_loaded = ACPI_TABLES_NOT_LOADED;
  *  acpi_table_generic_init()
  *  	Generic ACPI table init function
  */
-int acpi_table_generic_init(fwts_framework *fw, char *name, fwts_acpi_table_info **table)
+int acpi_table_generic_init(fwts_framework *fw, const char *name, fwts_acpi_table_info **table)
 {
 	if (fwts_acpi_find_table(fw, name, 0, table) != FWTS_OK) {
 		fwts_log_error(fw, "Cannot read ACPI tables.");
@@ -1431,8 +1431,8 @@  void fwts_acpi_reserved_zero_check_(
 	fwts_framework *fw,
 	const char *table,
 	const char *field,
-	uint64_t value,
-	uint8_t size,
+	const uint64_t value,
+	const uint8_t size,
 	bool *passed)
 {
 	if (value != 0) {
@@ -1474,8 +1474,8 @@  void fwts_acpi_reserved_zero_array_check(
 	fwts_framework *fw,
 	const char *table,
 	const char *field,
-	uint8_t* data,
-	uint8_t length,
+	const uint8_t *data,
+	const uint8_t length,
 	bool *passed)
 {
 	uint32_t value = 0;
@@ -1505,11 +1505,11 @@  void fwts_acpi_reserved_zero_array_check(
  */
 void fwts_acpi_fixed_value_check(
 	fwts_framework *fw,
-	fwts_log_level level,
+	const fwts_log_level level,
 	const char *table,
 	const char *field,
-	uint8_t actual,
-	uint8_t must_be,
+	const uint8_t actual,
+	const uint8_t must_be,
 	bool *passed)
 {
 	char label[20];
@@ -1533,10 +1533,10 @@  void fwts_acpi_reserved_bits_check_(
 	fwts_framework *fw,
 	const char *table,
 	const char *field,
-	uint64_t value,
-	uint8_t size,
-	uint8_t min,
-	uint8_t max,
+	const uint64_t value,
+	const uint8_t size,
+	const uint8_t min,
+	const uint8_t max,
 	bool *passed)
 {
 	uint64_t mask = 0;
@@ -1584,9 +1584,9 @@  void fwts_acpi_reserved_bits_check_(
 void fwts_acpi_reserved_type_check(
 	fwts_framework *fw,
 	const char *table,
-	uint8_t value,
-	uint8_t min,
-	uint8_t reserved,
+	const uint8_t value,
+	const uint8_t min,
+	const uint8_t reserved,
 	bool *passed)
 {
 	if (value < min || value >= reserved) {
@@ -1641,8 +1641,8 @@  void fwts_acpi_space_id_check(
 	const char *table,
 	const char *field,
 	bool *passed,
-	uint8_t actual,
-	uint8_t num_type,
+	const uint8_t actual,
+	const uint8_t num_type,
 	...)
 {
 	bool matched = false;
@@ -1698,8 +1698,8 @@  void fwts_acpi_space_id_check(
 bool fwts_acpi_table_length_check(
 	fwts_framework *fw,
 	const char *table,
-	uint32_t length,
-	uint32_t size)
+	const uint32_t length,
+	const uint32_t size)
 {
 	if (length < size) {
 		char label[30];
@@ -1721,9 +1721,9 @@  bool fwts_acpi_table_length_check(
 bool fwts_acpi_structure_length_check(
 	fwts_framework *fw,
 	const char *table,
-	uint8_t type,
-	uint32_t length,
-	uint32_t size)
+	const uint8_t type,
+	const uint32_t length,
+	const uint32_t size)
 {
 	if (length != size) {
 		char label[30];
@@ -1745,8 +1745,8 @@  bool fwts_acpi_structure_length_check(
 bool fwts_acpi_structure_length_zero_check(
 	fwts_framework *fw,
 	const char *table,
-	uint16_t length,
-	uint32_t offset)
+	const uint16_t length,
+	const uint32_t offset)
 {
 	if (length == 0) {
 		char label[30];
@@ -1767,8 +1767,8 @@  bool fwts_acpi_structure_length_zero_check(
 bool fwts_acpi_structure_range_check(
 	fwts_framework *fw,
 	const char *table,
-	uint32_t table_length,
-	uint32_t offset)
+	const uint32_t table_length,
+	const uint32_t offset)
 {
 	if (offset > table_length) {
 		char label[30];
@@ -1789,8 +1789,8 @@  bool fwts_acpi_structure_range_check(
 void fwts_acpi_structure_type_error(
 	fwts_framework *fw,
 	const char *table,
-	uint8_t max_type,
-	uint8_t type)
+	const uint8_t max_type,
+	const uint8_t type)
 {
 	char label[30];
 	strncpy(label, table, 4);	/* ACPI name is 4 char long */