[Pdbg] [PATCH 06/13] libpdbg: Restrict set_property to updating existing property

Amitay Isaacs amitay at ozlabs.org
Wed Jan 15 16:18:54 AEDT 2020


Device tree properties are going to be always accessed from dtb, so unless
the property already exists and has the exact size, it cannot be updated.

Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 libpdbg/device.c  | 22 ++++++----------------
 libpdbg/libpdbg.h |  2 +-
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/libpdbg/device.c b/libpdbg/device.c
index 6599171..91ad258 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -384,31 +384,21 @@ static struct dt_property *dt_add_property(struct pdbg_target *node,
 	return p;
 }
 
-static void dt_resize_property(struct dt_property **prop, size_t len)
-{
-	size_t new_len = sizeof(**prop) + len;
-
-	*prop = realloc(*prop, new_len);
-
-	/* Fix up linked lists in case we moved. (note: not an empty list). */
-	(*prop)->list.next->prev = &(*prop)->list;
-	(*prop)->list.prev->next = &(*prop)->list;
-}
-
-void pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size)
+bool pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size)
 {
 	struct dt_property *p;
 
 	if ((p = dt_find_property(target, name))) {
-		if (size > p->len) {
-			dt_resize_property(&p, size);
-			p->len = size;
+		if (size != p->len) {
+			return false;
 		}
 
 		memcpy(p->prop, val, size);
 	} else {
-		dt_add_property(target, name, val, size);
+		return false;
 	}
+
+	return true;
 }
 
 void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size)
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index be0aa09..d28fd90 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -84,7 +84,7 @@ struct pdbg_target *pdbg_target_parent_virtual(const char *klass, struct pdbg_ta
 struct pdbg_target *pdbg_target_require_parent(const char *klass, struct pdbg_target *target);
 
 /* Set the given property. Will automatically add one if one doesn't exist */
-void pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size);
+bool pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size);
 
 /* Get the given property and return the size */
 void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size);
-- 
2.21.1



More information about the Pdbg mailing list