From bdcf700f71500378ba1b26e6e9aab84421bdf931 Mon Sep 17 00:00:00 2001 From: Sotirios-Efstathios Maneas Date: Thu, 11 Oct 2018 18:20:53 -0400 Subject: [PATCH] mkfs.f2fs: Added missing statements related to error checking. The following patch adds a few missing statements related to error checking. Signed-off-by: Sotirios-Efstathios Maneas Signed-off-by: Jaegeuk Kim --- mkfs/f2fs_format.c | 10 ++++++++-- mkfs/f2fs_format_utils.c | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 9b0a0d1..a2685cb 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -991,12 +991,16 @@ static int f2fs_write_super_block(void) u_int8_t *zero_buff; zero_buff = calloc(F2FS_BLKSIZE, 1); + if (zero_buff == NULL) { + MSG(1, "\tError: Calloc Failed for super_blk_zero_buf!!!\n"); + return -1; + } memcpy(zero_buff + F2FS_SUPER_OFFSET, sb, sizeof(*sb)); DBG(1, "\tWriting super block, at offset 0x%08x\n", 0); for (index = 0; index < 2; index++) { if (dev_write_block(zero_buff, index)) { - MSG(1, "\tError: While while writing supe_blk " + MSG(1, "\tError: While while writing super_blk " "on disk!!! index : %d\n", index); free(zero_buff); return -1; @@ -1021,8 +1025,10 @@ static int f2fs_discard_obsolete_dnode(void) return 0; raw_node = calloc(sizeof(struct f2fs_node), 1); - if (!raw_node) + if (raw_node == NULL) { + MSG(1, "\tError: Calloc Failed for discard_raw_node!!!\n"); return -1; + } /* avoid power-off-recovery based on roll-forward policy */ offset = get_sb(main_blkaddr); diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c index 2c901f2..8bf128c 100644 --- a/mkfs/f2fs_format_utils.c +++ b/mkfs/f2fs_format_utils.c @@ -55,6 +55,11 @@ static int trim_device(int i) int fd = dev->fd; stat_buf = malloc(sizeof(struct stat)); + if (stat_buf == NULL) { + MSG(1, "\tError: Malloc Failed for trim_stat_buf!!!\n"); + return -1; + } + if (fstat(fd, stat_buf) < 0 ) { MSG(1, "\tError: Failed to get the device stat!!!\n"); free(stat_buf); -- 2.7.4