Skip to content

Commit 6c2b324

Browse files
LiBaokun96tytso
authored andcommitted
ext4: add new ext4_ext_path_brelse() helper
Add ext4_ext_path_brelse() helper function to reduce duplicate code and ensure that path->p_bh is set to NULL after it is released. Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ojaswin Mujoo <[email protected]> Tested-by: Ojaswin Mujoo <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent dcaa6c3 commit 6c2b324

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

fs/ext4/extents.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,21 @@ static int ext4_ext_trunc_restart_fn(struct inode *inode, int *dropped)
106106
return 0;
107107
}
108108

109+
static inline void ext4_ext_path_brelse(struct ext4_ext_path *path)
110+
{
111+
brelse(path->p_bh);
112+
path->p_bh = NULL;
113+
}
114+
109115
static void ext4_ext_drop_refs(struct ext4_ext_path *path)
110116
{
111117
int depth, i;
112118

113119
if (!path)
114120
return;
115121
depth = path->p_depth;
116-
for (i = 0; i <= depth; i++, path++) {
117-
brelse(path->p_bh);
118-
path->p_bh = NULL;
119-
}
122+
for (i = 0; i <= depth; i++, path++)
123+
ext4_ext_path_brelse(path);
120124
}
121125

122126
void ext4_free_ext_path(struct ext4_ext_path *path)
@@ -635,8 +639,7 @@ int ext4_ext_precache(struct inode *inode)
635639
*/
636640
if ((i == depth) ||
637641
path[i].p_idx > EXT_LAST_INDEX(path[i].p_hdr)) {
638-
brelse(path[i].p_bh);
639-
path[i].p_bh = NULL;
642+
ext4_ext_path_brelse(path + i);
640643
i--;
641644
continue;
642645
}
@@ -1889,8 +1892,7 @@ static void ext4_ext_try_to_merge_up(handle_t *handle,
18891892
(path[1].p_ext - EXT_FIRST_EXTENT(path[1].p_hdr));
18901893
path[0].p_hdr->eh_max = cpu_to_le16(max_root);
18911894

1892-
brelse(path[1].p_bh);
1893-
path[1].p_bh = NULL;
1895+
ext4_ext_path_brelse(path + 1);
18941896
ext4_free_blocks(handle, inode, NULL, blk, 1,
18951897
EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET);
18961898
}
@@ -2959,8 +2961,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
29592961
err = ext4_ext_rm_leaf(handle, inode, path,
29602962
&partial, start, end);
29612963
/* root level has p_bh == NULL, brelse() eats this */
2962-
brelse(path[i].p_bh);
2963-
path[i].p_bh = NULL;
2964+
ext4_ext_path_brelse(path + i);
29642965
i--;
29652966
continue;
29662967
}
@@ -3022,8 +3023,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
30223023
err = ext4_ext_rm_idx(handle, inode, path, i);
30233024
}
30243025
/* root level has p_bh == NULL, brelse() eats this */
3025-
brelse(path[i].p_bh);
3026-
path[i].p_bh = NULL;
3026+
ext4_ext_path_brelse(path + i);
30273027
i--;
30283028
ext_debug(inode, "return to level %d\n", i);
30293029
}

0 commit comments

Comments
 (0)