[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250918114130-3148bc05-4e21-44d6-b19f-dde33834a32e@linutronix.de>
Date: Thu, 18 Sep 2025 11:45:19 +0200
From: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
To: Guangshuo Li <lgs201920130244@...il.com>
Cc: Madhavan Srinivasan <maddy@...ux.ibm.com>,
Michael Ellerman <mpe@...erman.id.au>, Nicholas Piggin <npiggin@...il.com>,
Christophe Leroy <christophe.leroy@...roup.eu>, Naveen N Rao <naveen@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>, "Gautham R. Shenoy" <ego@...ux.vnet.ibm.com>,
linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org, stable@...r.kernel.org
Subject: Re: [PATCH] powerpc/smp: Add check for kcalloc() in
parse_thread_groups()
On Thu, Sep 18, 2025 at 05:34:15PM +0800, Guangshuo Li wrote:
> As kcalloc() may fail, check its return value to avoid a NULL pointer
> dereference when passing it to of_property_read_u32_array().
>
> Fixes: 790a1662d3a26 ("powerpc/smp: Parse ibm,thread-groups with multiple properties")
> Cc: stable@...r.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@...il.com>
> ---
> arch/powerpc/kernel/smp.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
> index dac45694a9c9..34de27d75b1b 100644
> --- a/arch/powerpc/kernel/smp.c
> +++ b/arch/powerpc/kernel/smp.c
> @@ -822,9 +822,9 @@ static int parse_thread_groups(struct device_node *dn,
>
> count = of_property_count_u32_elems(dn, "ibm,thread-groups");
> thread_group_array = kcalloc(count, sizeof(u32), GFP_KERNEL);
> - if (!thread_group_array) {
> - ret = -ENOMEM;
> - goto out_free;
> + if (!thread_group_array) { /* check kcalloc() to avoid NULL deref */
> + ret = -ENOMEM;
> + goto out_free;
Thanks for the patch!
This diff looks wrong, did you forget to squash two commits?
The comment is unnecessary.
It is enough to just 'return -ENOMEM'.
The return value documentation needs an update, too.
> }
> ret = of_property_read_u32_array(dn, "ibm,thread-groups",
> thread_group_array, count);
> --
> 2.43.0
>
Powered by blists - more mailing lists