[v4,2/2] of: unittest: treat missing of_root as error instead of fixing up

Message ID 20230317053415.2254616-3-frowand.list@gmail.com
State New
Headers
Series of: populate of_root_node if not set (alternate) |

Commit Message

Frank Rowand March 17, 2023, 5:34 a.m. UTC
  setup_of() now ensures that of_root node is populated with the
root of a default devicetree. Remove the unittest code that
created of_root if it was missing.  Verify that of_root is
valid before attempting to attach the testcase-data subtree.
Remove the unittest code that unflattens the unittest overlay
base if architecture is UML.

Signed-off-by: Frank Rowand <frowand.list@gmail.com>
---

Changes since version 3:
  - refresh for 6.3-rc1
  - remove the CONFIG_UML case of populating the devicetree
  - unittest_data_add() - move an EXPECT_BEGIN() to after an error
    check that can result in an early return

Changes since version 2:
  - none

Changes since version 1:
  - refresh for 6.2-rc1
  - update Signed-off-by
  - fix formatting error (leading space) in patch comment

 drivers/of/unittest.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
  

Patch

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index b5a7a31d8bd2..8dc293ac08b7 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1476,20 +1476,16 @@  static int __init unittest_data_add(void)
 		return -EINVAL;
 	}
 
+	/* attach the sub-tree to live tree */
 	if (!of_root) {
-		of_root = unittest_data_node;
-		for_each_of_allnodes(np)
-			__of_attach_node_sysfs(np);
-		of_aliases = of_find_node_by_path("/aliases");
-		of_chosen = of_find_node_by_path("/chosen");
-		of_overlay_mutex_unlock();
-		return 0;
+		pr_warn("%s: no live tree to attach sub-tree\n", __func__);
+		kfree(unittest_data);
+		return -ENODEV;
 	}
 
 	EXPECT_BEGIN(KERN_INFO,
 		     "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
 
-	/* attach the sub-tree to live tree */
 	np = unittest_data_node->child;
 	while (np) {
 		struct device_node *next = np->sibling;
@@ -3612,10 +3608,6 @@  static int __init of_unittest(void)
 	add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
 
 	/* adding data for unittest */
-
-	if (IS_ENABLED(CONFIG_UML))
-		unittest_unflatten_overlay_base();
-
 	res = unittest_data_add();
 	if (res)
 		return res;