[PATCH v6 1/2] of: kobj: export of_node_ktype for use by modules

From: Xu Yang

Date: Tue Jul 21 2026 - 07:10:28 EST


From: Xu Yang <xu.yang_2@xxxxxxx>

of_node_init() is a static inline that references of_node_ktype when
CONFIG_OF_KOBJ=y. Any module that calls of_node_init() will therefore
have an unresolved reference to of_node_ktype at load time, because
the symbol is defined in drivers/of/kobj.c but was never exported.

This causes a modpost build error when CONFIG_OF_KOBJ=y and
CONFIG_DRIVER_PE_KUNIT_TEST=m:

ERROR: modpost: "of_node_ktype"
[drivers/base/test/property-entry-test.ko] undefined!

Add EXPORT_SYMBOL_IF_KUNIT(of_node_ktype) so that modules such as the
KUnit property-entry test can call of_node_init() without hitting this
linker error.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202607181651.RnUuV8n6-lkp@xxxxxxxxx/
Signed-off-by: Xu Yang <xu.yang_2@xxxxxxx>

---
Changes in v6:
- use EXPORT_SYMBOL_IF_KUNIT as suggested by Andy Shevchenko
Changes in v5:
- new one
---
drivers/of/kobj.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c
index 1bb61a2c3399..081b8fa38603 100644
--- a/drivers/of/kobj.c
+++ b/drivers/of/kobj.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/of.h>
#include <linux/slab.h>
+#include <kunit/visibility.h>

#include "of_private.h"

@@ -27,6 +28,7 @@ static void of_node_release(struct kobject *kobj)
const struct kobj_type of_node_ktype = {
.release = of_node_release,
};
+EXPORT_SYMBOL_IF_KUNIT(of_node_ktype);

static ssize_t of_node_property_read(struct file *filp, struct kobject *kobj,
const struct bin_attribute *bin_attr, char *buf,
--
2.34.1