aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/selftest.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2011-12-12 11:25:58 -0500
committerGrant Likely <grant.likely@secretlab.ca>2012-01-28 12:29:20 -0500
commit7aff0fe33033fc75b61446ba29d38b1b1354af9f (patch)
tree2ddcfaf17ab0d98959478fd5133d1fe08adb8eef /drivers/of/selftest.c
parentdcd6c92267155e70a94b3927bce681ce74b80d1f (diff)
of: Add of_property_match_string() to find index into a string list
Add a helper function for finding the index of a string in a string list property. This helper is useful for bindings that use a separate *-name property for attaching names to tuples in another property such as 'reg' or 'gpios'. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of/selftest.c')
-rw-r--r--drivers/of/selftest.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index 9d2b4803a9d6..f24ffd7088d2 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -120,6 +120,34 @@ static void __init of_selftest_parse_phandle_with_args(void)
120 pr_info("end - %s\n", passed_all ? "PASS" : "FAIL"); 120 pr_info("end - %s\n", passed_all ? "PASS" : "FAIL");
121} 121}
122 122
123static void __init of_selftest_property_match_string(void)
124{
125 struct device_node *np;
126 int rc;
127
128 pr_info("start\n");
129 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
130 if (!np) {
131 pr_err("No testcase data in device tree\n");
132 return;
133 }
134
135 rc = of_property_match_string(np, "phandle-list-names", "first");
136 selftest(rc == 0, "first expected:0 got:%i\n", rc);
137 rc = of_property_match_string(np, "phandle-list-names", "second");
138 selftest(rc == 1, "second expected:0 got:%i\n", rc);
139 rc = of_property_match_string(np, "phandle-list-names", "third");
140 selftest(rc == 2, "third expected:0 got:%i\n", rc);
141 rc = of_property_match_string(np, "phandle-list-names", "fourth");
142 selftest(rc == -ENODATA, "unmatched string; rc=%i", rc);
143 rc = of_property_match_string(np, "missing-property", "blah");
144 selftest(rc == -EINVAL, "missing property; rc=%i", rc);
145 rc = of_property_match_string(np, "empty-property", "blah");
146 selftest(rc == -ENODATA, "empty property; rc=%i", rc);
147 rc = of_property_match_string(np, "unterminated-string", "blah");
148 selftest(rc == -EILSEQ, "unterminated string; rc=%i", rc);
149}
150
123static int __init of_selftest(void) 151static int __init of_selftest(void)
124{ 152{
125 struct device_node *np; 153 struct device_node *np;
@@ -133,6 +161,7 @@ static int __init of_selftest(void)
133 161
134 pr_info("start of selftest - you will see error messages\n"); 162 pr_info("start of selftest - you will see error messages\n");
135 of_selftest_parse_phandle_with_args(); 163 of_selftest_parse_phandle_with_args();
164 of_selftest_property_match_string();
136 pr_info("end of selftest - %s\n", selftest_passed ? "PASS" : "FAIL"); 165 pr_info("end of selftest - %s\n", selftest_passed ? "PASS" : "FAIL");
137 return 0; 166 return 0;
138} 167}