Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1476225

Re: [PATCH 3/4] x86/smpboot: Replace one kzalloc() call by kcalloc()

From Paolo Bonzini <pbonzini@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH 3/4] x86/smpboot: Replace one kzalloc() call by kcalloc()
Date 2016-09-05 11:30 +0200
Message-ID <sdYo2-1OC-11@gated-at.bofh.it> (permalink)
References <sdX8C-15T-13@gated-at.bofh.it> <sdXii-1av-23@gated-at.bofh.it> <sdYo2-1OC-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 05/09/2016 11:26, Paolo Bonzini wrote:
> 
> 
> On 05/09/2016 10:12, SF Markus Elfring wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Mon, 5 Sep 2016 09:29:40 +0200
>>
>> * The script "checkpatch.pl" can point information out like the following.
>>
>>   WARNING: Prefer kcalloc over kzalloc with multiply
>>
>>   Thus fix the affected source code place.
>>
>> * 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.
>>
>> * Delete the local variable "size" which became unnecessary with
>>   this refactoring.
>>
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>>  arch/x86/kernel/smpboot.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
>> index 2ce06ef..e3fdc44 100644
>> --- a/arch/x86/kernel/smpboot.c
>> +++ b/arch/x86/kernel/smpboot.c
>> @@ -311,7 +311,6 @@ EXPORT_SYMBOL(topology_phys_to_logical_pkg);
>>  static void __init smp_init_package_map(void)
>>  {
>>  	unsigned int ncpus, cpu;
>> -	size_t size;
>>  
>>  	/*
>>  	 * Today neither Intel nor AMD support heterogenous systems. That
>> @@ -357,8 +356,9 @@ static void __init smp_init_package_map(void)
>>  	memset(physical_to_logical_pkg,
>>  	       0xff,
>>  	       sizeof(*physical_to_logical_pkg) * max_physical_pkg_id);
>> -	size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long);
>> -	physical_package_map = kzalloc(size, GFP_KERNEL);
>> +	physical_package_map = kcalloc(BITS_TO_LONGS(max_physical_pkg_id),
>> +				       sizeof(*physical_package_map),
>> +				       GFP_KERNEL);
> 
> This is bitmap_alloc.

Doh, bitmap_alloc is only in tools/include/linux/bitmap.h, but perhaps
it makes sense to add it to include/linux/bitmap.h or
include/linux/slab.h too...

Paolo

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/4] x86/smpboot: Fine-tuning for smp_init_package_map() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-05 10:10 +0200
  [PATCH 1/4] x86/smpboot: Use kmalloc_array() in  smp_init_package_map() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-05 10:20 +0200
    Re: [PATCH 1/4] x86/smpboot: Use kmalloc_array() in  smp_init_package_map() Thomas Gleixner <tglx@linutronix.de> - 2016-09-05 11:30 +0200
  [PATCH 4/4] x86/smpboot: Return directly after a failed kcalloc() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-05 10:20 +0200
  [PATCH 2/4] x86/smpboot: Return directly after a failed  kmalloc_array() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-05 10:20 +0200
  [PATCH 3/4] x86/smpboot: Replace one kzalloc() call by kcalloc() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-05 10:20 +0200
    Re: [PATCH 3/4] x86/smpboot: Replace one kzalloc() call by kcalloc() Paolo Bonzini <pbonzini@redhat.com> - 2016-09-05 11:30 +0200
    Re: [PATCH 3/4] x86/smpboot: Replace one kzalloc() call by kcalloc() Paolo Bonzini <pbonzini@redhat.com> - 2016-09-05 11:30 +0200

csiph-web