From: Marc Kleine-Budde <mkl@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v3 1/9] of_path: of_find_path() factor out device detection logic into separate function
Date: Sun, 25 Oct 2015 22:03:28 +0100 [thread overview]
Message-ID: <1445807016-6637-2-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1445807016-6637-1-git-send-email-mkl@pengutronix.de>
This patch factors out the device detection logic into separate function, so
that it can be used from another function.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/of/of_path.c | 81 ++++++++++++++++++++++++++++------------------------
1 file changed, 44 insertions(+), 37 deletions(-)
diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index 992972c9b52e..ad64bee08af9 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -106,6 +106,48 @@ out:
return ret;
}
+static int __of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags)
+{
+ struct of_path op = {};
+ const char *str;
+ bool add_bb = false;
+ int i, ret;
+
+ op.dev = of_find_device_by_node_path(node->full_name);
+ if (!op.dev) {
+ op.dev = of_find_device_by_node_path(node->parent->full_name);
+ if (!op.dev)
+ return -ENODEV;
+ }
+
+ device_detect(op.dev);
+
+ op.cdev = cdev_by_device_node(node);
+
+ i = 1;
+
+ while (1) {
+ ret = of_property_read_string_index(node, propname, i++, &str);
+ if (ret)
+ break;
+
+ ret = of_path_parse_one(&op, str);
+ if (ret)
+ return ret;
+ }
+
+ if (!op.cdev)
+ return -ENOENT;
+
+ if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
+ mtd_can_have_bb(op.cdev->mtd))
+ add_bb = true;
+
+ *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : "");
+
+ return 0;
+}
+
/**
* of_find_path - translate a path description in the devicetree to a barebox
* path
@@ -134,11 +176,8 @@ out:
*/
int of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags)
{
- struct of_path op = {};
struct device_node *rnode;
- const char *path, *str;
- bool add_bb = false;
- int i, ret;
+ const char *path;
path = of_get_property(node, propname, NULL);
if (!path)
@@ -148,37 +187,5 @@ int of_find_path(struct device_node *node, const char *propname, char **outpath,
if (!rnode)
return -ENODEV;
- op.dev = of_find_device_by_node_path(rnode->full_name);
- if (!op.dev) {
- op.dev = of_find_device_by_node_path(rnode->parent->full_name);
- if (!op.dev)
- return -ENODEV;
- }
-
- device_detect(op.dev);
-
- op.cdev = cdev_by_device_node(rnode);
-
- i = 1;
-
- while (1) {
- ret = of_property_read_string_index(node, propname, i++, &str);
- if (ret)
- break;
-
- ret = of_path_parse_one(&op, str);
- if (ret)
- return ret;
- }
-
- if (!op.cdev)
- return -ENOENT;
-
- if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
- mtd_can_have_bb(op.cdev->mtd))
- add_bb = true;
-
- *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : "");
-
- return 0;
+ return __of_find_path(rnode, propname, outpath, flags);
}
--
2.6.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-10-25 21:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-25 21:03 [PATCH v3 0/8] state framework enhancements Marc Kleine-Budde
2015-10-25 21:03 ` Marc Kleine-Budde [this message]
2015-10-25 21:03 ` [PATCH v3 2/9] of_path: add of_find_path_by_node() Marc Kleine-Budde
2015-10-28 6:20 ` Sascha Hauer
2015-10-28 8:26 ` Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 3/9] state: make use of of_find_path_by_node() and add return -EPROBE_DEFER if device is not available Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 4/9] state: use name of device node as name if alias " Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 5/9] state: disable load command Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 6/9] crypto: Kconfig: add submenu for crypto related config options Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 7/9] crypto: add simple keystore Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 8/9] state: prepare raw backend for hmac support Marc Kleine-Budde
2015-10-25 21:03 ` [PATCH v3 9/9] state: backend_raw: add hamc support Marc Kleine-Budde
2015-10-28 6:24 ` 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=1445807016-6637-2-git-send-email-mkl@pengutronix.de \
--to=mkl@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