Skip to content

Commit

Permalink
ext4: avoid potential extra brelse in setup_new_flex_group_blocks()
Browse files Browse the repository at this point in the history
Currently bh is set to NULL only during first iteration of for cycle,
then this pointer is not cleared after end of using.
Therefore rollback after errors can lead to extra brelse(bh) call,
decrements bh counter and later trigger an unexpected warning in __brelse()

Patch moves brelse() calls in body of cycle to exclude requirement of
brelse() call in rollback.

Fixes: 33afdcc ("ext4: add a function which sets up group blocks ...")
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org # 3.3+
  • Loading branch information
Vasily Averin authored and Theodore Ts'o committed Nov 3, 2018
1 parent 33458ea commit 9e40289
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions fs/ext4/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
bh = bclean(handle, sb, block);
if (IS_ERR(bh)) {
err = PTR_ERR(bh);
bh = NULL;
goto out;
}
overhead = ext4_group_overhead_blocks(sb, group);
Expand All @@ -618,9 +617,9 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
ext4_mark_bitmap_end(EXT4_B2C(sbi, group_data[i].blocks_count),
sb->s_blocksize * 8, bh->b_data);
err = ext4_handle_dirty_metadata(handle, NULL, bh);
brelse(bh);
if (err)
goto out;
brelse(bh);

handle_ib:
if (bg_flags[i] & EXT4_BG_INODE_UNINIT)
Expand All @@ -635,18 +634,16 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
bh = bclean(handle, sb, block);
if (IS_ERR(bh)) {
err = PTR_ERR(bh);
bh = NULL;
goto out;
}

ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
sb->s_blocksize * 8, bh->b_data);
err = ext4_handle_dirty_metadata(handle, NULL, bh);
brelse(bh);
if (err)
goto out;
brelse(bh);
}
bh = NULL;

/* Mark group tables in block bitmap */
for (j = 0; j < GROUP_TABLE_COUNT; j++) {
Expand Down Expand Up @@ -685,7 +682,6 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
}

out:
brelse(bh);
err2 = ext4_journal_stop(handle);
if (err2 && !err)
err = err2;
Expand Down

0 comments on commit 9e40289

Please sign in to comment.