diff mbox

[U-Boot,v4,1/5] sf: ops: Squash the malloc+memset combo

Message ID 9b9d8079-0eac-47e7-a1ba-3573656aa5f0@AM1EHSMHS016.ehs.local
State Accepted
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Commit Message

Jagannadha Sutradharudu Teki Feb. 4, 2014, 4:06 p.m. UTC
Squash the malloc()+memset() combo in favor of calloc().

Signed-off-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
---
 drivers/mtd/spi/sf_ops.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Marek Vasut Feb. 4, 2014, 8:12 p.m. UTC | #1
On Tuesday, February 04, 2014 at 05:06:13 PM, Jagannadha Sutradharudu Teki 
wrote:
> Squash the malloc()+memset() combo in favor of calloc().
> 
> Signed-off-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>

Acked-by: Marek Vasut <marex@denx.de>

btw your CC list seems bugged for some reason ...

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
index 1f1bb36..ef91b92 100644
--- a/drivers/mtd/spi/sf_ops.c
+++ b/drivers/mtd/spi/sf_ops.c
@@ -9,6 +9,7 @@ 
  */
 
 #include <common.h>
+#include <errno.h>
 #include <malloc.h>
 #include <spi.h>
 #include <spi_flash.h>
@@ -381,8 +382,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) {
+		debug("SF: Failed to allocate cmd\n");
+		return -ENOMEM;
+	}
 
 	cmd[0] = flash->read_cmd;
 	while (len) {