loongarch.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
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 13:39:34 +0800	[thread overview]
Message-ID: <20260320053934.2306138-1-lijun01@kylinos.cn> (raw)

1.Replacing `of_find_node_by_path("/")` with `of_root` avoids multiple
calls to `of_node_put()`.
2.Fixes potential kernel oops during early boot when memory
allocation fails while parsing CPU model from device tree.

--Replacing `of_find_node_by_path("/")` with `of_root`,

Signed-off-by: Li Jun <lijun01@kylinos.cn>
---
 arch/loongarch/kernel/env.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
index 841206fde3ab..652456768b55 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++)
-- 
2.34.1


             reply	other threads:[~2026-03-20  5:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20  5:39 Li Jun [this message]
2026-03-26  2:50 ` [PATCH v4] LoongArch: env: fix missing NULL checks for kstrdup Huacai Chen
  -- strict thread matches above, loose matches on Subject: below --
2026-03-20  0:47 Li Jun
2026-03-20  3:29 ` 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=20260320053934.2306138-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).