Skip to content

Commit 0cf9c58

Browse files
mnikicjankara
authored andcommitted
ext2: replace BUG_ON with WARN_ON_ONCE in ext2_get_blocks
If ext2_get_blocks() is called with maxblocks == 0, it currently triggers a BUG_ON(), causing a kernel panic. While this condition implies a logic error in the caller, a filesystem should not crash the system due to invalid arguments. Replace the BUG_ON() with a WARN_ON_ONCE() to provide a stack trace for debugging, and return -EINVAL to handle the error gracefully. Signed-off-by: Milos Nikic <nikic.milos@gmail.com> Link: https://patch.msgid.link/20260207010617.216675-1-nikic.milos@gmail.com Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 6d942c8 commit 0cf9c58

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

fs/ext2/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ static int ext2_get_blocks(struct inode *inode,
638638
int count = 0;
639639
ext2_fsblk_t first_block = 0;
640640

641-
BUG_ON(maxblocks == 0);
641+
if (WARN_ON_ONCE(maxblocks == 0))
642+
return -EINVAL;
642643

643644
depth = ext2_block_to_path(inode,iblock,offsets,&blocks_to_boundary);
644645

0 commit comments

Comments
 (0)