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: [email protected]
> Signed-off-by: Guangshuo Li <[email protected]>
> ---
> 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
>