2 * Self tests for device tree subsystem
5 #define pr_fmt(fmt) "### dt-test ### " fmt
9 #include <linux/errno.h>
10 #include <linux/module.h>
12 #include <linux/of_fdt.h>
13 #include <linux/of_irq.h>
14 #include <linux/of_platform.h>
15 #include <linux/list.h>
16 #include <linux/mutex.h>
17 #include <linux/slab.h>
18 #include <linux/device.h>
20 #include "of_private.h"
22 static struct selftest_results
{
28 static struct device_node
*nodes
[NO_OF_NODES
];
29 static int last_node_index
;
30 static bool selftest_live_tree
;
32 #define selftest(result, fmt, ...) { \
34 selftest_results.failed++; \
35 pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
37 selftest_results.passed++; \
38 pr_debug("pass %s():%i\n", __func__, __LINE__); \
42 static void __init
of_selftest_find_node_by_name(void)
44 struct device_node
*np
;
46 np
= of_find_node_by_path("/testcase-data");
47 selftest(np
&& !strcmp("/testcase-data", np
->full_name
),
48 "find /testcase-data failed\n");
51 /* Test if trailing '/' works */
52 np
= of_find_node_by_path("/testcase-data/");
53 selftest(!np
, "trailing '/' on /testcase-data/ should fail\n");
55 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
56 selftest(np
&& !strcmp("/testcase-data/phandle-tests/consumer-a", np
->full_name
),
57 "find /testcase-data/phandle-tests/consumer-a failed\n");
60 np
= of_find_node_by_path("testcase-alias");
61 selftest(np
&& !strcmp("/testcase-data", np
->full_name
),
62 "find testcase-alias failed\n");
65 /* Test if trailing '/' works on aliases */
66 np
= of_find_node_by_path("testcase-alias/");
67 selftest(!np
, "trailing '/' on testcase-alias/ should fail\n");
69 np
= of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
70 selftest(np
&& !strcmp("/testcase-data/phandle-tests/consumer-a", np
->full_name
),
71 "find testcase-alias/phandle-tests/consumer-a failed\n");
74 np
= of_find_node_by_path("/testcase-data/missing-path");
75 selftest(!np
, "non-existent path returned node %s\n", np
->full_name
);
78 np
= of_find_node_by_path("missing-alias");
79 selftest(!np
, "non-existent alias returned node %s\n", np
->full_name
);
82 np
= of_find_node_by_path("testcase-alias/missing-path");
83 selftest(!np
, "non-existent alias with relative path returned node %s\n", np
->full_name
);
87 static void __init
of_selftest_dynamic(void)
89 struct device_node
*np
;
90 struct property
*prop
;
92 np
= of_find_node_by_path("/testcase-data");
94 pr_err("missing testcase data\n");
98 /* Array of 4 properties for the purpose of testing */
99 prop
= kzalloc(sizeof(*prop
) * 4, GFP_KERNEL
);
101 selftest(0, "kzalloc() failed\n");
105 /* Add a new property - should pass*/
106 prop
->name
= "new-property";
107 prop
->value
= "new-property-data";
108 prop
->length
= strlen(prop
->value
);
109 selftest(of_add_property(np
, prop
) == 0, "Adding a new property failed\n");
111 /* Try to add an existing property - should fail */
113 prop
->name
= "new-property";
114 prop
->value
= "new-property-data-should-fail";
115 prop
->length
= strlen(prop
->value
);
116 selftest(of_add_property(np
, prop
) != 0,
117 "Adding an existing property should have failed\n");
119 /* Try to modify an existing property - should pass */
120 prop
->value
= "modify-property-data-should-pass";
121 prop
->length
= strlen(prop
->value
);
122 selftest(of_update_property(np
, prop
) == 0,
123 "Updating an existing property should have passed\n");
125 /* Try to modify non-existent property - should pass*/
127 prop
->name
= "modify-property";
128 prop
->value
= "modify-missing-property-data-should-pass";
129 prop
->length
= strlen(prop
->value
);
130 selftest(of_update_property(np
, prop
) == 0,
131 "Updating a missing property should have passed\n");
133 /* Remove property - should pass */
134 selftest(of_remove_property(np
, prop
) == 0,
135 "Removing a property should have passed\n");
137 /* Adding very large property - should pass */
139 prop
->name
= "large-property-PAGE_SIZEx8";
140 prop
->length
= PAGE_SIZE
* 8;
141 prop
->value
= kzalloc(prop
->length
, GFP_KERNEL
);
142 selftest(prop
->value
!= NULL
, "Unable to allocate large buffer\n");
144 selftest(of_add_property(np
, prop
) == 0,
145 "Adding a large property should have passed\n");
148 static int __init
of_selftest_check_node_linkage(struct device_node
*np
)
150 struct device_node
*child
, *allnext_index
= np
;
153 for_each_child_of_node(np
, child
) {
154 if (child
->parent
!= np
) {
155 pr_err("Child node %s links to wrong parent %s\n",
156 child
->name
, np
->name
);
160 while (allnext_index
&& allnext_index
!= child
)
161 allnext_index
= allnext_index
->allnext
;
162 if (allnext_index
!= child
) {
163 pr_err("Node %s is ordered differently in sibling and allnode lists\n",
168 rc
= of_selftest_check_node_linkage(child
);
177 static void __init
of_selftest_check_tree_linkage(void)
179 struct device_node
*np
;
180 int allnode_count
= 0, child_count
;
185 for_each_of_allnodes(np
)
187 child_count
= of_selftest_check_node_linkage(of_allnodes
);
189 selftest(child_count
> 0, "Device node data structure is corrupted\n");
190 selftest(child_count
== allnode_count
, "allnodes list size (%i) doesn't match"
191 "sibling lists size (%i)\n", allnode_count
, child_count
);
192 pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count
, child_count
);
195 static void __init
of_selftest_parse_phandle_with_args(void)
197 struct device_node
*np
;
198 struct of_phandle_args args
;
201 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
203 pr_err("missing testcase data\n");
207 rc
= of_count_phandle_with_args(np
, "phandle-list", "#phandle-cells");
208 selftest(rc
== 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc
);
210 for (i
= 0; i
< 8; i
++) {
212 rc
= of_parse_phandle_with_args(np
, "phandle-list",
213 "#phandle-cells", i
, &args
);
215 /* Test the values from tests-phandle.dtsi */
219 passed
&= (args
.args_count
== 1);
220 passed
&= (args
.args
[0] == (i
+ 1));
224 passed
&= (args
.args_count
== 2);
225 passed
&= (args
.args
[0] == (i
+ 1));
226 passed
&= (args
.args
[1] == 0);
229 passed
&= (rc
== -ENOENT
);
233 passed
&= (args
.args_count
== 3);
234 passed
&= (args
.args
[0] == (i
+ 1));
235 passed
&= (args
.args
[1] == 4);
236 passed
&= (args
.args
[2] == 3);
240 passed
&= (args
.args_count
== 2);
241 passed
&= (args
.args
[0] == (i
+ 1));
242 passed
&= (args
.args
[1] == 100);
246 passed
&= (args
.args_count
== 0);
250 passed
&= (args
.args_count
== 1);
251 passed
&= (args
.args
[0] == (i
+ 1));
254 passed
&= (rc
== -ENOENT
);
260 selftest(passed
, "index %i - data error on node %s rc=%i\n",
261 i
, args
.np
->full_name
, rc
);
264 /* Check for missing list property */
265 rc
= of_parse_phandle_with_args(np
, "phandle-list-missing",
266 "#phandle-cells", 0, &args
);
267 selftest(rc
== -ENOENT
, "expected:%i got:%i\n", -ENOENT
, rc
);
268 rc
= of_count_phandle_with_args(np
, "phandle-list-missing",
270 selftest(rc
== -ENOENT
, "expected:%i got:%i\n", -ENOENT
, rc
);
272 /* Check for missing cells property */
273 rc
= of_parse_phandle_with_args(np
, "phandle-list",
274 "#phandle-cells-missing", 0, &args
);
275 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
276 rc
= of_count_phandle_with_args(np
, "phandle-list",
277 "#phandle-cells-missing");
278 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
280 /* Check for bad phandle in list */
281 rc
= of_parse_phandle_with_args(np
, "phandle-list-bad-phandle",
282 "#phandle-cells", 0, &args
);
283 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
284 rc
= of_count_phandle_with_args(np
, "phandle-list-bad-phandle",
286 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
288 /* Check for incorrectly formed argument list */
289 rc
= of_parse_phandle_with_args(np
, "phandle-list-bad-args",
290 "#phandle-cells", 1, &args
);
291 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
292 rc
= of_count_phandle_with_args(np
, "phandle-list-bad-args",
294 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
297 static void __init
of_selftest_property_match_string(void)
299 struct device_node
*np
;
302 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
304 pr_err("No testcase data in device tree\n");
308 rc
= of_property_match_string(np
, "phandle-list-names", "first");
309 selftest(rc
== 0, "first expected:0 got:%i\n", rc
);
310 rc
= of_property_match_string(np
, "phandle-list-names", "second");
311 selftest(rc
== 1, "second expected:0 got:%i\n", rc
);
312 rc
= of_property_match_string(np
, "phandle-list-names", "third");
313 selftest(rc
== 2, "third expected:0 got:%i\n", rc
);
314 rc
= of_property_match_string(np
, "phandle-list-names", "fourth");
315 selftest(rc
== -ENODATA
, "unmatched string; rc=%i", rc
);
316 rc
= of_property_match_string(np
, "missing-property", "blah");
317 selftest(rc
== -EINVAL
, "missing property; rc=%i", rc
);
318 rc
= of_property_match_string(np
, "empty-property", "blah");
319 selftest(rc
== -ENODATA
, "empty property; rc=%i", rc
);
320 rc
= of_property_match_string(np
, "unterminated-string", "blah");
321 selftest(rc
== -EILSEQ
, "unterminated string; rc=%i", rc
);
324 #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
325 (p1)->value && (p2)->value && \
326 !memcmp((p1)->value, (p2)->value, (p1)->length) && \
327 !strcmp((p1)->name, (p2)->name))
328 static void __init
of_selftest_property_copy(void)
330 #ifdef CONFIG_OF_DYNAMIC
331 struct property p1
= { .name
= "p1", .length
= 0, .value
= "" };
332 struct property p2
= { .name
= "p2", .length
= 5, .value
= "abcd" };
333 struct property
*new;
335 new = __of_prop_dup(&p1
, GFP_KERNEL
);
336 selftest(new && propcmp(&p1
, new), "empty property didn't copy correctly\n");
341 new = __of_prop_dup(&p2
, GFP_KERNEL
);
342 selftest(new && propcmp(&p2
, new), "non-empty property didn't copy correctly\n");
349 static void __init
of_selftest_changeset(void)
351 #ifdef CONFIG_OF_DYNAMIC
352 struct property
*ppadd
, padd
= { .name
= "prop-add", .length
= 0, .value
= "" };
353 struct property
*ppupdate
, pupdate
= { .name
= "prop-update", .length
= 5, .value
= "abcd" };
354 struct property
*ppremove
;
355 struct device_node
*n1
, *n2
, *n21
, *nremove
, *parent
;
356 struct of_changeset chgset
;
358 of_changeset_init(&chgset
);
359 n1
= __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL
);
360 selftest(n1
, "testcase setup failure\n");
361 n2
= __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL
);
362 selftest(n2
, "testcase setup failure\n");
363 n21
= __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL
);
364 selftest(n21
, "testcase setup failure %p\n", n21
);
365 nremove
= of_find_node_by_path("/testcase-data/changeset/node-remove");
366 selftest(nremove
, "testcase setup failure\n");
367 ppadd
= __of_prop_dup(&padd
, GFP_KERNEL
);
368 selftest(ppadd
, "testcase setup failure\n");
369 ppupdate
= __of_prop_dup(&pupdate
, GFP_KERNEL
);
370 selftest(ppupdate
, "testcase setup failure\n");
371 parent
= nremove
->parent
;
376 ppremove
= of_find_property(parent
, "prop-remove", NULL
);
377 selftest(ppremove
, "failed to find removal prop");
379 of_changeset_init(&chgset
);
380 selftest(!of_changeset_attach_node(&chgset
, n1
), "fail attach n1\n");
381 selftest(!of_changeset_attach_node(&chgset
, n2
), "fail attach n2\n");
382 selftest(!of_changeset_detach_node(&chgset
, nremove
), "fail remove node\n");
383 selftest(!of_changeset_attach_node(&chgset
, n21
), "fail attach n21\n");
384 selftest(!of_changeset_add_property(&chgset
, parent
, ppadd
), "fail add prop\n");
385 selftest(!of_changeset_update_property(&chgset
, parent
, ppupdate
), "fail update prop\n");
386 selftest(!of_changeset_remove_property(&chgset
, parent
, ppremove
), "fail remove prop\n");
387 mutex_lock(&of_mutex
);
388 selftest(!of_changeset_apply(&chgset
), "apply failed\n");
389 mutex_unlock(&of_mutex
);
391 mutex_lock(&of_mutex
);
392 selftest(!of_changeset_revert(&chgset
), "revert failed\n");
393 mutex_unlock(&of_mutex
);
395 of_changeset_destroy(&chgset
);
399 static void __init
of_selftest_parse_interrupts(void)
401 struct device_node
*np
;
402 struct of_phandle_args args
;
405 np
= of_find_node_by_path("/testcase-data/interrupts/interrupts0");
407 pr_err("missing testcase data\n");
411 for (i
= 0; i
< 4; i
++) {
414 rc
= of_irq_parse_one(np
, i
, &args
);
417 passed
&= (args
.args_count
== 1);
418 passed
&= (args
.args
[0] == (i
+ 1));
420 selftest(passed
, "index %i - data error on node %s rc=%i\n",
421 i
, args
.np
->full_name
, rc
);
425 np
= of_find_node_by_path("/testcase-data/interrupts/interrupts1");
427 pr_err("missing testcase data\n");
431 for (i
= 0; i
< 4; i
++) {
434 rc
= of_irq_parse_one(np
, i
, &args
);
436 /* Test the values from tests-phandle.dtsi */
440 passed
&= (args
.args_count
== 1);
441 passed
&= (args
.args
[0] == 9);
445 passed
&= (args
.args_count
== 3);
446 passed
&= (args
.args
[0] == 10);
447 passed
&= (args
.args
[1] == 11);
448 passed
&= (args
.args
[2] == 12);
452 passed
&= (args
.args_count
== 2);
453 passed
&= (args
.args
[0] == 13);
454 passed
&= (args
.args
[1] == 14);
458 passed
&= (args
.args_count
== 2);
459 passed
&= (args
.args
[0] == 15);
460 passed
&= (args
.args
[1] == 16);
465 selftest(passed
, "index %i - data error on node %s rc=%i\n",
466 i
, args
.np
->full_name
, rc
);
471 static void __init
of_selftest_parse_interrupts_extended(void)
473 struct device_node
*np
;
474 struct of_phandle_args args
;
477 np
= of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
479 pr_err("missing testcase data\n");
483 for (i
= 0; i
< 7; i
++) {
485 rc
= of_irq_parse_one(np
, i
, &args
);
487 /* Test the values from tests-phandle.dtsi */
491 passed
&= (args
.args_count
== 1);
492 passed
&= (args
.args
[0] == 1);
496 passed
&= (args
.args_count
== 3);
497 passed
&= (args
.args
[0] == 2);
498 passed
&= (args
.args
[1] == 3);
499 passed
&= (args
.args
[2] == 4);
503 passed
&= (args
.args_count
== 2);
504 passed
&= (args
.args
[0] == 5);
505 passed
&= (args
.args
[1] == 6);
509 passed
&= (args
.args_count
== 1);
510 passed
&= (args
.args
[0] == 9);
514 passed
&= (args
.args_count
== 3);
515 passed
&= (args
.args
[0] == 10);
516 passed
&= (args
.args
[1] == 11);
517 passed
&= (args
.args
[2] == 12);
521 passed
&= (args
.args_count
== 2);
522 passed
&= (args
.args
[0] == 13);
523 passed
&= (args
.args
[1] == 14);
527 passed
&= (args
.args_count
== 1);
528 passed
&= (args
.args
[0] == 15);
534 selftest(passed
, "index %i - data error on node %s rc=%i\n",
535 i
, args
.np
->full_name
, rc
);
540 static struct of_device_id match_node_table
[] = {
541 { .data
= "A", .name
= "name0", }, /* Name alone is lowest priority */
542 { .data
= "B", .type
= "type1", }, /* followed by type alone */
544 { .data
= "Ca", .name
= "name2", .type
= "type1", }, /* followed by both together */
545 { .data
= "Cb", .name
= "name2", }, /* Only match when type doesn't match */
546 { .data
= "Cc", .name
= "name2", .type
= "type2", },
548 { .data
= "E", .compatible
= "compat3" },
549 { .data
= "G", .compatible
= "compat2", },
550 { .data
= "H", .compatible
= "compat2", .name
= "name5", },
551 { .data
= "I", .compatible
= "compat2", .type
= "type1", },
552 { .data
= "J", .compatible
= "compat2", .type
= "type1", .name
= "name8", },
553 { .data
= "K", .compatible
= "compat2", .name
= "name9", },
560 } match_node_tests
[] = {
561 { .path
= "/testcase-data/match-node/name0", .data
= "A", },
562 { .path
= "/testcase-data/match-node/name1", .data
= "B", },
563 { .path
= "/testcase-data/match-node/a/name2", .data
= "Ca", },
564 { .path
= "/testcase-data/match-node/b/name2", .data
= "Cb", },
565 { .path
= "/testcase-data/match-node/c/name2", .data
= "Cc", },
566 { .path
= "/testcase-data/match-node/name3", .data
= "E", },
567 { .path
= "/testcase-data/match-node/name4", .data
= "G", },
568 { .path
= "/testcase-data/match-node/name5", .data
= "H", },
569 { .path
= "/testcase-data/match-node/name6", .data
= "G", },
570 { .path
= "/testcase-data/match-node/name7", .data
= "I", },
571 { .path
= "/testcase-data/match-node/name8", .data
= "J", },
572 { .path
= "/testcase-data/match-node/name9", .data
= "K", },
575 static void __init
of_selftest_match_node(void)
577 struct device_node
*np
;
578 const struct of_device_id
*match
;
581 for (i
= 0; i
< ARRAY_SIZE(match_node_tests
); i
++) {
582 np
= of_find_node_by_path(match_node_tests
[i
].path
);
584 selftest(0, "missing testcase node %s\n",
585 match_node_tests
[i
].path
);
589 match
= of_match_node(match_node_table
, np
);
591 selftest(0, "%s didn't match anything\n",
592 match_node_tests
[i
].path
);
596 if (strcmp(match
->data
, match_node_tests
[i
].data
) != 0) {
597 selftest(0, "%s got wrong match. expected %s, got %s\n",
598 match_node_tests
[i
].path
, match_node_tests
[i
].data
,
599 (const char *)match
->data
);
602 selftest(1, "passed");
606 static void __init
of_selftest_platform_populate(void)
609 struct device_node
*np
, *child
;
610 struct platform_device
*pdev
;
611 struct of_device_id match
[] = {
612 { .compatible
= "test-device", },
616 np
= of_find_node_by_path("/testcase-data");
617 of_platform_populate(np
, of_default_bus_match_table
, NULL
, NULL
);
619 /* Test that a missing irq domain returns -EPROBE_DEFER */
620 np
= of_find_node_by_path("/testcase-data/testcase-device1");
621 pdev
= of_find_device_by_node(np
);
622 selftest(pdev
, "device 1 creation failed\n");
624 irq
= platform_get_irq(pdev
, 0);
625 selftest(irq
== -EPROBE_DEFER
, "device deferred probe failed - %d\n", irq
);
627 /* Test that a parsing failure does not return -EPROBE_DEFER */
628 np
= of_find_node_by_path("/testcase-data/testcase-device2");
629 pdev
= of_find_device_by_node(np
);
630 selftest(pdev
, "device 2 creation failed\n");
631 irq
= platform_get_irq(pdev
, 0);
632 selftest(irq
< 0 && irq
!= -EPROBE_DEFER
, "device parsing error failed - %d\n", irq
);
634 np
= of_find_node_by_path("/testcase-data/platform-tests");
636 pr_err("No testcase data in device tree\n");
640 for_each_child_of_node(np
, child
) {
641 struct device_node
*grandchild
;
642 of_platform_populate(child
, match
, NULL
, NULL
);
643 for_each_child_of_node(child
, grandchild
)
644 selftest(of_find_device_by_node(grandchild
),
645 "Could not create device for node '%s'\n",
651 * update_node_properties - adds the properties
652 * of np into dup node (present in live tree) and
653 * updates parent of children of np to dup.
655 * @np: node already present in live tree
656 * @dup: node present in live tree to be updated
658 static void update_node_properties(struct device_node
*np
,
659 struct device_node
*dup
)
661 struct property
*prop
;
662 struct device_node
*child
;
664 for_each_property_of_node(np
, prop
)
665 of_add_property(dup
, prop
);
667 for_each_child_of_node(np
, child
)
672 * attach_node_and_children - attaches nodes
673 * and its children to live tree
675 * @np: Node to attach to live tree
677 static int attach_node_and_children(struct device_node
*np
)
679 struct device_node
*next
, *root
= np
, *dup
;
683 /* storing a copy in temporary node */
687 if (WARN_ON(last_node_index
>= NO_OF_NODES
))
689 nodes
[last_node_index
++] = dup
;
696 dup
= of_find_node_by_path(np
->full_name
);
698 update_node_properties(np
, dup
);
701 if (np
->parent
== root
)
702 np
->parent
= of_allnodes
;
712 * selftest_data_add - Reads, copies data from
713 * linked tree and attaches it to the live tree
715 static int __init
selftest_data_add(void)
718 struct device_node
*selftest_data_node
, *np
;
719 extern uint8_t __dtb_testcases_begin
[];
720 extern uint8_t __dtb_testcases_end
[];
721 const int size
= __dtb_testcases_end
- __dtb_testcases_begin
;
724 pr_warn("%s: No testcase data to attach; not running tests\n",
730 selftest_data
= kmemdup(__dtb_testcases_begin
, size
, GFP_KERNEL
);
732 if (!selftest_data
) {
733 pr_warn("%s: Failed to allocate memory for selftest_data; "
734 "not running tests\n", __func__
);
737 of_fdt_unflatten_tree(selftest_data
, &selftest_data_node
);
738 if (!selftest_data_node
) {
739 pr_warn("%s: No tree to attach; not running tests\n", __func__
);
744 /* enabling flag for removing nodes */
745 selftest_live_tree
= true;
746 of_allnodes
= selftest_data_node
;
748 for_each_of_allnodes(np
)
749 __of_attach_node_sysfs(np
);
750 of_aliases
= of_find_node_by_path("/aliases");
751 of_chosen
= of_find_node_by_path("/chosen");
755 /* attach the sub-tree to live tree */
756 return attach_node_and_children(selftest_data_node
);
760 * detach_node_and_children - detaches node
761 * and its children from live tree
763 * @np: Node to detach from live tree
765 static void detach_node_and_children(struct device_node
*np
)
768 detach_node_and_children(np
->child
);
773 * selftest_data_remove - removes the selftest data
774 * nodes from the live tree
776 static void selftest_data_remove(void)
778 struct device_node
*np
;
779 struct property
*prop
;
781 if (selftest_live_tree
) {
782 of_node_put(of_aliases
);
783 of_node_put(of_chosen
);
786 for_each_child_of_node(of_allnodes
, np
)
787 detach_node_and_children(np
);
788 __of_detach_node_sysfs(of_allnodes
);
793 while (last_node_index
>= 0) {
794 if (nodes
[last_node_index
]) {
795 np
= of_find_node_by_path(nodes
[last_node_index
]->full_name
);
796 if (strcmp(np
->full_name
, "/aliases") != 0) {
797 detach_node_and_children(np
);
799 for_each_property_of_node(np
, prop
) {
800 if (strcmp(prop
->name
, "testcase-alias") == 0)
801 of_remove_property(np
, prop
);
809 static int __init
of_selftest(void)
811 struct device_node
*np
;
814 /* adding data for selftest */
815 res
= selftest_data_add();
819 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
821 pr_info("No testcase data in device tree; not running tests\n");
826 pr_info("start of selftest - you will see error messages\n");
827 of_selftest_check_tree_linkage();
828 of_selftest_find_node_by_name();
829 of_selftest_dynamic();
830 of_selftest_parse_phandle_with_args();
831 of_selftest_property_match_string();
832 of_selftest_property_copy();
833 of_selftest_changeset();
834 of_selftest_parse_interrupts();
835 of_selftest_parse_interrupts_extended();
836 of_selftest_match_node();
837 of_selftest_platform_populate();
839 /* removing selftest data from live tree */
840 selftest_data_remove();
842 /* Double check linkage after removing testcase data */
843 of_selftest_check_tree_linkage();
845 pr_info("end of selftest - %i passed, %i failed\n",
846 selftest_results
.passed
, selftest_results
.failed
);
850 late_initcall(of_selftest
);