diff mbox series

[V3,XRT,Alveo,Infrastructure,3/8] of: create empty of root

Message ID 20211204003957.1448567-4-lizhi.hou@xilinx.com
State Superseded, archived
Headers show
Series XRT Alveo driver infrastructure overview | expand

Checks

Context Check Description
robh/checkpatch success
robh/dtbs-check success
robh/dt-meta-schema success

Commit Message

Lizhi Hou Dec. 4, 2021, 12:39 a.m. UTC
When OF_FLATTREE is selected and there is not a device tree, create an
empty device tree root node. of/unittest.c code is referenced.

Signed-off-by: Sonal Santan <sonal.santan@xilinx.com>
Signed-off-by: Max Zhen <max.zhen@xilinx.com>
Signed-off-by: Lizhi Hou <lizhi.hou@xilinx.com>
---
 drivers/of/Makefile        |  5 +++
 drivers/of/fdt.c           | 61 +++++++++++++++++++++++++++++++++
 drivers/of/fdt_default.dts |  5 +++
 drivers/of/of_private.h    | 15 ++++++++
 drivers/of/unittest.c      | 70 ++------------------------------------
 5 files changed, 89 insertions(+), 67 deletions(-)
 create mode 100644 drivers/of/fdt_default.dts

Comments

kernel test robot Dec. 4, 2021, 4:41 a.m. UTC | #1
Hi Lizhi,

I love your patch! Yet something to improve:

