Re: [PATCH v4] LoongArch: env: fix missing NULL checks for kstrdup

From: Huacai Chen

Date: Thu Mar 19 2026 - 23:29:26 EST


Hi, Jun,

What are you doing? In your understanding, my comments in V3 meant to
tell you to go back to V2?

Huacai

On Fri, Mar 20, 2026 at 8:48 AM Li Jun <lijun01@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---
> 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
>