From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Sat, 18 Jan 2014 21:34:29 +0100 Subject: [U-Boot] [PATCH 1/6] sf: ops: Squash the malloc+memset combo In-Reply-To: <99de5cd3-4b07-4254-a682-60957bd81a3b@VA3EHSMHS040.ehs.local> References: <1390075593-11226-1-git-send-email-jaganna@xilinx.com> <99de5cd3-4b07-4254-a682-60957bd81a3b@VA3EHSMHS040.ehs.local> Message-ID: <201401182134.29505.marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Saturday, January 18, 2014 at 09:06:28 PM, Jagannadha Sutradharudu Teki wrote: > Squash the malloc()+memset() combo in favor of calloc(). > > Signed-off-by: Jagannadha Sutradharudu Teki > Cc: Marek Vasut > --- > drivers/mtd/spi/sf_ops.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c > index 1f1bb36..1fac63a 100644 > --- a/drivers/mtd/spi/sf_ops.c > +++ b/drivers/mtd/spi/sf_ops.c > @@ -381,8 +381,11 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, > u32 offset, } > > cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte; > - cmd = malloc(cmdsz); > - memset(cmd, 0, cmdsz); > + cmd = calloc(1, cmdsz); > + if (!cmd) { > + printf("SF: Failed to allocate cmd\n"); Usually if your memory allocation fails on 4 bytes of data, the printf() here will not happen either :) Just use debug(). btw. if you use printf() without args, rather use puts() > + return ret; > + } > > cmd[0] = flash->read_cmd; > while (len) { Best regards, Marek Vasut