misc: Call calloc() not malloc() to ensure buffer is zeroed
Subsystems (3)
PATCH 1/1 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 <[email protected]>
--- drivers/net/mpc512x_fec.c | 8 +++----- lib/bzip2/bzlib.c | 4 ++-- lib/string.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-)
drivers/net/mpc512x_fec.c +3 -5
@@ -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
lib/bzip2/bzlib.c +2 -2
@@ -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 ; };
lib/string.c +1 -1
@@ -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 ; }
Signature · 1 line
1.7.9.5