[auto build test ERROR on robh/for-next]
[also build test ERROR on linux/master linus/master v5.16-rc3 next-20211203]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Lizhi-Hou/XRT-Alveo-driver-infrastructure-overview/20211204-084333
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: nds32-allnoconfig (https://download.01.org/0day-ci/archive/20211204/202112041242.HCDtTlb5-lkp@intel.com/config)
compiler: nds32le-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/1b36c19ebc303a293dff82ed399ea70bf4ddde50
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Lizhi-Hou/XRT-Alveo-driver-infrastructure-overview/20211204-084333
        git checkout 1b36c19ebc303a293dff82ed399ea70bf4ddde50
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=nds32 SHELL=/bin/bash drivers/of/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/of/fdt.c: In function 'of_fdt_root_init':
>> drivers/of/fdt.c:505:14: error: implicit declaration of function 'of_resolve_phandles'; did you mean 'of_parse_phandle'? [-Werror=implicit-function-declaration]
     505 |         rc = of_resolve_phandles(dt);
         |              ^~~~~~~~~~~~~~~~~~~
         |              of_parse_phandle
   cc1: some warnings being treated as errors


vim +505 drivers/of/fdt.c

   468	
   469	static int __init of_fdt_root_init(void)
   470	{
   471		struct device_node *dt = NULL, *np;
   472		void *fdt, *fdt_aligned;
   473		int size, rc;
   474	
   475	#if !defined(CONFIG_OF_UNITTEST)
   476		if (of_root)
   477			return 0;
   478	#endif
   479		size = __dtb_fdt_default_end - __dtb_fdt_default_begin;
   480	
   481		fdt = kmalloc(size + FDT_ALIGN_SIZE, GFP_KERNEL);
   482		if (!fdt)
   483			return -ENOMEM;
   484	
   485		fdt_aligned = PTR_ALIGN(fdt, FDT_ALIGN_SIZE);
   486		memcpy(fdt_aligned, __dtb_fdt_default_begin, size);
   487	
   488		if (!of_fdt_unflatten_tree((const unsigned long *)fdt_aligned,
   489					   NULL, &dt)) {
   490			pr_warn("%s: unflatten default tree failed\n", __func__);
   491			kfree(fdt);
   492			return -ENODATA;
   493		}
   494		if (!dt) {
   495			pr_warn("%s: empty default tree\n", __func__);
   496			kfree(fdt);
   497			return -ENODATA;
   498		}
   499	
   500		/*
   501		 * This lock normally encloses of_resolve_phandles()
   502		 */
   503		of_overlay_mutex_lock();
   504	
 > 505		rc = of_resolve_phandles(dt);
   506		if (rc) {
   507			pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
   508			of_overlay_mutex_unlock();
   509			return -EINVAL;
   510		}
   511	
   512		if (!of_root) {
   513			of_root = dt;
   514			for_each_of_allnodes(np)
   515				__of_attach_node_sysfs(np);
   516			of_aliases = of_find_node_by_path("/aliases");
   517			of_chosen = of_find_node_by_path("/chosen");
   518			of_overlay_mutex_unlock();
   519			return 0;
   520		}
   521	
   522		unittest_data_add(dt);
   523	
   524		of_overlay_mutex_unlock();
   525	
   526		return 0;
   527	}
   528	pure_initcall(of_fdt_root_init);
   529	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Dec. 4, 2021, 2:16 p.m. UTC | #2
Hi Lizhi,

I love your patch! Yet something to improve:

[auto build test ERROR on robh/for-next]
[also build test ERROR on linux/master linus/master v5.16-rc3 next-20211203]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Lizhi-Hou/XRT-Alveo-driver-infrastructure-overview/20211204-084333
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: mips-randconfig-c004-20211203 (https://download.01.org/0day-ci/archive/20211204/202112042255.DZihRncD-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 5f1d1854eb1450d352663ee732235893c5782237)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # https://github.com/0day-ci/linux/commit/1b36c19ebc303a293dff82ed399ea70bf4ddde50
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Lizhi-Hou/XRT-Alveo-driver-infrastructure-overview/20211204-084333
        git checkout 1b36c19ebc303a293dff82ed399ea70bf4ddde50
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/of/fdt.c:505:7: error: implicit declaration of function 'of_resolve_phandles' [-Werror,-Wimplicit-function-declaration]
           rc = of_resolve_phandles(dt);
                ^
   1 error generated.


vim +/of_resolve_phandles +505 drivers/of/fdt.c

   468	
   469	static int __init of_fdt_root_init(void)
   470	{
   471		struct device_node *dt = NULL, *np;
   472		void *fdt, *fdt_aligned;
   473		int size, rc;
   474	
   475	#if !defined(CONFIG_OF_UNITTEST)
   476		if (of_root)
   477			return 0;
   478	#endif
   479		size = __dtb_fdt_default_end - __dtb_fdt_default_begin;
   480	
   481		fdt = kmalloc(size + FDT_ALIGN_SIZE, GFP_KERNEL);
   482		if (!fdt)
   483			return -ENOMEM;
   484	
   485		fdt_aligned = PTR_ALIGN(fdt, FDT_ALIGN_SIZE);
   486		memcpy(fdt_aligned, __dtb_fdt_default_begin, size);
   487	
   488		if (!of_fdt_unflatten_tree((const unsigned long *)fdt_aligned,
   489					   NULL, &dt)) {
   490			pr_warn("%s: unflatten default tree failed\n", __func__);
   491			kfree(fdt);
   492			return -ENODATA;
   493		}
   494		if (!dt) {
   495			pr_warn("%s: empty default tree\n", __func__);
   496			kfree(fdt);
   497			return -ENODATA;
   498		}
   499	
   500		/*
   501		 * This lock normally encloses of_resolve_phandles()
   502		 */
   503		of_overlay_mutex_lock();
   504	
 > 505		rc = of_resolve_phandles(dt);
   506		if (rc) {
   507			pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
   508			of_overlay_mutex_unlock();
   509			return -EINVAL;
   510		}
   511	
   512		if (!of_root) {
   513			of_root = dt;
   514			for_each_of_allnodes(np)
   515				__of_attach_node_sysfs(np);
   516			of_aliases = of_find_node_by_path("/aliases");
   517			of_chosen = of_find_node_by_path("/chosen");
   518			of_overlay_mutex_unlock();
   519			return 0;
   520		}
   521	
   522		unittest_data_add(dt);
   523	
   524		of_overlay_mutex_unlock();
   525	
   526		return 0;
   527	}
   528	pure_initcall(of_fdt_root_init);
   529	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index c13b982084a3..a2989055c578 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,5 +1,6 @@ 
 # SPDX-License-Identifier: GPL-2.0
 obj-y = base.o device.o platform.o property.o
+
 obj-$(CONFIG_OF_KOBJ) += kobj.o
 obj-$(CONFIG_OF_DYNAMIC) += dynamic.o
 obj-$(CONFIG_OF_FLATTREE) += fdt.o
@@ -20,4 +21,8 @@  obj-y	+= kexec.o
 endif
 endif
 
+ifndef CONFIG_OF_UNITTEST
+obj-$(CONFIG_OF_FLATTREE) += fdt_default.dtb.o
+endif
+
 obj-$(CONFIG_OF_UNITTEST) += unittest-data/
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 4546572af24b..0b3577f08e1d 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -466,6 +466,67 @@  void *of_fdt_unflatten_tree(const unsigned long *blob,
 }
 EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree);
 
+static int __init of_fdt_root_init(void)
+{
+	struct device_node *dt = NULL, *np;
+	void *fdt, *fdt_aligned;
+	int size, rc;
+
+#if !defined(CONFIG_OF_UNITTEST)
+	if (of_root)
+		return 0;
+#endif
+	size = __dtb_fdt_default_end - __dtb_fdt_default_begin;
+
+	fdt = kmalloc(size + FDT_ALIGN_SIZE, GFP_KERNEL);
+	if (!fdt)
+		return -ENOMEM;
+
+	fdt_aligned = PTR_ALIGN(fdt, FDT_ALIGN_SIZE);
+	memcpy(fdt_aligned, __dtb_fdt_default_begin, size);
+
+	if (!of_fdt_unflatten_tree((const unsigned long *)fdt_aligned,
+				   NULL, &dt)) {
+		pr_warn("%s: unflatten default tree failed\n", __func__);
+		kfree(fdt);
+		return -ENODATA;
+	}
+	if (!dt) {
+		pr_warn("%s: empty default tree\n", __func__);
+		kfree(fdt);
+		return -ENODATA;
+	}
+
+	/*
+	 * This lock normally encloses of_resolve_phandles()
+	 */
+	of_overlay_mutex_lock();
+
+	rc = of_resolve_phandles(dt);
+	if (rc) {
+		pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
+		of_overlay_mutex_unlock();
+		return -EINVAL;
+	}
+
+	if (!of_root) {
+		of_root = dt;
+		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;
+	}
+
+	unittest_data_add(dt);
+
+	of_overlay_mutex_unlock();
+
+	return 0;
+}
+pure_initcall(of_fdt_root_init);
+
 /* Everything below here references initial_boot_params directly. */
 int __initdata dt_root_addr_cells;
 int __initdata dt_root_size_cells;
diff --git a/drivers/of/fdt_default.dts b/drivers/of/fdt_default.dts
new file mode 100644
index 000000000000..d1f12a76dfc6
--- /dev/null
+++ b/drivers/of/fdt_default.dts
@@ -0,0 +1,5 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+
+/ {
+};
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index 631489f7f8c0..af74ef1185be 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -41,6 +41,21 @@  extern struct mutex of_mutex;
 extern struct list_head aliases_lookup;
 extern struct kset *of_kset;
 
+#if defined(CONFIG_OF_UNITTEST)
+extern u8 __dtb_testcases_begin[];
+extern u8 __dtb_testcases_end[];
+#define __dtb_fdt_default_begin		__dtb_testcases_begin
+#define __dtb_fdt_default_end		__dtb_testcases_end
+int __init unittest_data_add(struct device_node *dt);
+#else
+extern u8 __dtb_fdt_default_begin[];
+extern u8 __dtb_fdt_default_end[];
+static inline int unittest_data_add(struct device_node *dt)
+{
+	return 0;
+}
+#endif
+
 #if defined(CONFIG_OF_DYNAMIC)
 extern int of_property_notify(int action, struct device_node *np,
 			      struct property *prop, struct property *old_prop);
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 8c056972a6dd..bc0b3184a6ce 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1402,73 +1402,15 @@  static void attach_node_and_children(struct device_node *np)
  *	unittest_data_add - Reads, copies data from
  *	linked tree and attaches it to the live tree
  */
-static int __init unittest_data_add(void)
+int __init unittest_data_add(struct device_node *dt)
 {
-	void *unittest_data;
-	void *unittest_data_align;
-	struct device_node *unittest_data_node = NULL, *np;
-	/*
-	 * __dtb_testcases_begin[] and __dtb_testcases_end[] are magically
-	 * created by cmd_dt_S_dtb in scripts/Makefile.lib
-	 */
-	extern uint8_t __dtb_testcases_begin[];
-	extern uint8_t __dtb_testcases_end[];
-	const int size = __dtb_testcases_end - __dtb_testcases_begin;
-	int rc;
-	void *ret;
-
-	if (!size) {
-		pr_warn("%s: testcases is empty\n", __func__);
-		return -ENODATA;
-	}
-
-	/* creating copy */
-	unittest_data = kmalloc(size + FDT_ALIGN_SIZE, GFP_KERNEL);
-	if (!unittest_data)
-		return -ENOMEM;
-
-	unittest_data_align = PTR_ALIGN(unittest_data, FDT_ALIGN_SIZE);
-	memcpy(unittest_data_align, __dtb_testcases_begin, size);
-
-	ret = of_fdt_unflatten_tree(unittest_data_align, NULL, &unittest_data_node);
-	if (!ret) {
-		pr_warn("%s: unflatten testcases tree failed\n", __func__);
-		kfree(unittest_data);
-		return -ENODATA;
-	}
-	if (!unittest_data_node) {
-		pr_warn("%s: testcases tree is empty\n", __func__);
-		kfree(unittest_data);
-		return -ENODATA;
-	}
-
-	/*
-	 * This lock normally encloses of_resolve_phandles()
-	 */
-	of_overlay_mutex_lock();
-
-	rc = of_resolve_phandles(unittest_data_node);
-	if (rc) {
-		pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
-		of_overlay_mutex_unlock();
-		return -EINVAL;
-	}
-
-	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;
-	}
+	struct device_node *np;
 
 	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;
+	np = dt->child;
 	while (np) {
 		struct device_node *next = np->sibling;
 
@@ -1480,8 +1422,6 @@  static int __init unittest_data_add(void)
 	EXPECT_END(KERN_INFO,
 		   "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
 
-	of_overlay_mutex_unlock();
-
 	return 0;
 }
 
@@ -3258,7 +3198,6 @@  static inline __init void of_unittest_overlay_high_level(void) {}
 static int __init of_unittest(void)
 {
 	struct device_node *np;
-	int res;
 
 	pr_info("start of unittest - you will see error messages\n");
 
@@ -3267,9 +3206,6 @@  static int __init of_unittest(void)
 	if (IS_ENABLED(CONFIG_UML))
 		unittest_unflatten_overlay_base();
 
-	res = unittest_data_add();
-	if (res)
-		return res;
 	if (!of_aliases)
 		of_aliases = of_find_node_by_path("/aliases");