add patch report-real-fs-size-after-resize
[ext4-patch-queue.git] / add-missing-brelse-in-add_new_gdb_meta_bg
blobda699e2d6aca09d0695fe19f9566dba1417d967a
1 ext4: add missing brelse() in add_new_gdb_meta_bg()
3 From: Lukas Czerner <lczerner@redhat.com>
5 Currently in add_new_gdb_meta_bg() there is a missing brelse of gdb_bh
6 in case ext4_journal_get_write_access() fails.
7 Additionally kvfree() is missing in the same error path. Fix it by
8 moving the ext4_journal_get_write_access() before the ext4 sb update as
9 Ted suggested and release n_group_desc and gdb_bh in case it fails.
11 Fixes: 61a9c11e5e7a ("ext4: add missing brelse() add_new_gdb_meta_bg()'s error path")
12 Signed-off-by: Lukas Czerner <lczerner@redhat.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 ---
15 v2: Move ext4_journal_get_write_access() before we update ext4 sb
17  fs/ext4/resize.c | 11 +++++++++--
18  1 file changed, 9 insertions(+), 2 deletions(-)
20 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
21 index 48421de803b7..5f89c19043a2 100644
22 --- a/fs/ext4/resize.c
23 +++ b/fs/ext4/resize.c
24 @@ -932,11 +932,18 @@ static int add_new_gdb_meta_bg(struct super_block *sb,
25         memcpy(n_group_desc, o_group_desc,
26                EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *));
27         n_group_desc[gdb_num] = gdb_bh;
29 +       BUFFER_TRACE(gdb_bh, "get_write_access");
30 +       err = ext4_journal_get_write_access(handle, gdb_bh);
31 +       if (err) {
32 +               kvfree(n_group_desc);
33 +               brelse(gdb_bh);
34 +               return err;
35 +       }
37         EXT4_SB(sb)->s_group_desc = n_group_desc;
38         EXT4_SB(sb)->s_gdb_count++;
39         kvfree(o_group_desc);
40 -       BUFFER_TRACE(gdb_bh, "get_write_access");
41 -       err = ext4_journal_get_write_access(handle, gdb_bh);
42         return err;
43  }
45 -- 
46 2.20.1