lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220126054807.492651-2-lizhi.hou@xilinx.com>
Date:   Tue, 25 Jan 2022 21:48:07 -0800
From:   Lizhi Hou <lizhi.hou@...inx.com>
To:     <devicetree@...r.kernel.org>, <robh@...nel.org>
CC:     Lizhi Hou <lizhi.hou@...inx.com>, <linux-kernel@...r.kernel.org>,
        <yilun.xu@...el.com>, <maxz@...inx.com>, <sonal.santan@...inx.com>,
        <yliu@...inx.com>, <michal.simek@...inx.com>,
        <stefanos@...inx.com>, <trix@...hat.com>, <mdf@...nel.org>,
        <dwmw2@...radead.org>, Max Zhen <max.zhen@...inx.com>
Subject: [PATCH V1 Create empty OF root 1/1] of: create empty of root

Add OF_EMPTY_ROOT config. When it is selected and there is not a device
tree, create an empty device tree root node.

Signed-off-by: Sonal Santan <sonal.santan@...inx.com>
Signed-off-by: Max Zhen <max.zhen@...inx.com>
Signed-off-by: Lizhi Hou <lizhi.hou@...inx.com>
---
 drivers/of/Kconfig         |  3 +++
 drivers/of/Makefile        |  1 +
 drivers/of/of_empty_root.c | 51 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 drivers/of/of_empty_root.c

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 80b5fd44ab1c..42afb126f91a 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -94,4 +94,7 @@ config OF_DMA_DEFAULT_COHERENT
 	# arches should select this if DMA is coherent by default for OF devices
 	bool
 
+config OF_EMPTY_ROOT
+	bool
+
 endif # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index e0360a44306e..c65364f32935 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
 obj-$(CONFIG_OF_RESOLVE)  += resolver.o
 obj-$(CONFIG_OF_OVERLAY) += overlay.o
 obj-$(CONFIG_OF_NUMA) += of_numa.o
+obj-$(CONFIG_OF_EMPTY_ROOT) += of_empty_root.o
 
 ifdef CONFIG_KEXEC_FILE
 ifdef CONFIG_OF_FLATTREE
diff --git a/drivers/of/of_empty_root.c b/drivers/of/of_empty_root.c
new file mode 100644
index 000000000000..5c429c7a27bd
--- /dev/null
+++ b/drivers/of/of_empty_root.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 Xilinx, Inc.
+ */
+
+#include <linux/of.h>
+#include <linux/slab.h>
+
+#include "of_private.h"
+
+static int __init of_root_init(void)
+{
+	struct property *prop = NULL;
+	struct device_node *node;
+	__be32 *val = NULL;
+
+	if (of_root)
+		return 0;
+
+	pr_info("Create empty OF root node\n");
+	node = kzalloc(sizeof(*node), GFP_KERNEL);
+	if (!node)
+		return -ENOMEM;
+	of_node_init(node);
+	node->full_name = "/";
+
+	prop = kcalloc(2, sizeof(*prop), GFP_KERNEL);
+	if (!prop)
+		return -ENOMEM;
+
+	val = kzalloc(sizeof(*val), GFP_KERNEL);
+	if (!val)
+		return -ENOMEM;
+	*val = cpu_to_be32(sizeof(void *) / sizeof(u32));
+
+	prop->name = "#address-cells";
+	prop->value = val;
+	prop->length = sizeof(u32);
+	of_add_property(node, prop);
+	prop++;
+	prop->name = "#size-cells";
+	prop->value = val;
+	prop->length = sizeof(u32);
+	of_add_property(node, prop);
+	of_root = node;
+	for_each_of_allnodes(node)
+		__of_attach_node_sysfs(node);
+
+	return 0;
+}
+pure_initcall(of_root_init);
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