loongarch.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Binbin Zhou <zhoubb.aaron@gmail.com>
To: Li Jun <lijun01@kylinos.cn>
Cc: chenhuacai@kernel.org, loongarch@lists.linux.dev,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] Loongarch: env: fix missing NULL checks for kstrdup
Date: Thu, 19 Mar 2026 10:40:48 +0800	[thread overview]
Message-ID: <CAMpQs4KoYxW9024vQ=24rYOzN5Qg-L+RYR=bx7LtaTkETuWYaA@mail.gmail.com> (raw)
In-Reply-To: <20260319005326.3796676-1-lijun01@kylinos.cn>

Hi Jun:

On Thu, Mar 19, 2026 at 8:53 AM Li Jun <lijun01@kylinos.cn> wrote:
>
> 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);

Replacing `of_find_node_by_path(“/”)` with `of_root` avoids multiple
calls to `of_node_put()`.

> +                       return -ENOMEM;
> +               }
>                 loongson_sysconf.cpuname = strsep(&cpuname, " ");
>         }
>         of_node_put(root);
> --
> 2.25.1
>
>

-- 
Thanks.
Binbin

      reply	other threads:[~2026-03-19  2:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19  0:53 [PATCH v2] Loongarch: env: fix missing NULL checks for kstrdup Li Jun
2026-03-19  2:40 ` Binbin Zhou [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='CAMpQs4KoYxW9024vQ=24rYOzN5Qg-L+RYR=bx7LtaTkETuWYaA@mail.gmail.com' \
    --to=zhoubb.aaron@gmail.com \
    --cc=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).