[PATCH v2 1/2] of: implement of_append_property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



barebox TLVs can be fixed up into a device tree for OS consumption. In
case of repeated TLVs, we will want barebox to append onto an existing
property. Add a helper that facilitates this.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
v1 -> v2:
  - early exist with of_new_property instead to simplify code (Sascha)
---
 drivers/of/base.c | 33 +++++++++++++++++++++++++++++++++
 include/of.h      |  8 ++++++++
 2 files changed, 41 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 101b2f74c74f..6d762ac43898 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2321,6 +2321,39 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	return 0;
 }
 
+int of_append_property(struct device_node *np, const char *name, const void *val, int len)
+{
+	struct property *pp;
+	int orig_len;
+	void *buf;
+
+	if (!np)
+		return -ENOENT;
+
+	pp = of_find_property(np, name, NULL);
+	if (!pp) {
+		of_new_property(np, name, val, len);
+		return 0;
+	}
+
+	orig_len = pp->length;
+	buf = realloc(pp->value, orig_len + len);
+	if (!buf)
+		return -ENOMEM;
+
+	memcpy(buf + orig_len, val, len);
+
+	pp->value = buf;
+	pp->length += len;
+
+	if (pp->value_const) {
+		memcpy(buf, pp->value_const, orig_len);
+		pp->value_const = NULL;
+	}
+
+	return 0;
+}
+
 int of_property_sprintf(struct device_node *np,
 			const char *propname, const char *fmt, ...)
 {
diff --git a/include/of.h b/include/of.h
index c65cef5a5a7c..97b4b3dd79bd 100644
--- a/include/of.h
+++ b/include/of.h
@@ -131,6 +131,8 @@ extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
 
 extern int of_set_property(struct device_node *node, const char *p,
 			const void *val, int len, int create);
+extern int of_append_property(struct device_node *np, const char *p,
+			      const void *val, int len);
 extern struct property *of_new_property(struct device_node *node,
 				const char *name, const void *data, int len);
 extern struct property *of_new_property_const(struct device_node *node,
@@ -515,6 +517,12 @@ static inline int of_set_property(struct device_node *node, const char *p,
 	return -ENOSYS;
 }
 
+static inline int of_append_property(struct device_node *np, const char *p,
+				      const void *val, int len)
+{
+	return -ENOSYS;
+}
+
 static inline struct property *of_new_property(struct device_node *node,
 				const char *name, const void *data, int len)
 {
-- 
2.30.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux