add patch add-missing-brelse-on-set_flex_bg_block_bitmap_error_path
[ext4-patch-queue.git] / avoid-extra-brelse-in-setup_new_flex_group_blocks
blob7aef4827028bff278bf10e0c594d33a01230c257
1 ext4: avoid potential extra brelse in setup_new_flex_group_blocks() 
3 From: Vasily Averin <vvs@virtuozzo.com>
5 Currently bh is set to NULL only during first iteration of for cycle,
6 then this pointer is not cleared after end of using.
7 Therefore rollback after errors can lead to extra brelse(bh) call,
8 decrements bh counter and later trigger an unexpected warning in __brelse()
10 Patch moves brelse() calls in body of cycle to exclude requirement of
11 brelse() call in rollback.
13 Fixes: 33afdcc5402d ("ext4: add a function which sets up group blocks ...")
14 Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
15 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 Cc: stable@kernel.org # 3.3+
17 ---
18  fs/ext4/resize.c | 8 ++------
19  1 file changed, 2 insertions(+), 6 deletions(-)
21 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
22 index ebbc663d0798..c3fa30878ca8 100644
23 --- a/fs/ext4/resize.c
24 +++ b/fs/ext4/resize.c
25 @@ -605,7 +605,6 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
26                 bh = bclean(handle, sb, block);
27                 if (IS_ERR(bh)) {
28                         err = PTR_ERR(bh);
29 -                       bh = NULL;
30                         goto out;
31                 }
32                 overhead = ext4_group_overhead_blocks(sb, group);
33 @@ -618,9 +617,9 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
34                 ext4_mark_bitmap_end(EXT4_B2C(sbi, group_data[i].blocks_count),
35                                      sb->s_blocksize * 8, bh->b_data);
36                 err = ext4_handle_dirty_metadata(handle, NULL, bh);
37 +               brelse(bh);
38                 if (err)
39                         goto out;
40 -               brelse(bh);
42  handle_ib:
43                 if (bg_flags[i] & EXT4_BG_INODE_UNINIT)
44 @@ -635,18 +634,16 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
45                 bh = bclean(handle, sb, block);
46                 if (IS_ERR(bh)) {
47                         err = PTR_ERR(bh);
48 -                       bh = NULL;
49                         goto out;
50                 }
52                 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb),
53                                      sb->s_blocksize * 8, bh->b_data);
54                 err = ext4_handle_dirty_metadata(handle, NULL, bh);
55 +               brelse(bh);
56                 if (err)
57                         goto out;
58 -               brelse(bh);
59         }
60 -       bh = NULL;
62         /* Mark group tables in block bitmap */
63         for (j = 0; j < GROUP_TABLE_COUNT; j++) {
64 @@ -685,7 +682,6 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
65         }
67  out:
68 -       brelse(bh);
69         err2 = ext4_journal_stop(handle);
70         if (err2 && !err)
71                 err = err2;
72 -- 
73 2.17.1