Skip to content

Commit 523f431

Browse files
committed
ext4: call ext4_ext_drop_refs() from ext4_ext_find_extent()
In nearly all of the calls to ext4_ext_find_extent() where the caller is trying to recycle the path object, ext4_ext_drop_refs() gets called to release the buffer heads before the path object gets overwritten. To simplify things for the callers, and to avoid the possibility of a memory leak, make ext4_ext_find_extent() responsible for dropping the buffers. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent dfe5080 commit 523f431

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,10 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
867867
eh = ext_inode_hdr(inode);
868868
depth = ext_depth(inode);
869869

870-
/* account possible depth increase */
871-
if (!path) {
870+
if (path)
871+
ext4_ext_drop_refs(path);
872+
else {
873+
/* account possible depth increase */
872874
path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 2),
873875
GFP_NOFS);
874876
if (unlikely(!path))
@@ -1356,7 +1358,6 @@ static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
13561358
goto out;
13571359

13581360
/* refill path */
1359-
ext4_ext_drop_refs(path);
13601361
path = ext4_ext_find_extent(inode,
13611362
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
13621363
ppath, gb_flags);
@@ -1369,7 +1370,6 @@ static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
13691370
goto out;
13701371

13711372
/* refill path */
1372-
ext4_ext_drop_refs(path);
13731373
path = ext4_ext_find_extent(inode,
13741374
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
13751375
ppath, gb_flags);
@@ -3319,7 +3319,6 @@ static int ext4_split_extent(handle_t *handle,
33193319
* Update path is required because previous ext4_split_extent_at() may
33203320
* result in split of original leaf or extent zeroout.
33213321
*/
3322-
ext4_ext_drop_refs(path);
33233322
path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
33243323
if (IS_ERR(path))
33253324
return PTR_ERR(path);
@@ -3718,7 +3717,6 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle,
37183717
EXT4_GET_BLOCKS_CONVERT);
37193718
if (err < 0)
37203719
return err;
3721-
ext4_ext_drop_refs(path);
37223720
path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
37233721
if (IS_ERR(path))
37243722
return PTR_ERR(path);
@@ -3947,7 +3945,6 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
39473945
EXT4_GET_BLOCKS_CONVERT_UNWRITTEN);
39483946
if (err < 0)
39493947
return err;
3950-
ext4_ext_drop_refs(path);
39513948
path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
39523949
if (IS_ERR(path))
39533950
return PTR_ERR(path);

0 commit comments

Comments
 (0)