Add stable@vger.kernel.org annotations
[ext4-patch-queue.git] / release-bh-in-make_indexed_dir
blobc2f5c96867631aeb5f583cb176fa3909dd8eda0b
1 ext4: release bh in make_indexed_dir
3 From: gmail <yngsion@gmail.com>
5 The commit 6050d47adcad: "ext4: bail out from make_indexed_dir() on
6 first error" could end up leaking bh2 in the error path.
8 [ Also avoid renaming bh2 to bh, which just confuses things --tytso ]
10 Cc: stable@vger.kernel.org
11 Signed-off-by: yangsheng <yngsion@gmail.com>
12 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 ---
14  fs/ext4/namei.c | 14 ++++++--------
15  1 file changed, 6 insertions(+), 8 deletions(-)
17 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
18 index 2243ae2..c344b81 100644
19 --- a/fs/ext4/namei.c
20 +++ b/fs/ext4/namei.c
21 @@ -2044,33 +2044,31 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
22         frame->entries = entries;
23         frame->at = entries;
24         frame->bh = bh;
25 -       bh = bh2;
27         retval = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
28         if (retval)
29                 goto out_frames;        
30 -       retval = ext4_handle_dirty_dirent_node(handle, dir, bh);
31 +       retval = ext4_handle_dirty_dirent_node(handle, dir, bh2);
32         if (retval)
33                 goto out_frames;        
35 -       de = do_split(handle,dir, &bh, frame, &fname->hinfo);
36 +       de = do_split(handle,dir, &bh2, frame, &fname->hinfo);
37         if (IS_ERR(de)) {
38                 retval = PTR_ERR(de);
39                 goto out_frames;
40         }
41 -       dx_release(frames);
43 -       retval = add_dirent_to_buf(handle, fname, dir, inode, de, bh);
44 -       brelse(bh);
45 -       return retval;
46 +       retval = add_dirent_to_buf(handle, fname, dir, inode, de, bh2);
47  out_frames:
48         /*
49          * Even if the block split failed, we have to properly write
50          * out all the changes we did so far. Otherwise we can end up
51          * with corrupted filesystem.
52          */
53 -       ext4_mark_inode_dirty(handle, dir);
54 +       if (retval)
55 +               ext4_mark_inode_dirty(handle, dir);
56         dx_release(frames);
57 +       brelse(bh2);
58         return retval;
59  }