All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] fsck.f2fs: fix to avoid using uninitialized buffer
@ 2025-06-03  7:26 Chao Yu via Linux-f2fs-devel
  2025-06-03 16:52 ` Daeho Jeong
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-06-03  7:26 UTC (permalink / raw)
  To: jaegeuk; +Cc: Daeho Jeong, linux-f2fs-devel

fsck.c: In function ‘chk_and_fix_wp_with_sit’:
fsck.c:3529:17: error: variable-sized object may not be initialized
 3529 |                 char buffer[F2FS_BLKSIZE] = {};
      |                 ^~~~

The reason is F2FS_BLKSIZE macro is defined w/ c.blksize, let's use
calloc() to allocate zeroed memory to fix this issue.

Cc: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Chao Yu <chao@kernel.org>
---
 fsck/fsck.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 4d05e1b..bb39f8b 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -3526,7 +3526,7 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque)
 
 	ret = f2fs_finish_zone(wpd->dev_index, blkz);
 	if (ret) {
-		u8 buffer[F2FS_BLKSIZE] = {};
+		u8 *buffer;
 		u64 blk_addr = wp_block;
 		u64 fill_sects = blk_zone_length(blkz) -
 			(blk_zone_wp_sector(blkz) - blk_zone_sector(blkz));
@@ -3534,6 +3534,9 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque)
 		struct seg_entry *se = get_seg_entry(sbi, wp_segno);
 		enum rw_hint whint = f2fs_io_type_to_rw_hint(se->type);
 
+		buffer = calloc(F2FS_BLKSIZE, 1);
+		ASSERT(buffer);
+
 		printf("[FSCK] Finishing zone failed: %s\n", dev->path);
 		while (len--) {
 			ret = dev_fill_block(buffer, blk_addr++, whint);
@@ -3542,6 +3545,8 @@ static int chk_and_fix_wp_with_sit(int UNUSED(i), void *blkzone, void *opaque)
 				break;
 			}
 		}
+
+		free(buffer);
 	}
 
 	if (!ret)
-- 
2.40.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-03 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-03  7:26 [f2fs-dev] [PATCH] fsck.f2fs: fix to avoid using uninitialized buffer Chao Yu via Linux-f2fs-devel
2025-06-03 16:52 ` Daeho Jeong
2025-06-03 16:54   ` Daeho Jeong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.