Skip to content

Commit b951f9d

Browse files
gauravminochaosglikely
authored andcommitted
Enabling OF selftest to run without machine's devicetree
If there is no devicetree present, this patch adds the selftest data as a live devicetree. It also removes the same after the testcase execution is complete. Tested with and without machine's devicetree. Signed-off-by: Gaurav Minocha <gaurav.minocha.os@gmail.com> Signed-off-by: Grant Likely <grant.likely@linaro.org>
1 parent b5f2a8c commit b951f9d

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

‎drivers/of/selftest.c‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static struct selftest_results {
2727
#define NO_OF_NODES 2
2828
static struct device_node *nodes[NO_OF_NODES];
2929
static int last_node_index;
30+
static bool selftest_live_tree;
3031

3132
#define selftest(result, fmt, ...) { \
3233
if (!(result)) { \
@@ -630,13 +631,6 @@ static int attach_node_and_children(struct device_node *np)
630631
{
631632
struct device_node *next, *root = np, *dup;
632633

633-
if (!np) {
634-
pr_warn("%s: No tree to attach; not running tests\n",
635-
__func__);
636-
return -ENODATA;
637-
}
638-
639-
640634
/* skip root node */
641635
np = np->child;
642636
/* storing a copy in temporary node */
@@ -672,12 +666,12 @@ static int attach_node_and_children(struct device_node *np)
672666
static int __init selftest_data_add(void)
673667
{
674668
void *selftest_data;
675-
struct device_node *selftest_data_node;
669+
struct device_node *selftest_data_node, *np;
676670
extern uint8_t __dtb_testcases_begin[];
677671
extern uint8_t __dtb_testcases_end[];
678672
const int size = __dtb_testcases_end - __dtb_testcases_begin;
679673

680-
if (!size || !of_allnodes) {
674+
if (!size) {
681675
pr_warn("%s: No testcase data to attach; not running tests\n",
682676
__func__);
683677
return -ENODATA;
@@ -692,6 +686,22 @@ static int __init selftest_data_add(void)
692686
return -ENOMEM;
693687
}
694688
of_fdt_unflatten_tree(selftest_data, &selftest_data_node);
689+
if (!selftest_data_node) {
690+
pr_warn("%s: No tree to attach; not running tests\n", __func__);
691+
return -ENODATA;
692+
}
693+
694+
if (!of_allnodes) {
695+
/* enabling flag for removing nodes */
696+
selftest_live_tree = true;
697+
of_allnodes = selftest_data_node;
698+
699+
for_each_of_allnodes(np)
700+
__of_attach_node_sysfs(np);
701+
of_aliases = of_find_node_by_path("/aliases");
702+
of_chosen = of_find_node_by_path("/chosen");
703+
return 0;
704+
}
695705

696706
/* attach the sub-tree to live tree */
697707
return attach_node_and_children(selftest_data_node);
@@ -723,6 +733,18 @@ static void selftest_data_remove(void)
723733
struct device_node *np;
724734
struct property *prop;
725735

736+
if (selftest_live_tree) {
737+
of_node_put(of_aliases);
738+
of_node_put(of_chosen);
739+
of_aliases = NULL;
740+
of_chosen = NULL;
741+
for_each_child_of_node(of_allnodes, np)
742+
detach_node_and_children(np);
743+
__of_detach_node_sysfs(of_allnodes);
744+
of_allnodes = NULL;
745+
return;
746+
}
747+
726748
while (last_node_index >= 0) {
727749
if (nodes[last_node_index]) {
728750
np = of_find_node_by_path(nodes[last_node_index]->full_name);

0 commit comments

Comments
 (0)