Add a check for the return value of kobject_create_and_add to ensure
that the kobj allocation succeeds.
Signed-off-by: cuitao <cuitao@kylinos.cn>
---
v3: Removed the unnecessary debug prints.
https://lore.kernel.org/all/CAAhV-H5CjH8i81dGNxaVrzdVUiTwqMUYeuBifQ0wSW_Mw9wSTw@mail.gmail.com/
---
arch/loongarch/kernel/env.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
index c0a5dc9aeae2..e9a7ea3bc5c8 100644
--- a/arch/loongarch/kernel/env.c
+++ b/arch/loongarch/kernel/env.c
@@ -109,6 +109,9 @@ static int __init boardinfo_init(void)
struct kobject *loongson_kobj;
loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
+ if (!loongson_kobj) {
+ return -ENOMEM;
+ }
return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
}
--
2.48.1