Re: [PATCH 1/4] x86/smpboot: Use kmalloc_array() in smp_init_package_map()

From: Thomas Gleixner
Date: Mon Sep 05 2016 - 05:23:15 EST


On Mon, 5 Sep 2016, SF Markus Elfring wrote:

> From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> Date: Mon, 5 Sep 2016 08:30:20 +0200
>
> * A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "kmalloc_array".
>
> This issue was detected by using the Coccinelle software.
>
> * Replace the specification of a data type by a pointer dereference
> to make the corresponding size determination a bit safer according to
> the Linux coding style convention.
>
> * Move a calculation for one function call.
>
> Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> ---
> arch/x86/kernel/smpboot.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> index 3878725..36cf27e 100644
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -349,9 +349,12 @@ static void __init smp_init_package_map(void)
> * package can be smaller than the actual used apic ids.
> */
> max_physical_pkg_id = DIV_ROUND_UP(MAX_LOCAL_APIC, ncpus);
> - size = max_physical_pkg_id * sizeof(unsigned int);
> - physical_to_logical_pkg = kmalloc(size, GFP_KERNEL);
> - memset(physical_to_logical_pkg, 0xff, size);
> + physical_to_logical_pkg = kmalloc_array(max_physical_pkg_id,
> + sizeof(*physical_to_logical_pkg),
> + GFP_KERNEL);
> + memset(physical_to_logical_pkg,
> + 0xff,
> + sizeof(*physical_to_logical_pkg) * max_physical_pkg_id);


Why are you replacing well readable code by this line breaked crap?

Stop acting like a shell script or we might replace you by one.

Thanks,

tglx