public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc
@ 2006-11-24 12:01 Yan Burman
  2006-11-24 17:33 ` Stefan Richter
  2006-12-01  1:12 ` David Miller
  0 siblings, 2 replies; 6+ messages in thread
From: Yan Burman @ 2006-11-24 12:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: trivial, wli

Replace kmalloc+memset with kzalloc 

Signed-off-by: Yan Burman <burman.yan@gmail.com>

diff -rubp linux-2.6.19-rc5_orig/arch/sparc/kernel/ioport.c linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/ioport.c
--- linux-2.6.19-rc5_orig/arch/sparc/kernel/ioport.c	2006-11-09 12:16:21.000000000 +0200
+++ linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/ioport.c	2006-11-11 22:44:04.000000000 +0200
@@ -317,9 +317,8 @@ void *sbus_alloc_consistent(struct sbus_
 	if ((va = __get_free_pages(GFP_KERNEL|__GFP_COMP, order)) == 0)
 		goto err_nopages;
 
-	if ((res = kmalloc(sizeof(struct resource), GFP_KERNEL)) == NULL)
+	if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL)
 		goto err_nomem;
-	memset((char*)res, 0, sizeof(struct resource));
 
 	if (allocate_resource(&_sparc_dvma, res, len_total,
 	    _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
@@ -589,12 +588,11 @@ void *pci_alloc_consistent(struct pci_de
 		return NULL;
 	}
 
-	if ((res = kmalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
+	if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
 		free_pages(va, order);
 		printk("pci_alloc_consistent: no core\n");
 		return NULL;
 	}
-	memset((char*)res, 0, sizeof(struct resource));
 
 	if (allocate_resource(&_sparc_dvma, res, len_total,
 	    _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
diff -rubp linux-2.6.19-rc5_orig/arch/sparc/kernel/of_device.c linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/of_device.c
--- linux-2.6.19-rc5_orig/arch/sparc/kernel/of_device.c	2006-11-09 12:16:21.000000000 +0200
+++ linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/of_device.c	2006-11-11 22:44:04.000000000 +0200
@@ -793,10 +793,9 @@ struct of_device* of_platform_device_cre
 {
 	struct of_device *dev;
 
-	dev = kmalloc(sizeof(*dev), GFP_KERNEL);
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
 	if (!dev)
 		return NULL;
-	memset(dev, 0, sizeof(*dev));
 
 	dev->dev.parent = parent;
 	dev->dev.bus = bus;
diff -rubp linux-2.6.19-rc5_orig/arch/sparc/kernel/sun4d_irq.c linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/sun4d_irq.c
--- linux-2.6.19-rc5_orig/arch/sparc/kernel/sun4d_irq.c	2006-11-09 12:16:21.000000000 +0200
+++ linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/sun4d_irq.c	2006-11-11 22:44:04.000000000 +0200
@@ -545,8 +545,7 @@ void __init sun4d_init_sbi_irq(void)
 	nsbi = 0;
 	for_each_sbus(sbus)
 		nsbi++;
-	sbus_actions = (struct sbus_action *)kmalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
-	memset (sbus_actions, 0, (nsbi * 8 * 4 * sizeof(struct sbus_action)));
+	sbus_actions = kzalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
 	for_each_sbus(sbus) {
 #ifdef CONFIG_SMP	
 		extern unsigned char boot_cpu_id;
diff -rubp linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c
--- linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c	2006-11-09 12:16:21.000000000 +0200
+++ linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c	2006-11-11 22:44:04.000000000 +0200
@@ -41,9 +41,8 @@ iounit_init(int sbi_node, int io_node, s
 	struct linux_prom_registers iommu_promregs[PROMREG_MAX];
 	struct resource r;
 
-	iounit = kmalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
+	iounit = kzalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
 
-	memset(iounit, 0, sizeof(*iounit));
 	iounit->limit[0] = IOUNIT_BMAP1_START;
 	iounit->limit[1] = IOUNIT_BMAP2_START;
 	iounit->limit[2] = IOUNIT_BMAPM_START;



Regards
Yan Burman

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

* Re: [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc
  2006-11-24 12:01 [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc Yan Burman
@ 2006-11-24 17:33 ` Stefan Richter
  2006-11-24 19:02   ` Yan Burman
  2006-12-01  1:12 ` David Miller
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Richter @ 2006-11-24 17:33 UTC (permalink / raw)
  To: Yan Burman; +Cc: linux-kernel, trivial, wli, sparclinux

Yan Burman wrote:
...
> --- linux-2.6.19-rc5_orig/arch/sparc/kernel/sun4d_irq.c	2006-11-09 12:16:21.000000000 +0200
> +++ linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/sun4d_irq.c	2006-11-11 22:44:04.000000000 +0200
> @@ -545,8 +545,7 @@ void __init sun4d_init_sbi_irq(void)
>  	nsbi = 0;
>  	for_each_sbus(sbus)
>  		nsbi++;
> -	sbus_actions = (struct sbus_action *)kmalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
> -	memset (sbus_actions, 0, (nsbi * 8 * 4 * sizeof(struct sbus_action)));
> +	sbus_actions = kzalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
>  	for_each_sbus(sbus) {
>  #ifdef CONFIG_SMP	
>  		extern unsigned char boot_cpu_id;

I'm not sure about this ^ hunk, but...

> diff -rubp linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c
> --- linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c	2006-11-09 12:16:21.000000000 +0200
> +++ linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c	2006-11-11 22:44:04.000000000 +0200
> @@ -41,9 +41,8 @@ iounit_init(int sbi_node, int io_node, s
>  	struct linux_prom_registers iommu_promregs[PROMREG_MAX];
>  	struct resource r;
>  
> -	iounit = kmalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
> +	iounit = kzalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
>  
> -	memset(iounit, 0, sizeof(*iounit));
>  	iounit->limit[0] = IOUNIT_BMAP1_START;
>  	iounit->limit[1] = IOUNIT_BMAP2_START;
>  	iounit->limit[2] = IOUNIT_BMAPM_START;

...in this ^, the old code and your update don't check for NULL return.
-- 
Stefan Richter
-=====-=-==- =-== ==---
http://arcgraph.de/sr/

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

* Re: [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc
  2006-11-24 17:33 ` Stefan Richter
@ 2006-11-24 19:02   ` Yan Burman
  2006-11-24 19:13     ` Stefan Richter
  2006-11-24 21:52     ` David Miller
  0 siblings, 2 replies; 6+ messages in thread
From: Yan Burman @ 2006-11-24 19:02 UTC (permalink / raw)
  To: Stefan Richter; +Cc: linux-kernel, trivial, wli, sparclinux

Stefan Richter wrote:
> Yan Burman wrote:
> ...
>   
>> --- linux-2.6.19-rc5_orig/arch/sparc/kernel/sun4d_irq.c	2006-11-09 12:16:21.000000000 +0200
>> +++ linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/sun4d_irq.c	2006-11-11 22:44:04.000000000 +0200
>> @@ -545,8 +545,7 @@ void __init sun4d_init_sbi_irq(void)
>>  	nsbi = 0;
>>  	for_each_sbus(sbus)
>>  		nsbi++;
>> -	sbus_actions = (struct sbus_action *)kmalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
>> -	memset (sbus_actions, 0, (nsbi * 8 * 4 * sizeof(struct sbus_action)));
>> +	sbus_actions = kzalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
>>  	for_each_sbus(sbus) {
>>  #ifdef CONFIG_SMP	
>>  		extern unsigned char boot_cpu_id;
>>     
>
> I'm not sure about this ^ hunk, but...
>
>   
>> diff -rubp linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c
>> --- linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c	2006-11-09 12:16:21.000000000 +0200
>> +++ linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c	2006-11-11 22:44:04.000000000 +0200
>> @@ -41,9 +41,8 @@ iounit_init(int sbi_node, int io_node, s
>>  	struct linux_prom_registers iommu_promregs[PROMREG_MAX];
>>  	struct resource r;
>>  
>> -	iounit = kmalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
>> +	iounit = kzalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
>>  
>> -	memset(iounit, 0, sizeof(*iounit));
>>  	iounit->limit[0] = IOUNIT_BMAP1_START;
>>  	iounit->limit[1] = IOUNIT_BMAP2_START;
>>  	iounit->limit[2] = IOUNIT_BMAPM_START;
>>     
>
> ...in this ^, the old code and your update don't check for NULL return.
>   

Both of this parts are done at early stages, so it is probably:
a) Impossible to recover from failure
b) If you run out of memory at this stage, you are probably in very big 
trouble anyway

I could modify it to check and panic if the check fails.
Would that be better?


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

* Re: [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc
  2006-11-24 19:02   ` Yan Burman
@ 2006-11-24 19:13     ` Stefan Richter
  2006-11-24 21:52     ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Richter @ 2006-11-24 19:13 UTC (permalink / raw)
  To: Yan Burman; +Cc: linux-kernel, trivial, wli, sparclinux

Yan Burman wrote:
> Stefan Richter wrote:
>> ...in this ^, the old code and your update don't check for NULL return.
> 
> Both of this parts are done at early stages, so it is probably:
> a) Impossible to recover from failure
> b) If you run out of memory at this stage, you are probably in very big
> trouble anyway
> 
> I could modify it to check and panic if the check fails.
> Would that be better?

I hope the domain experts answer this. (I have no recommendation but
wanted to point out a potential, although unlikely, cause for trouble.)
-- 
Stefan Richter
-=====-=-==- =-== ==---
http://arcgraph.de/sr/

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

* Re: [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc
  2006-11-24 19:02   ` Yan Burman
  2006-11-24 19:13     ` Stefan Richter
@ 2006-11-24 21:52     ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2006-11-24 21:52 UTC (permalink / raw)
  To: burman.yan; +Cc: stefanr, linux-kernel, trivial, wli, sparclinux

From: Yan Burman <burman.yan@gmail.com>
Date: Fri, 24 Nov 2006 21:02:53 +0200

> Stefan Richter wrote:
> > Yan Burman wrote:
> > ...
> >   
> >> --- linux-2.6.19-rc5_orig/arch/sparc/kernel/sun4d_irq.c	2006-11-09 12:16:21.000000000 +0200
> >> +++ linux-2.6.19-rc5_kzalloc/arch/sparc/kernel/sun4d_irq.c	2006-11-11 22:44:04.000000000 +0200
> >> @@ -545,8 +545,7 @@ void __init sun4d_init_sbi_irq(void)
> >>  	nsbi = 0;
> >>  	for_each_sbus(sbus)
> >>  		nsbi++;
> >> -	sbus_actions = (struct sbus_action *)kmalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
> >> -	memset (sbus_actions, 0, (nsbi * 8 * 4 * sizeof(struct sbus_action)));
> >> +	sbus_actions = kzalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
> >>  	for_each_sbus(sbus) {
> >>  #ifdef CONFIG_SMP	
> >>  		extern unsigned char boot_cpu_id;
> >>     
> >
> > I'm not sure about this ^ hunk, but...
> >
> >   
> >> diff -rubp linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c
> >> --- linux-2.6.19-rc5_orig/arch/sparc/mm/io-unit.c	2006-11-09 12:16:21.000000000 +0200
> >> +++ linux-2.6.19-rc5_kzalloc/arch/sparc/mm/io-unit.c	2006-11-11 22:44:04.000000000 +0200
> >> @@ -41,9 +41,8 @@ iounit_init(int sbi_node, int io_node, s
> >>  	struct linux_prom_registers iommu_promregs[PROMREG_MAX];
> >>  	struct resource r;
> >>  
> >> -	iounit = kmalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
> >> +	iounit = kzalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
> >>  
> >> -	memset(iounit, 0, sizeof(*iounit));
> >>  	iounit->limit[0] = IOUNIT_BMAP1_START;
> >>  	iounit->limit[1] = IOUNIT_BMAP2_START;
> >>  	iounit->limit[2] = IOUNIT_BMAPM_START;
> >>     
> >
> > ...in this ^, the old code and your update don't check for NULL return.
> >   
> 
> Both of this parts are done at early stages, so it is probably:
> a) Impossible to recover from failure
> b) If you run out of memory at this stage, you are probably in very big 
> trouble anyway
> 
> I could modify it to check and panic if the check fails.
> Would that be better?

Don't panic, call prom_printf() with a suitable message and then
prom_halt() just like all other early-boot failures do on sparc.

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

* Re: [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc
  2006-11-24 12:01 [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc Yan Burman
  2006-11-24 17:33 ` Stefan Richter
@ 2006-12-01  1:12 ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2006-12-01  1:12 UTC (permalink / raw)
  To: burman.yan; +Cc: linux-kernel, trivial, wli

From: Yan Burman <burman.yan@gmail.com>
Date: Fri, 24 Nov 2006 14:01:14 +0200

> Replace kmalloc+memset with kzalloc 
> 
> Signed-off-by: Yan Burman <burman.yan@gmail.com>

Applied and I added the necessary return value checks in
sun4d_irq.c and io-unit.c

Thanks.

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

end of thread, other threads:[~2006-12-01  1:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-24 12:01 [PATCH 2.6.19-rc6] sparc: replace kmalloc+memset with kzalloc Yan Burman
2006-11-24 17:33 ` Stefan Richter
2006-11-24 19:02   ` Yan Burman
2006-11-24 19:13     ` Stefan Richter
2006-11-24 21:52     ` David Miller
2006-12-01  1:12 ` David Miller

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