diff mbox series

[RFC,13/20] ext4: mballoc: Don't BUG if kmalloc or read blk bitmap fail for DOUBLE_CHECK

Message ID e0ec6f93833863d35577028abacb7f0ca8b46e96.1588313626.git.riteshh@linux.ibm.com
State Superseded
Headers show
Series ext4: Fix ENOSPC error, improve mballoc dbg, other cleanups | expand

Commit Message

Ritesh Harjani May 1, 2020, 6:29 a.m. UTC
Remove the BUG_ON() logic if kmalloc() or ext4_read_block_bitmap() fails.
We should simply mark grp->bb_bitmap as NULL if above happens.
In fact ext4_read_block_bitmap() may even return an error in case of resize
ioctl. Hence remove this BUG_ON logic (fstests ext4/032 may trigger

Should we add a ext4_msg() if any of above fails?

Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
 fs/ext4/mballoc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index e32f3675f962..aa22ecf3f827 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -548,13 +548,20 @@  static void mb_group_bb_bitmap_alloc(struct super_block *sb,
 	struct buffer_head *bh;
 	grp->bb_bitmap = kmalloc(sb->s_blocksize, GFP_NOFS);
-	BUG_ON(grp->bb_bitmap == NULL);
+	if (!grp->bb_bitmap)
+		goto out;
 	bh = ext4_read_block_bitmap(sb, group);
+	if (IS_ERR_OR_NULL(bh)) {
+		kfree(grp->bb_bitmap);
+		grp->bb_bitmap = NULL;
+		goto out;
+	}
 	memcpy(grp->bb_bitmap, bh->b_data, sb->s_blocksize);
+	return;
 static void mb_group_bb_bitmap_free(struct ext4_group_info *grp)