Skip to contentSkip to conversation

kzalloc() conversion in lib/

PATCH In review Eric Sesterhenn 3 participants 6 messages Mar 5, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kzalloc() conversion in lib/

hi,

this patch converts lib/ to kzalloc usage.
Compile tested with allyesconfig.

lib/genalloc.c renamed from lib/genalloc.c.orig +4 -7
@@ -47,20 +47,17 @@ struct gen_pool *gen_pool_create(int nr_
 	if (!max_chunk_shift)
 		max_chunk_shift = PAGE_SHIFT;
 
-	poolp = kmalloc(sizeof(struct gen_pool), GFP_KERNEL);
+	poolp = kzalloc(sizeof(struct gen_pool), GFP_KERNEL);
 	if (!poolp)
 		return NULL;
-	memset(poolp, 0, sizeof(struct gen_pool));
-	poolp->h = kmalloc(sizeof(struct gen_pool_link) *
-			   (max_chunk_shift - ALLOC_MIN_SHIFT + 1),
-			   GFP_KERNEL);
+	poolp->h = kcalloc((max_chunk_shift - ALLOC_MIN_SHIFT + ),
+				sizeof(struct gen_pool_link), 
+				GFP_KERNEL);
 	if (!poolp->h) {
 		printk(KERN_WARNING "gen_pool_alloc() failed to allocate\n");
 		kfree(poolp);
 		return NULL;
 	}
-	memset(poolp->h, 0, sizeof(struct gen_pool_link) *
-	       (max_chunk_shift - ALLOC_MIN_SHIFT + 1));
 
 	spin_lock_init(&poolp->lock);
 	poolp->get_new_chunk = fp;
lib/kobject.c renamed from lib/kobject.c.orig +1 -2
@@ -111,10 +111,9 @@ char *kobject_get_path(struct kobject *k
 	len = get_kobj_path_length(kobj);
 	if (len == 0)
 		return NULL;
-	path = kmalloc(len, gfp_mask);
+	path = kzalloc(len, gfp_mask);
 	if (!path)
 		return NULL;
-	memset(path, 0x00, len);
 	fill_kobj_path(kobj, path, len);
 
 	return path;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw
Quoted 8 lines · Eric Sesterhenn

this patch converts lib/ to kzalloc usage.
Compile tested with allyesconfig.

lib/genalloc.c renamed from lib/genalloc.c.orig +0 -0
@@ -47,20 +47,17 @@ struct gen_pool *gen_pool_create(int nr_
 	if (!max_chunk_shift)
 		max_chunk_shift = PAGE_SHIFT;

lib/genalloc.c struct gen_pool *gen_pool_create(int nr_ · line 53

Quoted 10 lines
lib/genalloc.c renamed from lib/genalloc.c.orig +2 -5
 
-	poolp = kmalloc(sizeof(struct gen_pool), GFP_KERNEL);
+	poolp = kzalloc(sizeof(struct gen_pool), GFP_KERNEL);
 	if (!poolp)
 		return NULL;
-	memset(poolp, 0, sizeof(struct gen_pool));
-	poolp->h = kmalloc(sizeof(struct gen_pool_link) *
-			   (max_chunk_shift - ALLOC_MIN_SHIFT + 1),
-			   GFP_KERNEL);
+	poolp->h = kcalloc((max_chunk_shift - ALLOC_MIN_SHIFT + ),

This will screw ia64.

lib/genalloc.c struct gen_pool *gen_pool_create(int nr_ · line 63

Quoted 9 lines
lib/genalloc.c renamed from lib/genalloc.c.orig +2 -2
+				sizeof(struct gen_pool_link),
+				GFP_KERNEL);
 	if (!poolp->h) {
 		printk(KERN_WARNING "gen_pool_alloc() failed to allocate\n");
 		kfree(poolp);
 		return NULL;
 	}
-	memset(poolp->h, 0, sizeof(struct gen_pool_link) *
-	       (max_chunk_shift - ALLOC_MIN_SHIFT + 1));

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw
In reply to Eric Sesterhenn
Quoted 5 lines · Alexey Dobriyan
Quoted 2 lines · Eric Sesterhenn

this patch converts lib/ to kzalloc usage.
Compile tested with allyesconfig.

Quoted 11 lines

lib/genalloc.c struct gen_pool *gen_pool_create(int nr_ · line 53

Quoted 7 lines
	if (!poolp)
		return NULL;
lib/genalloc.c renamed from lib/genalloc.c.orig +1 -4
-	memset(poolp, 0, sizeof(struct gen_pool));
-	poolp->h = kmalloc(sizeof(struct gen_pool_link) *
-			   (max_chunk_shift - ALLOC_MIN_SHIFT + 1),
-			   GFP_KERNEL);
+	poolp->h = kcalloc((max_chunk_shift - ALLOC_MIN_SHIFT + ),

This will screw ia64.

I don't see how it would even compile in the first place. But would you mind explaining how this would screw ia64?

Quoted 8 lines
Quoted 8 lines
lib/genalloc.c renamed from lib/genalloc.c.orig +2 -0
+				sizeof(struct gen_pool_link),
+				GFP_KERNEL);
	if (!poolp->h) {
		printk(KERN_WARNING "gen_pool_alloc() failed to allocate\n");
		kfree(poolp);
		return NULL;
	}
Signature · 3 lines
There are only 10 kinds of people in this world,
  those that understand binary and those that don't.
http://www.kroon.co.za/

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#3 lore raw
In reply to Eric Sesterhenn

hi,

Quoted 5 lines
Quoted 2 lines

This will screw ia64.

I don't see how it would even compile in the first place. But would you mind explaining how this would screw ia64?

thats why it would screw ia64. It seems to not get compiled on i386, thats why my "make lib/" didnt catch it

Eric

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#4 lore raw
In reply to Eric Sesterhenn

hi,

Quoted 6 lines
Quoted 6 lines
lib/genalloc.c renamed from lib/genalloc.c.orig +0 -0
@@ -47,20 +47,17 @@ struct gen_pool *gen_pool_create(int nr_
 	if (!max_chunk_shift)
 		max_chunk_shift = PAGE_SHIFT;
 
Quoted 11 lines

lib/genalloc.c struct gen_pool *gen_pool_create(int nr_ · line 53

Quoted 9 lines
lib/genalloc.c renamed from lib/genalloc.c.orig +2 -5
-	poolp = kmalloc(sizeof(struct gen_pool), GFP_KERNEL);
+	poolp = kzalloc(sizeof(struct gen_pool), GFP_KERNEL);
 	if (!poolp)
 		return NULL;
-	memset(poolp, 0, sizeof(struct gen_pool));
-	poolp->h = kmalloc(sizeof(struct gen_pool_link) *
-			   (max_chunk_shift - ALLOC_MIN_SHIFT + 1),
-			   GFP_KERNEL);
+	poolp->h = kcalloc((max_chunk_shift - ALLOC_MIN_SHIFT + ),

This will screw ia64.

attached patch below. Is there something like a cross compiler live cd, so one can put time where concentration is missing to catch such stuff?

lib/genalloc.c renamed from lib/genalloc.c.orig +4 -7
@@ -47,20 +47,17 @@ struct gen_pool *gen_pool_create(int nr_
 	if (!max_chunk_shift)
 		max_chunk_shift = PAGE_SHIFT;
 
-	poolp = kmalloc(sizeof(struct gen_pool), GFP_KERNEL);
+	poolp = kzalloc(sizeof(struct gen_pool), GFP_KERNEL);
 	if (!poolp)
 		return NULL;
-	memset(poolp, 0, sizeof(struct gen_pool));
-	poolp->h = kmalloc(sizeof(struct gen_pool_link) *
-			   (max_chunk_shift - ALLOC_MIN_SHIFT + 1),
-			   GFP_KERNEL);
+	poolp->h = kcalloc((max_chunk_shift - ALLOC_MIN_SHIFT + 1),
+				sizeof(struct gen_pool_link), 
+				GFP_KERNEL);
 	if (!poolp->h) {
 		printk(KERN_WARNING "gen_pool_alloc() failed to allocate\n");
 		kfree(poolp);
 		return NULL;
 	}
-	memset(poolp->h, 0, sizeof(struct gen_pool_link) *
-	       (max_chunk_shift - ALLOC_MIN_SHIFT + 1));
 
 	spin_lock_init(&poolp->lock);
 	poolp->get_new_chunk = fp;
lib/kobject.c renamed from lib/kobject.c.orig +1 -2
@@ -111,10 +111,9 @@ char *kobject_get_path(struct kobject *k
 	len = get_kobj_path_length(kobj);
 	if (len == 0)
 		return NULL;
-	path = kmalloc(len, gfp_mask);
+	path = kzalloc(len, gfp_mask);
 	if (!path)
 		return NULL;
-	memset(path, 0x00, len);
 	fill_kobj_path(kobj, path, len);
 
 	return path;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#5 lore raw
In reply to Eric Sesterhenn
Quoted 21 lines · Eric Sesterhenn

hi,

Quoted 6 lines
Quoted 6 lines
lib/genalloc.c renamed from lib/genalloc.c.orig +0 -0
@@ -47,20 +47,17 @@ struct gen_pool *gen_pool_create(int nr_
 	if (!max_chunk_shift)
 		max_chunk_shift = PAGE_SHIFT;
 
Quoted 11 lines

lib/genalloc.c struct gen_pool *gen_pool_create(int nr_ · line 53

Quoted 9 lines
lib/genalloc.c renamed from lib/genalloc.c.orig +2 -5
-	poolp = kmalloc(sizeof(struct gen_pool), GFP_KERNEL);
+	poolp = kzalloc(sizeof(struct gen_pool), GFP_KERNEL);
 	if (!poolp)
 		return NULL;
-	memset(poolp, 0, sizeof(struct gen_pool));
-	poolp->h = kmalloc(sizeof(struct gen_pool_link) *
-			   (max_chunk_shift - ALLOC_MIN_SHIFT + 1),
-			   GFP_KERNEL);
+	poolp->h = kcalloc((max_chunk_shift - ALLOC_MIN_SHIFT + ),

This will screw ia64.

Quoted 2 lines

attached patch below. Is there something like a cross compiler live cd, so one can put time where concentration is missing to catch such stuff?

Why would you need a cross-compiler live cd? I've used the Gentoo crossdev package on Friday to build cross-compilers on my system for other architectures which would allow you to pass two flags to the kernel build process, for example:

$ make ARCH=ia64 CROSS_COMPILE=x86_64-pc-linux-gnu- allyesconfig
$ make ARCH=ia64 CROSS_COMPILE=x86_64-pc-linux-gnu-

to build for ia64, or to build for armeb:

$ make ARCH=arm CROSS_COMPILE=armeb-unknown-linux-gnu- ixdp2801_defconfig
$ make ARCH=arm CROSS_COMPILE=armeb-unknown-linux-gnu-

And so forth. This of course assumes that the required compilers exist.

Jaco

Signature · 3 lines
There are only 10 kinds of people in this world,
  those that understand binary and those that don't.
http://www.kroon.co.za/

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors