[PATCH] lib: fwts_acpi_table: make indexes which and index uint32_t

Colin King colin.king at canonical.com
Fri Sep 8 08:26:00 UTC 2017


From: Colin Ian King <colin.king at 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 at 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) {
-- 
2.14.1




More information about the fwts-devel mailing list