Skip to contentSkip to conversation

kmalloc + memzero -> kzalloc conversion

PATCH In review Deepak Saxena 5 participants 6 messages Oct 1, 2005 – Oct 3, 2005 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kmalloc + memzero -> kzalloc conversion

We have the API, so use it.

drivers/mtd/maps/bast-flash.c +1 -2
@@ -123,14 +123,13 @@ static int bast_flash_probe(struct devic
 	struct resource *res;
 	int err = 0;
 
-	info = kmalloc(sizeof(*info), GFP_KERNEL);
+	info = kzalloc(sizeof(*info), GFP_KERNEL);
 	if (info == NULL) {
 		printk(KERN_ERR PFX "no memory for flash info\n");
 		err = -ENOMEM;
 		goto exit_error;
 	}
 
-	memzero(info, sizeof(*info));
 	dev_set_drvdata(dev, info);
 
 	res = pdev->resource;  /* assume that the flash has one resource */
drivers/mtd/maps/epxa10db-flash.c +1 -2
@@ -142,8 +142,7 @@ static int __init epxa_default_partition
 
 	printk("Using default partitions for %s\n",BOARD_NAME);
 	npartitions=1;
-	parts = kmalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL);
-	memzero(parts,npartitions*sizeof(*parts)+strlen(name));
+	parts = kzalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL);
 	if (!parts) {
 		ret = -ENOMEM;
 		goto out;
drivers/mtd/maps/ixp2000.c +1 -2
@@ -168,12 +168,11 @@ static int ixp2000_flash_probe(struct de
 		return -EIO;
 	}
 
-	info = kmalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
+	info = kzalloc(sizeof(struct ixp2000_flash_info), GFP_KERNEL);
 	if(!info) {
 		err = -ENOMEM;
 		goto Error;
 	}	
-	memzero(info, sizeof(struct ixp2000_flash_info));
 
 	dev_set_drvdata(&dev->dev, info);
 
drivers/mtd/maps/ixp4xx.c +1 -2
@@ -153,12 +153,11 @@ static int ixp4xx_flash_probe(struct dev
 			return err;
 	}
 
-	info = kmalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
+	info = kzalloc(sizeof(struct ixp4xx_flash_info), GFP_KERNEL);
 	if(!info) {
 		err = -ENOMEM;
 		goto Error;
 	}	
-	memzero(info, sizeof(struct ixp4xx_flash_info));
 
 	dev_set_drvdata(&dev->dev, info);
 
Signature · 3 lines
Deepak Saxena - [email protected] - http://www.plexity.net

Even a stopped clock gives the right time twice a day.
#1 lore raw
Quoted 4 lines · Deepak Saxena

We have the API, so use it.

Well, does it really hurt if one does kmalloc() + memset(zero) instead? Is it worth fixing this? Doubts.

Signature · 3 lines
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
#2 lore raw

On Oct 01 2005, at 11:46, Artem B. Bityutskiy was caught saying:

Quoted 6 lines · Deepak Saxena
Quoted 4 lines

We have the API, so use it.

Well, does it really hurt if one does kmalloc() + memset(zero) instead? Is it worth fixing this? Doubts.

I see it more as an API usage cleanup then a "fix" of any sort.

~Deepak

Signature · 3 lines
Deepak Saxena - [email protected] - http://www.plexity.net

Even a stopped clock gives the right time twice a day.
#3 lore raw
Quoted 2 lines · Deepak Saxena

I see it more as an API usage cleanup then a "fix" of any sort.

Well, actually it may be helpful in only future, for example, if it is known that the allocated memory is zero-filled already, memzero() may be avoided at all.

Signature · 3 lines
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
#4 lore raw
Quoted 6 lines · Artem B. Bityutskiy
Quoted 2 lines · Deepak Saxena

I see it more as an API usage cleanup then a "fix" of any sort.

Well, actually it may be helpful in only future, for example, if it is known that the allocated memory is zero-filled already, memzero() may be avoided at all.

Even today, kzalloc() takes less code than kmalloc() + memset(). Shrinks your binary size by a tiny amount.

Jörn

Signature · 3 lines
Mundie uses a textbook tactic of manipulation: start with some
reasonable talk, and lead the audience to an unreasonable conclusion.
-- Bruce Perens
#5 lore raw
In reply to Deepak Saxena
Quoted 1 line · Deepak Saxena

We have the API, so use it.

Ummm. There is a patch in Andrew's tree that allows the use of __GFP_ZERO with slabs in the same way as the page allocator. With that functionality kmalloc_node will also be able to zero stuff.