diff mbox series

[v2,2/4] libpdbg: Handle properties defined on virtual targets correctly

Message ID 20200227042528.165837-3-amitay@ozlabs.org
State Superseded
Headers show
Series Fix handling of attributes for virtual targets | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (8b4611b5d8e7e2279fe4aa80c892fcfe10aa398d)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Amitay Isaacs Feb. 27, 2020, 4:25 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libpdbg/device.c | 49 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/device.c b/libpdbg/device.c
index 48f2c58..cd8a459 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -321,17 +321,41 @@  static void dt_add_phandle(struct pdbg_target *node, const char *name,
 	}
 }
 
+static const void *_target_property(struct pdbg_target *target, const char *name, size_t *size)
+{
+	const void *buf;
+	int buflen;
+
+	if (target->fdt_offset == -1) {
+		size ? *size = 0 : 0;
+		return NULL;
+	}
+
+	buf = fdt_getprop(target->fdt, target->fdt_offset, name, &buflen);
+	if (!buf) {
+		size ? *size = 0 : 0;
+		return NULL;
+	}
+
+	size ? *size = buflen : 0;
+	return buf;
+}
+
 bool pdbg_target_set_property(struct pdbg_target *target, const char *name, const void *val, size_t size)
 {
 	const void *p;
 	size_t len;
 	int ret;
 
-	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
+	p = _target_property(target, name, &len);
+	if (!p && target->vnode) {
+		target = target->vnode;
+		p = _target_property(target, name, &len);
+	}
+	if (!p)
 		return false;
 
-	p = pdbg_target_property(target, name, &len);
-	if (!p)
+	if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt))
 		return false;
 
 	if (len != size)
@@ -346,22 +370,13 @@  bool pdbg_target_set_property(struct pdbg_target *target, const char *name, cons
 
 const void *pdbg_target_property(struct pdbg_target *target, const char *name, size_t *size)
 {
-	const void *buf;
-	int buflen;
-
-	if (target->fdt_offset == -1) {
-		size ? *size = 0 : 0;
-		return NULL;
-	}
+	const void *p;
 
-	buf = fdt_getprop(target->fdt, target->fdt_offset, name, &buflen);
-	if (!buf) {
-		size ? *size = 0 : 0;
-		return NULL;
-	}
+	p = _target_property(target, name, size);
+	if (!p && target->vnode)
+		p = _target_property(target->vnode, name, size);
 
-	size ? *size = buflen : 0;
-	return buf;
+	return p;
 }
 
 static u32 dt_property_get_cell(const void *prop, size_t len, u32 index)