From: Fabian Pflug <f.pflug@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>,
Sascha Hauer <s.hauer@pengutronix.de>
Cc: Fabian Pflug <f.pflug@pengutronix.de>
Subject: [PATCH v3 1/5] of: add of_property_write_string_array()
Date: Wed, 18 Mar 2026 10:21:59 +0100 [thread overview]
Message-ID: <20260318-v2026-02-0-topic-sconfig_console-v3-1-e26055294723@pengutronix.de> (raw)
In-Reply-To: <20260318-v2026-02-0-topic-sconfig_console-v3-0-e26055294723@pengutronix.de>
Helper function to write an array of string into a property.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
drivers/of/base.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/of.h | 3 +++
test/self/of_manipulation.c | 14 +++++++++++++-
test/self/of_manipulation.dts | 5 +++++
4 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 460b5e2f4b..376a2ac6a8 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1570,6 +1570,49 @@ int of_property_write_u64_array(struct device_node *np,
return 0;
}
+/**
+ * of_property_write_string_array - Write strings to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write a string to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created, -EINVAL if no strings specified.
+ */
+int of_property_write_string_array(struct device_node *np,
+ const char *propname, const char **values,
+ size_t sz)
+{
+ char *buf = NULL, *next;
+ size_t len = 0;
+ int ret = 0, i;
+
+ for (i = 0; i < sz; i++)
+ len += strlen(values[i]) + 1;
+
+ if (!len)
+ return -EINVAL;
+
+ buf = malloc(len);
+ if (!buf)
+ return -ENOMEM;
+
+ next = buf;
+
+ for (i = 0; i < sz; i++)
+ next = stpcpy(next, values[i]) + 1;
+
+ ret = of_set_property(np, propname, buf, len, 1);
+ free(buf);
+ return ret;
+}
+
/**
* of_property_write_strings - Write strings to a property. If
* the property does not exist, it will be created and appended to the given
diff --git a/include/of.h b/include/of.h
index ba8d1e358d..34439ee763 100644
--- a/include/of.h
+++ b/include/of.h
@@ -310,6 +310,9 @@ extern int of_property_write_string(struct device_node *np, const char *propname
const char *value);
extern int of_property_write_strings(struct device_node *np, const char *propname,
...) __attribute__((__sentinel__));
+int of_property_write_string_array(struct device_node *np,
+ const char *propname, const char **values,
+ size_t sz);
int of_property_sprintf(struct device_node *np, const char *propname, const char *fmt, ...)
__printf(3, 4);
diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
index 8d645b1137..faf948a17b 100644
--- a/test/self/of_manipulation.c
+++ b/test/self/of_manipulation.c
@@ -71,13 +71,19 @@ static void test_of_basics(struct device_node *root)
static void test_of_property_strings(struct device_node *root)
{
- struct device_node *np1, *np2, *np3, *np4;
+ struct device_node *np1, *np2, *np3, *np4, *np5;
char properties[] = "ayy\0bee\0sea";
+ static const char * const prop_array[] = {
+ "ayy",
+ "bee\0\0\0",
+ "sea\0",
+ };
np1 = of_new_node(root, "np1");
np2 = of_new_node(root, "np2");
np3 = of_new_node(root, "np3");
np4 = of_new_node(root, "np4");
+ np5 = of_new_node(root, "np5");
of_property_sprintf(np1, "property-single", "%c%c%c", 'a', 'y', 'y');
@@ -108,6 +114,12 @@ static void test_of_property_strings(struct device_node *root)
of_prepend_property(np4, "property-multi", "ayy", 4);
assert_equal(np3, np4);
+
+ of_property_write_string_array(np5, "property-single", prop_array, 1);
+
+ of_property_write_string_array(np5, "property-multi", prop_array, 3);
+
+ assert_equal(np4, np5);
}
static void __init test_of_manipulation(void)
diff --git a/test/self/of_manipulation.dts b/test/self/of_manipulation.dts
index 2cc6773fa9..7a1fb1217d 100644
--- a/test/self/of_manipulation.dts
+++ b/test/self/of_manipulation.dts
@@ -34,4 +34,9 @@ np4 {
property-single = "ayy";
property-multi = "ayy", "bee", "sea";
};
+
+ np5 {
+ property-single = "ayy";
+ property-multi = "ayy", "bee", "sea";
+ };
};
--
2.47.3
next prev parent reply other threads:[~2026-03-18 9:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 9:21 [PATCH v3 0/5] Add helper for security policies Fabian Pflug
2026-03-18 9:21 ` Fabian Pflug [this message]
2026-03-18 9:22 ` [PATCH v3 2/5] common: bootm: add policy to commandline Fabian Pflug
2026-03-18 10:23 ` Sascha Hauer
2026-03-18 9:22 ` [PATCH v3 3/5] security: policy: set active policy on boot Fabian Pflug
2026-03-18 11:28 ` Ahmad Fatoum
2026-03-18 11:38 ` Fabian Pflug
2026-03-18 11:54 ` Ahmad Fatoum
2026-03-18 12:47 ` Fabian Pflug
2026-03-19 14:58 ` Ahmad Fatoum
2026-03-18 9:22 ` [PATCH v3 4/5] security: configure pinctrl based on policy name Fabian Pflug
2026-03-18 11:43 ` Ahmad Fatoum
2026-03-18 9:22 ` [PATCH v3 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts Fabian Pflug
2026-03-18 11:53 ` Ahmad Fatoum
2026-03-18 9:57 ` [PATCH v3 0/5] Add helper for security policies Sascha Hauer
2026-03-18 11:43 ` Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260318-v2026-02-0-topic-sconfig_console-v3-1-e26055294723@pengutronix.de \
--to=f.pflug@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox