Skip to content

Commit a000bc8

Browse files
LiBaokun96tytso
authored andcommitted
ext4: get rid of ppath in ext4_ext_create_new_leaf()
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. To get rid of the ppath in ext4_ext_create_new_leaf(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. 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 6b854d5 commit a000bc8

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

fs/ext4/extents.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,13 +1397,12 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
13971397
* finds empty index and adds new leaf.
13981398
* if no free index is found, then it requests in-depth growing.
13991399
*/
1400-
static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
1401-
unsigned int mb_flags,
1402-
unsigned int gb_flags,
1403-
struct ext4_ext_path **ppath,
1404-
struct ext4_extent *newext)
1400+
static struct ext4_ext_path *
1401+
ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
1402+
unsigned int mb_flags, unsigned int gb_flags,
1403+
struct ext4_ext_path *path,
1404+
struct ext4_extent *newext)
14051405
{
1406-
struct ext4_ext_path *path = *ppath;
14071406
struct ext4_ext_path *curp;
14081407
int depth, i, err = 0;
14091408

@@ -1424,28 +1423,25 @@ static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
14241423
* entry: create all needed subtree and add new leaf */
14251424
err = ext4_ext_split(handle, inode, mb_flags, path, newext, i);
14261425
if (err)
1427-
goto out;
1426+
goto errout;
14281427

14291428
/* refill path */
14301429
path = ext4_find_extent(inode,
14311430
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
14321431
path, gb_flags);
1433-
if (IS_ERR(path))
1434-
err = PTR_ERR(path);
1432+
return path;
14351433
} else {
14361434
/* tree is full, time to grow in depth */
14371435
err = ext4_ext_grow_indepth(handle, inode, mb_flags);
14381436
if (err)
1439-
goto out;
1437+
goto errout;
14401438

14411439
/* refill path */
14421440
path = ext4_find_extent(inode,
14431441
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
14441442
path, gb_flags);
1445-
if (IS_ERR(path)) {
1446-
err = PTR_ERR(path);
1447-
goto out;
1448-
}
1443+
if (IS_ERR(path))
1444+
return path;
14491445

14501446
/*
14511447
* only first (depth 0 -> 1) produces free space;
@@ -1457,9 +1453,11 @@ static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
14571453
goto repeat;
14581454
}
14591455
}
1460-
out:
1461-
*ppath = IS_ERR(path) ? NULL : path;
1462-
return err;
1456+
return path;
1457+
1458+
errout:
1459+
ext4_free_ext_path(path);
1460+
return ERR_PTR(err);
14631461
}
14641462

14651463
/*
@@ -2112,11 +2110,14 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
21122110
*/
21132111
if (gb_flags & EXT4_GET_BLOCKS_METADATA_NOFAIL)
21142112
mb_flags |= EXT4_MB_USE_RESERVED;
2115-
err = ext4_ext_create_new_leaf(handle, inode, mb_flags, gb_flags,
2116-
ppath, newext);
2117-
if (err)
2113+
path = ext4_ext_create_new_leaf(handle, inode, mb_flags, gb_flags,
2114+
path, newext);
2115+
if (IS_ERR(path)) {
2116+
*ppath = NULL;
2117+
err = PTR_ERR(path);
21182118
goto cleanup;
2119-
path = *ppath;
2119+
}
2120+
*ppath = path;
21202121
depth = ext_depth(inode);
21212122
eh = path[depth].p_hdr;
21222123

0 commit comments

Comments
 (0)