lib: fwts_acpi_table: make indexes which and index uint32_t

Message ID 20170908082600.5165-1-colin.king@canonical.com
State Accepted
Headers show
Series
  • lib: fwts_acpi_table: make indexes which and index uint32_t
Related show

Commit Message

Colin King Sept. 8, 2017, 8:26 a.m.
From: Colin Ian King <colin.king@canonical.com>

Theses indexes should never go below zero, so make them uint32_t. This
also allows us to remove a less than zero range check.

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

Comments

Alex Hung Sept. 11, 2017, 4:50 p.m. | #1
On 2017-09-08 01:26 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Theses indexes should never go below zero, so make them uint32_t. This
> also allows us to remove a less than zero range check.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/include/fwts_acpi_tables.h | 16 ++++++++--------
>   src/lib/src/fwts_acpi_tables.c     | 12 ++++++++----
>   2 files changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index d478d99a..035060eb 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -33,22 +33,22 @@ typedef enum {
>   } fwts_acpi_table_provenance;
>   
>   typedef struct {
> -	char    name[5];
> +	char	   name[5];
>   	const void *data;
> -	size_t	length;
> -	int 	which;
> -	int	index;
> -	bool	has_aml;
> -	uint64_t addr;
> +	size_t	   length;
> +	uint32_t   which;
> +	uint32_t   index;
> +	bool	   has_aml;
> +	uint64_t   addr;
>   	fwts_acpi_table_provenance provenance;
>   } fwts_acpi_table_info;
>   
>   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 int which, 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 int index, 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(const fwts_acpi_table_fadt *fadt);
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 4ac70f81..0a639da0 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -235,7 +235,7 @@ static void fwts_acpi_add_table(
>   						/* Where we got the table from */
>   {
>   	int i;
> -	int which = 0;
> +	uint32_t which = 0;
>   
>   	for (i = 0; i < ACPI_MAX_TABLES; i++) {
>   		if (addr && tables[i].addr == addr) {
> @@ -1237,7 +1237,11 @@ int fwts_acpi_load_tables(fwts_framework *fw)
>    *  	Search for an ACPI table. There may be more than one, so
>    *  	specify the one using which.
>    */
> -int fwts_acpi_find_table(fwts_framework *fw, const char *name, const int which, 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 i;
>   
> @@ -1302,14 +1306,14 @@ int fwts_acpi_find_table_by_addr(fwts_framework *fw, const uint64_t addr, fwts_a
>    *  fwts_acpi_get_table()
>    *  	Get the Nth cached ACPI table.
>    */
> -int fwts_acpi_get_table(fwts_framework *fw, const int index, fwts_acpi_table_info **info)
> +int fwts_acpi_get_table(fwts_framework *fw, const uint32_t index, fwts_acpi_table_info **info)
>   {
>   	if (info == NULL)
>   		return FWTS_NULL_POINTER;
>   
>   	*info = NULL;
>   
> -	if ((index < 0) || (index >= ACPI_MAX_TABLES))
> +	if (index >= ACPI_MAX_TABLES)
>   		return FWTS_ERROR;
>   
>   	if (acpi_tables_loaded == ACPI_TABLES_NOT_LOADED) {
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu Sept. 21, 2017, 8:37 a.m. | #2
On 09/08/2017 04:26 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Theses indexes should never go below zero, so make them uint32_t. This
> also allows us to remove a less than zero range check.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/include/fwts_acpi_tables.h | 16 ++++++++--------
>   src/lib/src/fwts_acpi_tables.c     | 12 ++++++++----
>   2 files changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
> index d478d99a..035060eb 100644
> --- a/src/lib/include/fwts_acpi_tables.h
> +++ b/src/lib/include/fwts_acpi_tables.h
> @@ -33,22 +33,22 @@ typedef enum {
>   } fwts_acpi_table_provenance;
>   
>   typedef struct {
> -	char    name[5];
> +	char	   name[5];
>   	const void *data;
> -	size_t	length;
> -	int 	which;
> -	int	index;
> -	bool	has_aml;
> -	uint64_t addr;
> +	size_t	   length;
> +	uint32_t   which;
> +	uint32_t   index;
> +	bool	   has_aml;
> +	uint64_t   addr;
>   	fwts_acpi_table_provenance provenance;
>   } fwts_acpi_table_info;
>   
>   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 int which, 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 int index, 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(const fwts_acpi_table_fadt *fadt);
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 4ac70f81..0a639da0 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -235,7 +235,7 @@ static void fwts_acpi_add_table(
>   						/* Where we got the table from */
>   {
>   	int i;
> -	int which = 0;
> +	uint32_t which = 0;
>   
>   	for (i = 0; i < ACPI_MAX_TABLES; i++) {
>   		if (addr && tables[i].addr == addr) {
> @@ -1237,7 +1237,11 @@ int fwts_acpi_load_tables(fwts_framework *fw)
>    *  	Search for an ACPI table. There may be more than one, so
>    *  	specify the one using which.
>    */
> -int fwts_acpi_find_table(fwts_framework *fw, const char *name, const int which, 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 i;
>   
> @@ -1302,14 +1306,14 @@ int fwts_acpi_find_table_by_addr(fwts_framework *fw, const uint64_t addr, fwts_a
>    *  fwts_acpi_get_table()
>    *  	Get the Nth cached ACPI table.
>    */
> -int fwts_acpi_get_table(fwts_framework *fw, const int index, fwts_acpi_table_info **info)
> +int fwts_acpi_get_table(fwts_framework *fw, const uint32_t index, fwts_acpi_table_info **info)
>   {
>   	if (info == NULL)
>   		return FWTS_NULL_POINTER;
>   
>   	*info = NULL;
>   
> -	if ((index < 0) || (index >= ACPI_MAX_TABLES))
> +	if (index >= ACPI_MAX_TABLES)
>   		return FWTS_ERROR;
>   
>   	if (acpi_tables_loaded == ACPI_TABLES_NOT_LOADED) {
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/lib/include/fwts_acpi_tables.h b/src/lib/include/fwts_acpi_tables.h
index d478d99a..035060eb 100644
--- a/src/lib/include/fwts_acpi_tables.h
+++ b/src/lib/include/fwts_acpi_tables.h
@@ -33,22 +33,22 @@  typedef enum {
 } fwts_acpi_table_provenance;
 
 typedef struct {
-	char    name[5];
+	char	   name[5];
 	const void *data;
-	size_t	length;
-	int 	which;
-	int	index;
-	bool	has_aml;
-	uint64_t addr;
+	size_t	   length;
+	uint32_t   which;
+	uint32_t   index;
+	bool	   has_aml;
+	uint64_t   addr;
 	fwts_acpi_table_provenance provenance;
 } fwts_acpi_table_info;
 
 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 int which, 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 int index, 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(const fwts_acpi_table_fadt *fadt);
diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 4ac70f81..0a639da0 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -235,7 +235,7 @@  static void fwts_acpi_add_table(
 						/* Where we got the table from */
 {
 	int i;
-	int which = 0;
+	uint32_t which = 0;
 
 	for (i = 0; i < ACPI_MAX_TABLES; i++) {
 		if (addr && tables[i].addr == addr) {
@@ -1237,7 +1237,11 @@  int fwts_acpi_load_tables(fwts_framework *fw)
  *  	Search for an ACPI table. There may be more than one, so
  *  	specify the one using which.
  */
-int fwts_acpi_find_table(fwts_framework *fw, const char *name, const int which, 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 i;
 
@@ -1302,14 +1306,14 @@  int fwts_acpi_find_table_by_addr(fwts_framework *fw, const uint64_t addr, fwts_a
  *  fwts_acpi_get_table()
  *  	Get the Nth cached ACPI table.
  */
-int fwts_acpi_get_table(fwts_framework *fw, const int index, fwts_acpi_table_info **info)
+int fwts_acpi_get_table(fwts_framework *fw, const uint32_t index, fwts_acpi_table_info **info)
 {
 	if (info == NULL)
 		return FWTS_NULL_POINTER;
 
 	*info = NULL;
 
-	if ((index < 0) || (index >= ACPI_MAX_TABLES))
+	if (index >= ACPI_MAX_TABLES)
 		return FWTS_ERROR;
 
 	if (acpi_tables_loaded == ACPI_TABLES_NOT_LOADED) {