Skip to contentSkip to conversation

replacing kmalloc with kzalloc in io_apic.c

KJ Surya Prabhakar N 4 participants 5 messages Aug 13, 2007

lore
Share & tools
lore
#0 lore raw

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

---

arch/i386/kernel/io_apic.c +2 -4
index 4b8a8da..1329615 100644
@@ -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.

#1 lore raw
Quoted 24 lines

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

---

arch/i386/kernel/io_apic.c +0 -1
index 4b8a8da..1329615 100644
@@ -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);

arch/i386/kernel/io_apic.c +1 -0
+		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");

arch/i386/kernel/io_apic.c static int __init balanced_irq_init(void) · line 701

Quoted 7 lines
arch/i386/kernel/io_apic.c +0 -2
 			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

#2 lore raw
Quoted 30 lines · Mariusz Kozlowski
Quoted 30 lines

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

---

arch/i386/kernel/io_apic.c +0 -1
index 4b8a8da..1329615 100644
@@ -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);

arch/i386/kernel/io_apic.c +1 -0
+		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");

arch/i386/kernel/io_apic.c +0 -2
 			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);
 	}
Quoted 8 lines
Quoted 1 line

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

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================
#3 lore raw
Quoted 4 lines

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.

#4 lore raw
Quoted 10 lines · Roland Dreier
Quoted 4 lines

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

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

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