[Pdbg] [PATCH 6/8] libpdbg: Find compatible hw unit from registered hw units

Amitay Isaacs amitay at ozlabs.org
Thu Jun 13 13:24:14 AEST 2019


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 libpdbg/device.c |  4 ++--
 libpdbg/hwunit.c | 15 +++++++++------
 libpdbg/hwunit.h |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/libpdbg/device.c b/libpdbg/device.c
index 6a60676..b7fd49f 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -72,7 +72,7 @@ static void free_name(const char *name)
 
 static struct pdbg_target *dt_new_node(const char *name, const void *fdt, int node_offset)
 {
-	struct hw_unit_info *hw_info = NULL;
+	const struct hw_unit_info *hw_info = NULL;
 	const struct fdt_property *prop;
 	struct pdbg_target *node;
 	size_t size = sizeof(*node);
@@ -89,7 +89,7 @@ static struct pdbg_target *dt_new_node(const char *name, const void *fdt, int no
 			 */
 			i = 0;
 			while (i < prop_len) {
-				hw_info = find_compatible_target(&prop->data[i]);
+				hw_info = pdbg_hwunit_find_compatible(&prop->data[i]);
 				if (hw_info) {
 					size = hw_info->size;
 					break;
diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c
index ad329f8..acd1457 100644
--- a/libpdbg/hwunit.c
+++ b/libpdbg/hwunit.c
@@ -34,17 +34,20 @@ void pdbg_hwunit_register(const struct hw_unit_info *hw_unit)
 
 extern struct hw_unit_info *__start_hw_units;
 extern struct hw_init_info *__stop_hw_units;
-struct hw_unit_info *find_compatible_target(const char *compat)
+
+const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat)
 {
-	struct hw_unit_info **p;
+	const struct hw_unit_info *p;
 	struct pdbg_target *target;
+	int i;
+
+	for (i = 0; i < g_hw_unit_count; i++) {
+		p = g_hw_unit[i];
+		target = p->hw_unit;
 
-	for (p = &__start_hw_units; p < (struct hw_unit_info **) &__stop_hw_units; p++) {
-		target = (*p)->hw_unit;
 		if (!strcmp(target->compatible, compat))
-			return *p;
+			return p;
 	}
 
 	return NULL;
 }
-
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index 28dba27..75d193a 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -32,7 +32,7 @@ struct hw_unit_info {
 };
 
 void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
-struct hw_unit_info *find_compatible_target(const char *compat);
+const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat);
 
 /* We can't pack the structs themselves directly into a special
  * section because there doesn't seem to be any standard way of doing
-- 
2.21.0



More information about the Pdbg mailing list