[U-Boot] [PATCH] misc: Call calloc() not malloc() to ensure buffer is zeroed

- mpc512x_fec.c: 'fec' was not being memset while dev was, just call calloc() instead for both. 'bd' was being memset afterwards but given that it's an awkward looking call, just calloc() it directly. - bzlib.c: Some fields to 'bzf' are being set to NULL later but for clarity calloc() the structure. - string.c: We rely on malloc() having zeroed the buffer here so use calloc() instead.
Signed-off-by: Tom Rini trini@ti.com --- drivers/net/mpc512x_fec.c | 8 +++----- lib/bzip2/bzlib.c | 4 ++-- lib/string.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/net/mpc512x_fec.c b/drivers/net/mpc512x_fec.c index 427e0b8..bee67d33 100644 --- a/drivers/net/mpc512x_fec.c +++ b/drivers/net/mpc512x_fec.c @@ -616,9 +616,8 @@ int mpc512x_fec_initialize (bd_t * bis) struct eth_device *dev; void * bd;
- fec = (mpc512x_fec_priv *) malloc (sizeof(*fec)); - dev = (struct eth_device *) malloc (sizeof(*dev)); - memset (dev, 0, sizeof *dev); + fec = (mpc512x_fec_priv *) cmalloc (sizeof(*fec)); + dev = (struct eth_device *) cmalloc (sizeof(*dev));
fec->eth = &im->fec;
@@ -650,9 +649,8 @@ int mpc512x_fec_initialize (bd_t * bis) * Malloc space for BDs (must be quad word-aligned) * this pointer is lost, so cannot be freed */ - bd = malloc (sizeof(mpc512x_buff_descs) + 0x1f); + bd = cmalloc (sizeof(mpc512x_buff_descs) + 0x1f); fec->bdBase = (mpc512x_buff_descs*)((u32)bd & 0xfffffff0); - memset ((void *) bd, 0x00, sizeof(mpc512x_buff_descs) + 0x1f);
/* * Set interrupt mask register diff --git a/lib/bzip2/bzlib.c b/lib/bzip2/bzlib.c index 9262e40..1305808 100644 --- a/lib/bzip2/bzlib.c +++ b/lib/bzip2/bzlib.c @@ -963,7 +963,7 @@ BZFILE* BZ_API(BZ2_bzWriteOpen) if (ferror(f)) { BZ_SETERR(BZ_IO_ERROR); return NULL; };
- bzf = malloc ( sizeof(bzFile) ); + bzf = cmalloc ( sizeof(bzFile) ); if (bzf == NULL) { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
@@ -1135,7 +1135,7 @@ BZFILE* BZ_API(BZ2_bzReadOpen) if (ferror(f)) { BZ_SETERR(BZ_IO_ERROR); return NULL; };
- bzf = malloc ( sizeof(bzFile) ); + bzf = cmalloc ( sizeof(bzFile) ); if (bzf == NULL) { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
diff --git a/lib/string.c b/lib/string.c index 87c9a40..f496dbe 100644 --- a/lib/string.c +++ b/lib/string.c @@ -284,7 +284,7 @@ char * strdup(const char *s) char *new;
if ((s == NULL) || - ((new = malloc (strlen(s) + 1)) == NULL) ) { + ((new = cmalloc (strlen(s) + 1)) == NULL) ) { return NULL; }
participants (1)
-
Tom Rini