Skip to content

Commit 6b854d5

Browse files
LiBaokun96tytso
authored andcommitted
ext4: get rid of ppath in get_ext_path()
The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. After getting rid of ppath in get_ext_path(), its caller may pass an error pointer to ext4_free_ext_path(), so it needs to teach ext4_free_ext_path() and ext4_ext_drop_refs() to skip the error pointer. No functional changes. 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 0be4c0c commit 6b854d5

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

fs/ext4/extents.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void ext4_ext_drop_refs(struct ext4_ext_path *path)
116116
{
117117
int depth, i;
118118

119-
if (!path)
119+
if (IS_ERR_OR_NULL(path))
120120
return;
121121
depth = path->p_depth;
122122
for (i = 0; i <= depth; i++, path++)
@@ -125,6 +125,8 @@ static void ext4_ext_drop_refs(struct ext4_ext_path *path)
125125

126126
void ext4_free_ext_path(struct ext4_ext_path *path)
127127
{
128+
if (IS_ERR_OR_NULL(path))
129+
return;
128130
ext4_ext_drop_refs(path);
129131
kfree(path);
130132
}
@@ -4193,7 +4195,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
41934195
path = ext4_find_extent(inode, map->m_lblk, NULL, 0);
41944196
if (IS_ERR(path)) {
41954197
err = PTR_ERR(path);
4196-
path = NULL;
41974198
goto out;
41984199
}
41994200

fs/ext4/move_extent.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,23 @@
1717
* get_ext_path() - Find an extent path for designated logical block number.
1818
* @inode: inode to be searched
1919
* @lblock: logical block number to find an extent path
20-
* @ppath: pointer to an extent path pointer (for output)
20+
* @path: pointer to an extent path
2121
*
22-
* ext4_find_extent wrapper. Return 0 on success, or a negative error value
23-
* on failure.
22+
* ext4_find_extent wrapper. Return an extent path pointer on success,
23+
* or an error pointer on failure.
2424
*/
25-
static inline int
25+
static inline struct ext4_ext_path *
2626
get_ext_path(struct inode *inode, ext4_lblk_t lblock,
27-
struct ext4_ext_path **ppath)
27+
struct ext4_ext_path *path)
2828
{
29-
struct ext4_ext_path *path = *ppath;
30-
31-
*ppath = NULL;
3229
path = ext4_find_extent(inode, lblock, path, EXT4_EX_NOCACHE);
3330
if (IS_ERR(path))
34-
return PTR_ERR(path);
31+
return path;
3532
if (path[ext_depth(inode)].p_ext == NULL) {
3633
ext4_free_ext_path(path);
37-
return -ENODATA;
34+
return ERR_PTR(-ENODATA);
3835
}
39-
*ppath = path;
40-
return 0;
36+
return path;
4137
}
4238

4339
/**
@@ -95,9 +91,11 @@ mext_check_coverage(struct inode *inode, ext4_lblk_t from, ext4_lblk_t count,
9591
int ret = 0;
9692
ext4_lblk_t last = from + count;
9793
while (from < last) {
98-
*err = get_ext_path(inode, from, &path);
99-
if (*err)
100-
goto out;
94+
path = get_ext_path(inode, from, path);
95+
if (IS_ERR(path)) {
96+
*err = PTR_ERR(path);
97+
return ret;
98+
}
10199
ext = path[ext_depth(inode)].p_ext;
102100
if (unwritten != ext4_ext_is_unwritten(ext))
103101
goto out;
@@ -636,9 +634,11 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
636634
int offset_in_page;
637635
int unwritten, cur_len;
638636

639-
ret = get_ext_path(orig_inode, o_start, &path);
640-
if (ret)
637+
path = get_ext_path(orig_inode, o_start, path);
638+
if (IS_ERR(path)) {
639+
ret = PTR_ERR(path);
641640
goto out;
641+
}
642642
ex = path[path->p_depth].p_ext;
643643
cur_blk = le32_to_cpu(ex->ee_block);
644644
cur_len = ext4_ext_get_actual_len(ex);

0 commit comments

Comments
 (0)