From: Huacai Chen <chenhuacai@kernel.org>
To: Li Jun <lijun01@kylinos.cn>
Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] Loongarch: env: fix missing NULL checks for kstrdup
Date: Thu, 19 Mar 2026 16:31:02 +0800 [thread overview]
Message-ID: <CAAhV-H6Q2U2eNQFZmrOz9qATJhd3ri2SDpfA2ZHkazx5vLCxtw@mail.gmail.com> (raw)
In-Reply-To: <20260319055801.4187615-1-lijun01@kylinos.cn>
Hi, Jun,
Please replace Loongarch with LoongArch, and...
On Thu, Mar 19, 2026 at 1:58 PM Li Jun <lijun01@kylinos.cn> wrote:
>
> 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`,
> Fix missing NULL checks.
Why say it again?
>
> Signed-off-by: Li Jun <lijun01@kylinos.cn>
> ---
> arch/loongarch/kernel/env.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
> index 841206fde3ab..2afc9b09f139 100644
> --- a/arch/loongarch/kernel/env.c
> +++ b/arch/loongarch/kernel/env.c
> @@ -15,6 +15,7 @@
> #include <asm/loongson.h>
> #include <asm/setup.h>
> #include <asm/time.h>
> +#include <linux/of.h>
I don't think this is needed, we already use of_find_node_by_path in
of.h, which means it has already been included implicitly.
Huacai
>
> u64 efi_system_table;
> struct loongson_system_configuration loongson_sysconf;
> @@ -42,16 +43,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
>
>
prev parent reply other threads:[~2026-03-19 8:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 5:58 [PATCH v3] Loongarch: env: fix missing NULL checks for kstrdup Li Jun
2026-03-19 8:31 ` Huacai Chen [this message]
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=CAAhV-H6Q2U2eNQFZmrOz9qATJhd3ri2SDpfA2ZHkazx5vLCxtw@mail.gmail.com \
--to=chenhuacai@kernel.org \
--cc=lijun01@kylinos.cn \
--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).