diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-08-09 12:08:13 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-08-11 08:26:14 +0200 |
commit | f2f635c2f600bd55fc8311213ebd42d64fcfb2ef (patch) | |
tree | c1ce5893712b1eaf2570a142c6790347d2768526 /drivers | |
parent | 2ab6780b80e35796cbfd95bc8bbc0993f1df0bcd (diff) | |
download | barebox-f2f635c2f600bd55fc8311213ebd42d64fcfb2ef.tar.gz barebox-f2f635c2f600bd55fc8311213ebd42d64fcfb2ef.tar.xz |
of: implement of_append_property
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@pengutronix.de>
Link: https://lore.barebox.org/20220809100814.1455984-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/base.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 37c94d00bf..b91ee92e1b 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2329,6 +2329,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, ...) { |