summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorLi Jun <lijun01@kylinos.cn>2026-03-26 09:29:08 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-04-02 14:23:24 +0300
commita1da957c25cf751a2dce8fb7777f82ccbac0cb3e (patch)
tree8d4d4f280733635723285bd82af874fa00344c68 /arch
parent70e2eb91cb6310a3508439f6f2539dfffa0abf77 (diff)
downloadlinux-a1da957c25cf751a2dce8fb7777f82ccbac0cb3e.tar.xz
LoongArch: Fix missing NULL checks for kstrdup()
commit 3a28daa9b7d7c2ddf2c722e9e95d7e0928bf0cd1 upstream. 1. Replace "of_find_node_by_path("/")" with "of_root" to avoid multiple calls to "of_node_put()". 2. Fix a potential kernel oops during early boot when memory allocation fails while parsing CPU model from device tree. Cc: stable@vger.kernel.org Signed-off-by: Li Jun <lijun01@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/loongarch/kernel/env.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
index 23bd5ae2212c..b28554f702d2 100644
--- a/arch/loongarch/kernel/env.c
+++ b/arch/loongarch/kernel/env.c
@@ -42,16 +42,15 @@ static int __init init_cpu_fullname(void)
int cpu, ret;
char *cpuname;
const char *model;
- struct device_node *root;
/* Parsing cpuname from DTS model property */
- root = of_find_node_by_path("/");
- ret = of_property_read_string(root, "model", &model);
+ ret = of_property_read_string(of_root, "model", &model);
if (ret == 0) {
cpuname = kstrdup(model, GFP_KERNEL);
+ if (!cpuname)
+ return -ENOMEM;
loongson_sysconf.cpuname = strsep(&cpuname, " ");
}
- of_node_put(root);
if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
for (cpu = 0; cpu < NR_CPUS; cpu++)