The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [KJ] replacing kmalloc with kzalloc in io_apic.c
@ 2007-08-13  8:31 Surya Prabhakar N
  2007-08-13 13:18 ` Mariusz Kozlowski
  0 siblings, 1 reply; 5+ messages in thread
From: Surya Prabhakar N @ 2007-08-13  8:31 UTC (permalink / raw)
  To: mingo; +Cc: yaku, kisimoto, zab, Linux Kernel

Hi,
   Replacing kmalloc with kzalloc and cleaning up memset in 
arch/i386/kernel/io_apic.c


Signed-off-by: Surya Prabhakar <surya.prabhakar@wipro.com>
--- 

diff --git a/arch/i386/kernel/io_apic.c b/arch/i386/kernel/io_apic.c
index 4b8a8da..1329615 100644
--- a/arch/i386/kernel/io_apic.c
+++ b/arch/i386/kernel/io_apic.c
@@ -690,14 +690,12 @@ static int __init balanced_irq_init(void)
 		physical_balance = 1;
 
 	for_each_online_cpu(i) {
-		irq_cpu_data[i].irq_delta = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
-		irq_cpu_data[i].last_irq = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
+		irq_cpu_data[i].irq_delta = kzalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
+		irq_cpu_data[i].last_irq = kzalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
 		if (irq_cpu_data[i].irq_delta == NULL || irq_cpu_data[i].last_irq == NULL) {
 			printk(KERN_ERR "balanced_irq_init: out of memory");
 			goto failed;
 		}
-		memset(irq_cpu_data[i].irq_delta,0,sizeof(unsigned long) * NR_IRQS);
-		memset(irq_cpu_data[i].last_irq,0,sizeof(unsigned long) * NR_IRQS);
 	}
 	
 	printk(KERN_INFO "Starting balanced_irq\n");



thanks
surya.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [KJ] replacing kmalloc with kzalloc in io_apic.c
  2007-08-13  8:31 [KJ] replacing kmalloc with kzalloc in io_apic.c Surya Prabhakar N
@ 2007-08-13 13:18 ` Mariusz Kozlowski
  2007-08-13 15:54   ` Robert P. J. Day
  0 siblings, 1 reply; 5+ messages in thread
From: Mariusz Kozlowski @ 2007-08-13 13:18 UTC (permalink / raw)
  To: surya.prabhakar; +Cc: mingo, yaku, kisimoto, zab, Linux Kernel

> Hi,
>    Replacing kmalloc with kzalloc and cleaning up memset in
> arch/i386/kernel/io_apic.c
>
>
> Signed-off-by: Surya Prabhakar <surya.prabhakar@wipro.com>
> ---
>
> diff --git a/arch/i386/kernel/io_apic.c b/arch/i386/kernel/io_apic.c
> index 4b8a8da..1329615 100644
> --- a/arch/i386/kernel/io_apic.c
> +++ b/arch/i386/kernel/io_apic.c
> @@ -690,14 +690,12 @@ static int __init balanced_irq_init(void)
>  		physical_balance = 1;
>
>  	for_each_online_cpu(i) {
> -		irq_cpu_data[i].irq_delta = kmalloc(sizeof(unsigned long) * NR_IRQS,
> GFP_KERNEL); -		irq_cpu_data[i].last_irq = kmalloc(sizeof(unsigned long) *
> NR_IRQS, GFP_KERNEL); +		irq_cpu_data[i].irq_delta =
> kzalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
> +		irq_cpu_data[i].last_irq = kzalloc(sizeof(unsigned long) * NR_IRQS,
> GFP_KERNEL); if (irq_cpu_data[i].irq_delta == NULL ||
> irq_cpu_data[i].last_irq == NULL) { printk(KERN_ERR "balanced_irq_init: out
> of memory");
>  			goto failed;
>  		}
> -		memset(irq_cpu_data[i].irq_delta,0,sizeof(unsigned long) * NR_IRQS);
> -		memset(irq_cpu_data[i].last_irq,0,sizeof(unsigned long) * NR_IRQS);
>  	}
>
>  	printk(KERN_INFO "Starting balanced_irq\n");

How about using kcalloc here?

i.e. 
...
... = kcalloc(NR_IRQS, sizeof(unsigned long), GFP_KERNEL);
...

Regards,

	Mariusz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [KJ] replacing kmalloc with kzalloc in io_apic.c
  2007-08-13 13:18 ` Mariusz Kozlowski
@ 2007-08-13 15:54   ` Robert P. J. Day
  2007-08-13 17:27     ` Roland Dreier
  0 siblings, 1 reply; 5+ messages in thread
From: Robert P. J. Day @ 2007-08-13 15:54 UTC (permalink / raw)
  To: Mariusz Kozlowski
  Cc: surya.prabhakar, mingo, yaku, kisimoto, zab, Linux Kernel

