]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
LoongArch: Fix missing NULL checks for kstrdup()
authorLi Jun <lijun01@kylinos.cn>
Thu, 26 Mar 2026 06:29:08 +0000 (14:29 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 26 Mar 2026 06:29:08 +0000 (14:29 +0800)
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>
arch/loongarch/kernel/env.c

index 841206fde3ab72ae694ad4c03c09a8352a80f178..652456768b551609841ce7d46c4ee5f984cdb22f 100644 (file)
@@ -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++)