[RHEL7,COMMIT] ext4 resise: extra brelse in setup_new_flex_group_blocks()

Submitted by Konstantin Khorenko on Oct. 31, 2018, 10:44 a.m.

Details

Message ID 201810311044.w9VAifPJ022771@finist-ce7.sw.ru
State New
Series "ext4 resise: extra brelse in setup_new_flex_group_blocks()"
Headers show

Commit Message

Konstantin Khorenko Oct. 31, 2018, 10:44 a.m.
The commit is pushed to "branch-rh7-3.10.0-862.14.4.vz7.72.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.14.4.vz7.72.15
------>
commit f492b8d02485e7bc35a0502c62caf6239ca91ea1
Author: Vasily Averin <vvs@virtuozzo.com>
Date:   Wed Oct 31 13:44:41 2018 +0300

    ext4 resise: extra brelse in setup_new_flex_group_blocks()
    
    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 33afdcc5402d ("ext4: add a function which sets up group blocks ...")
    VvS: was sent to mainline
    
    fixes warning in __brelse "VFS: brelse: Trying to free free buffer"
    https://jira.sw.ru/browse/PSBM-89583
    
    Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 fs/ext4/resize.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 5bfe31c8e0f9..30ee69563f6a 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -587,7 +587,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);
@@ -599,9 +598,9 @@  static int setup_new_flex_group_blocks(struct super_block *sb,
 		ext4_mark_bitmap_end(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)
@@ -616,18 +615,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++) {
@@ -658,7 +655,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;