From: Li Jun <lijun01@kylinos.cn>
To: chenhuacai@kernel.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org, lijun01@kylinos.cn
Subject: [PATCH v4] LoongArch: env: fix missing NULL checks for kstrdup
Date: Fri, 20 Mar 2026 08:47:25 +0800 [thread overview]
Message-ID: <20260320004725.1927073-1-lijun01@kylinos.cn> (raw)
Fixes potential kernel oops during early boot when memory
allocation fails while parsing CPU model from device tree.
before return -ENOMEM, of_node_put(root) first.
Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
arch/loongarch/kernel/env.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
index 841206fde3ab..c586de80027c 100644
--- a/arch/loongarch/kernel/env.c
+++ b/arch/loongarch/kernel/env.c
@@ -49,6 +49,10 @@ static int __init init_cpu_fullname(void)
ret = of_property_read_string(root, "model", &model);
if (ret == 0) {
cpuname = kstrdup(model, GFP_KERNEL);
+ if (!cpuname) {
+ of_node_put(root);
+ return -ENOMEM;
+ }
loongson_sysconf.cpuname = strsep(&cpuname, " ");
}
of_node_put(root);
--
2.25.1
next reply other threads:[~2026-03-20 0:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 0:47 Li Jun [this message]
2026-03-20 3:29 ` [PATCH v4] LoongArch: env: fix missing NULL checks for kstrdup Huacai Chen
-- strict thread matches above, loose matches on Subject: below --
2026-03-20 5:39 Li Jun
2026-03-26 2:50 ` Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260320004725.1927073-1-lijun01@kylinos.cn \
--to=lijun01@kylinos.cn \
--cc=chenhuacai@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).