ext4: add missing brelse() in add_new_gdb_meta_bg() [Linux 3.16.72]

This Linux kernel change "ext4: add missing brelse() in add_new_gdb_meta_bg()" is included in the Linux 3.16.72 release. This change is authored by Lukas Czerner <lczerner [at] redhat.com> on Fri Mar 15 00:15:32 2019 -0400. The commit for this change in Linux stable tree is 7420151 (patch) which is from upstream commit d64264d. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream d64264d.

ext4: add missing brelse() in add_new_gdb_meta_bg()

commit d64264d6218e6892edd832dc3a5a5857c2856c53 upstream.

Currently in add_new_gdb_meta_bg() there is a missing brelse of gdb_bh
in case ext4_journal_get_write_access() fails.
Additionally kvfree() is missing in the same error path. Fix it by
moving the ext4_journal_get_write_access() before the ext4 sb update as
Ted suggested and release n_group_desc and gdb_bh in case it fails.

Fixes: 61a9c11e5e7a ("ext4: add missing brelse() add_new_gdb_meta_bg()'s error path")
Signed-off-by: Lukas Czerner <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <[email protected]>

There are 11 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/ext4/resize.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 80c3f1e..63597cd 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -908,11 +908,18 @@ static int add_new_gdb_meta_bg(struct super_block *sb,
    memcpy(n_group_desc, o_group_desc,
           EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *));
    n_group_desc[gdb_num] = gdb_bh;
+
+   BUFFER_TRACE(gdb_bh, "get_write_access");
+   err = ext4_journal_get_write_access(handle, gdb_bh);
+   if (err) {
+       kvfree(n_group_desc);
+       brelse(gdb_bh);
+       return err;
+   }
+
    EXT4_SB(sb)->s_group_desc = n_group_desc;
    EXT4_SB(sb)->s_gdb_count++;
    ext4_kvfree(o_group_desc);
-   BUFFER_TRACE(gdb_bh, "get_write_access");
-   err = ext4_journal_get_write_access(handle, gdb_bh);
    return err;
 }

Leave a Reply

Your email address will not be published. Required fields are marked *