On Mon, 13 Aug 2007, Mariusz Kozlowski wrote:

> > Hi,
> >    Replacing kmalloc with kzalloc and cleaning up memset in
> > arch/i386/kernel/io_apic.c
> >
> >
> > Signed-off-by: Surya Prabhakar <surya.prabhakar@wipro.com>
> > ---
> >
> > diff --git a/arch/i386/kernel/io_apic.c b/arch/i386/kernel/io_apic.c
> > index 4b8a8da..1329615 100644
> > --- a/arch/i386/kernel/io_apic.c
> > +++ b/arch/i386/kernel/io_apic.c
> > @@ -690,14 +690,12 @@ static int __init balanced_irq_init(void)
> >  		physical_balance = 1;
> >
> >  	for_each_online_cpu(i) {
> > -		irq_cpu_data[i].irq_delta = kmalloc(sizeof(unsigned long) * NR_IRQS,
> > GFP_KERNEL); -		irq_cpu_data[i].last_irq = kmalloc(sizeof(unsigned long) *
> > NR_IRQS, GFP_KERNEL); +		irq_cpu_data[i].irq_delta =
> > kzalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
> > +		irq_cpu_data[i].last_irq = kzalloc(sizeof(unsigned long) * NR_IRQS,
> > GFP_KERNEL); if (irq_cpu_data[i].irq_delta == NULL ||
> > irq_cpu_data[i].last_irq == NULL) { printk(KERN_ERR "balanced_irq_init: out
> > of memory");
> >  			goto failed;
> >  		}
> > -		memset(irq_cpu_data[i].irq_delta,0,sizeof(unsigned long) * NR_IRQS);
> > -		memset(irq_cpu_data[i].last_irq,0,sizeof(unsigned long) * NR_IRQS);
> >  	}
> >
> >  	printk(KERN_INFO "Starting balanced_irq\n");
>
> How about using kcalloc here?
>
> i.e.
> ...
> ... = kcalloc(NR_IRQS, sizeof(unsigned long), GFP_KERNEL);
> ...

from my days submitting numerous patches of this type, i can recall
that in cases like the above, it's a judgment call -- use kzalloc to
get the zeroing, or use kcalloc to get the array-flavoured behaviour.
what a shame you can't have both at the same time.

rday
-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [KJ] replacing kmalloc with kzalloc in io_apic.c
  2007-08-13 17:27     ` Roland Dreier
@ 2007-08-13 17:26       ` Robert P. J. Day
  0 siblings, 0 replies; 5+ messages in thread
From: Robert P. J. Day @ 2007-08-13 17:26 UTC (permalink / raw)
  To: Roland Dreier
  Cc: Mariusz Kozlowski, surya.prabhakar, mingo, yaku, kisimoto, zab,
	Linux Kernel

On Mon, 13 Aug 2007, Roland Dreier wrote:

>  > from my days submitting numerous patches of this type, i can recall
>  > that in cases like the above, it's a judgment call -- use kzalloc to
>  > get the zeroing, or use kcalloc to get the array-flavoured behaviour.
>  > what a shame you can't have both at the same time.
>
> kcalloc() zeros memory just like standard calloc() in userspace.
>
> As <linux/slab.h> says:
>
>  * kcalloc - allocate memory for an array. The memory is set to zero.

oops.  quite right, my bad.

rday
-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [KJ] replacing kmalloc with kzalloc in io_apic.c
  2007-08-13 15:54   ` Robert P. J. Day
@ 2007-08-13 17:27     ` Roland Dreier
  2007-08-13 17:26       ` Robert P. J. Day
  0 siblings, 1 reply; 5+ messages in thread
From: Roland Dreier @ 2007-08-13 17:27 UTC (permalink / raw)
  To: Robert P. J. Day
  Cc: Mariusz Kozlowski, surya.prabhakar, mingo, yaku, kisimoto, zab,
	Linux Kernel

 > from my days submitting numerous patches of this type, i can recall
 > that in cases like the above, it's a judgment call -- use kzalloc to
 > get the zeroing, or use kcalloc to get the array-flavoured behaviour.
 > what a shame you can't have both at the same time.

kcalloc() zeros memory just like standard calloc() in userspace.

As <linux/slab.h> says:

 * kcalloc - allocate memory for an array. The memory is set to zero.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-08-13 17:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-13  8:31 [KJ] replacing kmalloc with kzalloc in io_apic.c Surya Prabhakar N
2007-08-13 13:18 ` Mariusz Kozlowski
2007-08-13 15:54   ` Robert P. J. Day
2007-08-13 17:27     ` Roland Dreier
2007-08-13 17:26       ` Robert P. J. Day

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox