From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/6] of: Add of_property_read_string_index()
Date: Mon, 22 Apr 2013 09:27:19 +0200 [thread overview]
Message-ID: <1366615643-22213-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1366615643-22213-1-git-send-email-s.hauer@pengutronix.de>
Directly imported from the Kernel
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 2 ++
2 files changed, 48 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 65d8171..c086f7e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -579,6 +579,52 @@ int of_property_read_string(struct device_node *np, const char *propname,
}
EXPORT_SYMBOL_GPL(of_property_read_string);
+/**
+ * of_property_read_string_index - Find and read a string from a multiple
+ * strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the string in the list of strings
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy) in the list of strings
+ * contained in that property.
+ * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
+ * property does not have a value, and -EILSEQ if the string is not
+ * null-terminated within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string_index(struct device_node *np, const char *propname,
+ int index, const char **output)
+{
+ struct property *prop = of_find_property(np, propname);
+ int i = 0;
+ size_t l = 0, total = 0;
+ const char *p;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
+
+ p = prop->value;
+
+ for (i = 0; total < prop->length; total += l, p += l) {
+ l = strlen(p) + 1;
+ if (i++ == index) {
+ *output = p;
+ return 0;
+ }
+ }
+ return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_read_string_index);
+
struct device_node *of_get_root_node(void)
{
return root_node;
diff --git a/include/of.h b/include/of.h
index 94ccfd8..852231e 100644
--- a/include/of.h
+++ b/include/of.h
@@ -160,6 +160,8 @@ void of_delete_property(struct property *pp);
int of_property_read_string(struct device_node *np, const char *propname,
const char **out_string);
+int of_property_read_string_index(struct device_node *np, const char *propname,
+ int index, const char **output);
int of_set_property(struct device_node *node, const char *p, const void *val, int len,
int create);
struct device_node *of_create_node(struct device_node *root, const char *path);
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-04-22 7:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-22 7:27 [PATCH] devicetree patches Sascha Hauer
2013-04-22 7:27 ` [PATCH 1/6] of: parse phandles before probing devices Sascha Hauer
2013-04-22 7:27 ` Sascha Hauer [this message]
2013-04-22 7:27 ` [PATCH 3/6] of: Allow multiple resources in 'reg' property Sascha Hauer
2013-04-22 7:27 ` [PATCH 4/6] of: read resource names from devicetree Sascha Hauer
2013-04-22 7:27 ` [PATCH 5/6] of: partitions: pass struct cdev as argument Sascha Hauer
2013-04-22 7:27 ` [PATCH 6/6] of: partitions: create bb device for nand flashes Sascha Hauer
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=1366615643-22213-3-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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