2005-10-01 05:00:05

by Deepak Saxena

[permalink] [raw]
Subject: [PATCH] [MTD] kmalloc + memzero -> kzalloc conversion


We have the API, so use it.

Signed-off-by: Deepak Saxena <[email protected]>

diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -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 */
diff --git a/drivers/mtd/maps/epxa10db-flash.c b/drivers/mtd/maps/epxa10db-flash.c
--- a/drivers/mtd/maps/epxa10db-flash.c
+++ b/drivers/mtd/maps/epxa10db-flash.c
@@ -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;
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -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);

diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -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);



--
Deepak Saxena - [email protected] - http://www.plexity.net

Even a stopped clock gives the right time twice a day.


2005-10-01 07:46:40

by Artem Bityutskiy

[permalink] [raw]
Subject: Re: [PATCH] [MTD] kmalloc + memzero -> kzalloc conversion

On Fri, 2005-09-30 at 22:00 -0700, Deepak Saxena wrote:
> We have the API, so use it.
>
> Signed-off-by: Deepak Saxena <[email protected]>
>
Well, does it really hurt if one does kmalloc() + memset(zero) instead? Is it worth fixing this? Doubts.

--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.

2005-10-01 08:00:29

by Deepak Saxena

[permalink] [raw]
Subject: Re: [PATCH] [MTD] kmalloc + memzero -> kzalloc conversion

On Oct 01 2005, at 11:46, Artem B. Bityutskiy was caught saying:
> On Fri, 2005-09-30 at 22:00 -0700, Deepak Saxena wrote:
> > We have the API, so use it.
> >
> > Signed-off-by: Deepak Saxena <[email protected]>
> >
> 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

--
Deepak Saxena - [email protected] - http://www.plexity.net

Even a stopped clock gives the right time twice a day.

2005-10-01 08:05:04

by Artem Bityutskiy

[permalink] [raw]
Subject: Re: [PATCH] [MTD] kmalloc + memzero -> kzalloc conversion

Deepak Saxena wrote:
> 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.

--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.

2005-10-02 12:08:10

by Jörn Engel

[permalink] [raw]
Subject: Re: [PATCH] [MTD] kmalloc + memzero -> kzalloc conversion

On Sat, 1 October 2005 12:04:59 +0400, Artem B. Bityutskiy wrote:
> Deepak Saxena wrote:
> >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

--
Mundie uses a textbook tactic of manipulation: start with some
reasonable talk, and lead the audience to an unreasonable conclusion.
-- Bruce Perens

2005-10-03 15:58:00

by Christoph Lameter

[permalink] [raw]
Subject: Re: [PATCH] [MTD] kmalloc + memzero -> kzalloc conversion

On Fri, 30 Sep 2005, Deepak Saxena wrote:

> 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.