2006-09-18 00:54:09

by Om Narasimhan

[permalink] [raw]
Subject: kmalloc to kzalloc patches for drivers/base

Tested by compiling.

Signed off by Om Narasimhan <[email protected]>


drivers/base/class.c | 2 +-
drivers/base/dmapool.c | 4 ++--
drivers/base/firmware_class.c | 2 +-
drivers/base/map.c | 4 ++--
drivers/base/platform.c | 4 ++--
5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index de89083..4858d3a 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -511,7 +511,7 @@ char *make_class_name(const char *name,

size = strlen(name) + strlen(kobject_name(kobj)) + 2;

- class_name = kmalloc(size, GFP_KERNEL);
+ class_name = kzalloc(size, GFP_KERNEL);
if (!class_name)
return ERR_PTR(-ENOMEM);

diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c
index 33c5cce..a9558c3 100644
--- a/drivers/base/dmapool.c
+++ b/drivers/base/dmapool.c
@@ -126,7 +126,7 @@ dma_pool_create (const char *name, struc
} else if (allocation < size)
return NULL;

- if (!(retval = kmalloc (sizeof *retval, SLAB_KERNEL)))
+ if (!(retval = kzalloc (sizeof *retval, SLAB_KERNEL)))
return retval;

strlcpy (retval->name, name, sizeof retval->name);
@@ -164,7 +164,7 @@ pool_alloc_page (struct dma_pool *pool,
mapsize = (mapsize + BITS_PER_LONG - 1) / BITS_PER_LONG;
mapsize *= sizeof (long);

- page = (struct dma_page *) kmalloc (mapsize + sizeof *page, mem_flags);
+ page = (struct dma_page *) kzalloc (mapsize + sizeof *page, mem_flags);
if (!page)
return NULL;
page->vaddr = dma_alloc_coherent (pool->dev,
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 5d6c011..3b6348d 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -546,7 +546,7 @@ request_firmware_nowait(
const char *name, struct device *device, void *context,
void (*cont)(const struct firmware *fw, void *context))
{
- struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work),
+ struct firmware_work *fw_work = kzalloc(sizeof (struct firmware_work),
GFP_ATOMIC);
int ret;

diff --git a/drivers/base/map.c b/drivers/base/map.c
index e87017f..4e389b2 100644
--- a/drivers/base/map.c
+++ b/drivers/base/map.c
@@ -41,7 +41,7 @@ int kobj_map(struct kobj_map *domain, de
if (n > 255)
n = 255;

- p = kmalloc(sizeof(struct probe) * n, GFP_KERNEL);
+ p = kzalloc(sizeof(struct probe) * n, GFP_KERNEL);

if (p == NULL)
return -ENOMEM;
@@ -135,7 +135,7 @@ retry:

struct kobj_map *kobj_map_init(kobj_probe_t *base_probe, struct mutex *lock)
{
- struct kobj_map *p = kmalloc(sizeof(struct kobj_map), GFP_KERNEL);
+ struct kobj_map *p = kzalloc(sizeof(struct kobj_map), GFP_KERNEL);
struct probe *base = kzalloc(sizeof(*base), GFP_KERNEL);
int i;

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 2b8755d..e08950b 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -192,7 +192,7 @@ int platform_device_add_resources(struct
{
struct resource *r;

- r = kmalloc(sizeof(struct resource) * num, GFP_KERNEL);
+ r = kzalloc(sizeof(struct resource) * num, GFP_KERNEL);
if (r) {
memcpy(r, res, sizeof(struct resource) * num);
pdev->resource = r;
@@ -216,7 +216,7 @@ int platform_device_add_data(struct plat
{
void *d;

- d = kmalloc(size, GFP_KERNEL);
+ d = kzalloc(size, GFP_KERNEL);
if (d) {
memcpy(d, data, size);
pdev->dev.platform_data = d;


2006-09-18 01:08:41

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: kmalloc to kzalloc patches for drivers/base

On Sunday 17 September 2006 20:53, Om Narasimhan wrote:
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 2b8755d..e08950b 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -192,7 +192,7 @@ int platform_device_add_resources(struct
> ?{
> ????????struct resource *r;
>
> -???????r = kmalloc(sizeof(struct resource) * num, GFP_KERNEL);
> +???????r = kzalloc(sizeof(struct resource) * num, GFP_KERNEL);
> ????????if (r) {
> ????????????????memcpy(r, res, sizeof(struct resource) * num);
> ????????????????pdev->resource = r;

Just out of curiosity could you tell me what is the benefit of
zeroing allocated memory here?

> @@ -216,7 +216,7 @@ int platform_device_add_data(struct plat
> ?{
> ????????void *d;
>
> -???????d = kmalloc(size, GFP_KERNEL);
> +???????d = kzalloc(size, GFP_KERNEL);
> ????????if (d) {
> ????????????????memcpy(d, data, size);
> ????????????????pdev->dev.platform_data = d;
>

And here?

--
Dmitry

2006-09-18 02:27:07

by Om Narasimhan

[permalink] [raw]
Subject: Re: kmalloc to kzalloc patches for drivers/base

On 9/17/06, Dmitry Torokhov <[email protected]> wrote:
> On Sunday 17 September 2006 20:53, Om Narasimhan wrote:
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index 2b8755d..e08950b 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -192,7 +192,7 @@ int platform_device_add_resources(struct
> > {
> > struct resource *r;
> >
> > -r = kmalloc(sizeof(struct resource) * num, GFP_KERNEL);
> > +r = kzalloc(sizeof(struct resource) * num, GFP_KERNEL);
> > if (r) {
> > memcpy(r, res, sizeof(struct resource) * num);
> > pdev->resource = r;
>
> Just out of curiosity could you tell me what is the benefit of
> zeroing allocated memory here?
My mistake. :-D
>
> > @@ -216,7 +216,7 @@ int platform_device_add_data(struct plat
> > {
> > void *d;
> >
> > -d = kmalloc(size, GFP_KERNEL);
> > +d = kzalloc(size, GFP_KERNEL);
> > if (d) {
> > memcpy(d, data, size);
> > pdev->dev.platform_data = d;
> >
>
> And here?
Mea Culpa :-D

Thanks for the comment.
Regards,
Om.

2006-09-18 09:17:07

by Alan

[permalink] [raw]
Subject: Re: kmalloc to kzalloc patches for drivers/base

Ar Sul, 2006-09-17 am 17:53 -0700, ysgrifennodd Om Narasimhan:
> Tested by compiling.
>
> Signed off by Om Narasimhan <[email protected]>

> - if (!(retval = kmalloc (sizeof *retval, SLAB_KERNEL)))
> + if (!(retval = kzalloc (sizeof *retval, SLAB_KERNEL)))
> return retval;


NAK

Why slow all these allocations down when they don't zero the memory
anyway ?

2006-09-18 12:46:05

by Greg KH

[permalink] [raw]
Subject: Re: [KJ] kmalloc to kzalloc patches for drivers/base

On Sun, Sep 17, 2006 at 05:53:58PM -0700, Om Narasimhan wrote:
> Tested by compiling.
>
> Signed off by Om Narasimhan <[email protected]>
>
>
> drivers/base/class.c | 2 +-
> drivers/base/dmapool.c | 4 ++--
> drivers/base/firmware_class.c | 2 +-
> drivers/base/map.c | 4 ++--
> drivers/base/platform.c | 4 ++--
> 5 files changed, 8 insertions(+), 8 deletions(-)

No, sorry, none of these changes are needed.

thanks,

greg k-h