Re: [PATCH] drivers: Conversions from kmalloc+memset to k(z|c)alloc.

From: Daniel K.
Date: Tue Jul 18 2006 - 22:42:59 EST


Panagiotis Issaris wrote:
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 3fa80aa..7c84863 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -802,12 +802,7 @@ static int rio_init_drivers(void)
static void *ckmalloc(int size)
{
- void *p;
-
- p = kmalloc(size, GFP_KERNEL);
- if (p)
- memset(p, 0, size);
- return p;
+ return kzalloc(size, GFP_KERNEL);
}
diff --git a/drivers/char/rio/riocmd.c b/drivers/char/rio/riocmd.c
index 4df6ab2..593940f 100644
--- a/drivers/char/rio/riocmd.c
+++ b/drivers/char/rio/riocmd.c
@@ -556,9 +556,7 @@ struct CmdBlk *RIOGetCmdBlk(void)
{
struct CmdBlk *CmdBlkP;
- CmdBlkP = (struct CmdBlk *)kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
- if (CmdBlkP)
- memset(CmdBlkP, 0, sizeof(struct CmdBlk));
+ CmdBlkP = kzalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
return CmdBlkP;
}

Why not return kzalloc(...) here? Alternatively, return (type *) kzalloc(...),
if you believe in explicit type casting of void pointers.

diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index 5ff269f..ca0e9f2 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -925,11 +925,7 @@ static int zilog_irq = -1;
static void * __init alloc_one_table(unsigned long size)
{
void *ret;
-
- ret = kmalloc(size, GFP_KERNEL);
- if (ret != NULL)
- memset(ret, 0, size);
-
+ ret = kzalloc(size, GFP_KERNEL);
return ret;
}

And here as well.

What is preferred by developers?


Daniel K.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/