Skip to content

Commit 3ce04b4

Browse files
gauravminochaosrobherring
authored andcommitted
Removes OF_UNITTEST dependency on OF_DYNAMIC config symbol
This patch intends to remove the unittests dependency on the functions defined in dynamic.c. So, rather than calling of_attach_node defined in dynamic.c, minimal functionality required to attach a new node is re-defined in unittest.c. Also, now after executing the tests the test data is not removed from the device tree so there is no need to call of_detach_node. Tested with and without OF_DYNAMIC enabled on ppc, arm and x86 Signed-off-by: Gaurav Minocha <[email protected]> Signed-off-by: Rob Herring <[email protected]>
1 parent 9a4305b commit 3ce04b4

File tree

2 files changed

+12
-59
lines changed

2 files changed

+12
-59
lines changed

drivers/of/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ menu "Device Tree and Open Firmware support"
1010
config OF_UNITTEST
1111
bool "Device Tree runtime unit tests"
1212
depends on OF_IRQ && OF_EARLY_FLATTREE
13-
select OF_DYNAMIC
1413
select OF_RESOLVE
1514
help
1615
This option builds in test cases for the device tree infrastructure

drivers/of/unittest.c

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ static void update_node_properties(struct device_node *np,
822822
static int attach_node_and_children(struct device_node *np)
823823
{
824824
struct device_node *next, *dup, *child;
825+
unsigned long flags;
825826

826827
dup = of_find_node_by_path(np->full_name);
827828
if (dup) {
@@ -838,8 +839,17 @@ static int attach_node_and_children(struct device_node *np)
838839

839840
child = np->child;
840841
np->child = NULL;
841-
np->sibling = NULL;
842-
of_attach_node(np);
842+
843+
mutex_lock(&of_mutex);
844+
raw_spin_lock_irqsave(&devtree_lock, flags);
845+
np->sibling = np->parent->child;
846+
np->parent->child = np;
847+
of_node_clear_flag(np, OF_DETACHED);
848+
raw_spin_unlock_irqrestore(&devtree_lock, flags);
849+
850+
__of_attach_node_sysfs(np);
851+
mutex_unlock(&of_mutex);
852+
843853
while (child) {
844854
next = child->sibling;
845855
attach_node_and_children(child);
@@ -911,59 +921,6 @@ static int __init selftest_data_add(void)
911921
return 0;
912922
}
913923

914-
/**
915-
* detach_node_and_children - detaches node
916-
* and its children from live tree
917-
*
918-
* @np: Node to detach from live tree
919-
*/
920-
static void detach_node_and_children(struct device_node *np)
921-
{
922-
while (np->child)
923-
detach_node_and_children(np->child);
924-
of_detach_node(np);
925-
}
926-
927-
/**
928-
* selftest_data_remove - removes the selftest data
929-
* nodes from the live tree
930-
*/
931-
static void selftest_data_remove(void)
932-
{
933-
struct device_node *np;
934-
struct property *prop;
935-
936-
if (selftest_live_tree) {
937-
of_node_put(of_aliases);
938-
of_node_put(of_chosen);
939-
of_aliases = NULL;
940-
of_chosen = NULL;
941-
for_each_child_of_node(of_root, np)
942-
detach_node_and_children(np);
943-
__of_detach_node_sysfs(of_root);
944-
of_root = NULL;
945-
return;
946-
}
947-
948-
while (last_node_index-- > 0) {
949-
if (nodes[last_node_index]) {
950-
np = of_find_node_by_path(nodes[last_node_index]->full_name);
951-
if (np == nodes[last_node_index]) {
952-
if (of_aliases == np) {
953-
of_node_put(of_aliases);
954-
of_aliases = NULL;
955-
}
956-
detach_node_and_children(np);
957-
} else {
958-
for_each_property_of_node(np, prop) {
959-
if (strcmp(prop->name, "testcase-alias") == 0)
960-
of_remove_property(np, prop);
961-
}
962-
}
963-
}
964-
}
965-
}
966-
967924
#ifdef CONFIG_OF_OVERLAY
968925

969926
static int selftest_probe(struct platform_device *pdev)
@@ -1475,9 +1432,6 @@ static int __init of_selftest(void)
14751432
of_selftest_platform_populate();
14761433
of_selftest_overlay();
14771434

1478-
/* removing selftest data from live tree */
1479-
selftest_data_remove();
1480-
14811435
/* Double check linkage after removing testcase data */
14821436
of_selftest_check_tree_linkage();
14831437

0 commit comments

Comments
 (0)