Skip to content

Commit 76342c9

Browse files
neilbrownbrauner
authored andcommitted
ovl: simplify gotos in ovl_rename()
Rather than having three separate goto label: out_unlock, out_dput_old, and out_dput, make use of that fact that dput() happily accepts a NULL pointer to reduce this to just one goto label: out_unlock. olddentry and newdentry are initialised to NULL and only set once a value dentry is found. They are then dput() late in the function. Suggested-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: NeilBrown <neil@brown.name> Link: https://lore.kernel.org/20250716004725.1206467-9-neil@brown.name Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent e460bc4 commit 76342c9

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

fs/overlayfs/dir.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,9 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
10821082
int err;
10831083
struct dentry *old_upperdir;
10841084
struct dentry *new_upperdir;
1085-
struct dentry *olddentry;
1086-
struct dentry *newdentry;
1087-
struct dentry *trap;
1085+
struct dentry *olddentry = NULL;
1086+
struct dentry *newdentry = NULL;
1087+
struct dentry *trap, *de;
10881088
bool old_opaque;
10891089
bool new_opaque;
10901090
bool cleanup_whiteout = false;
@@ -1197,21 +1197,23 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
11971197
goto out_revert_creds;
11981198
}
11991199

1200-
olddentry = ovl_lookup_upper(ofs, old->d_name.name, old_upperdir,
1201-
old->d_name.len);
1202-
err = PTR_ERR(olddentry);
1203-
if (IS_ERR(olddentry))
1200+
de = ovl_lookup_upper(ofs, old->d_name.name, old_upperdir,
1201+
old->d_name.len);
1202+
err = PTR_ERR(de);
1203+
if (IS_ERR(de))
12041204
goto out_unlock;
1205+
olddentry = de;
12051206

12061207
err = -ESTALE;
12071208
if (!ovl_matches_upper(old, olddentry))
1208-
goto out_dput_old;
1209+
goto out_unlock;
12091210

1210-
newdentry = ovl_lookup_upper(ofs, new->d_name.name, new_upperdir,
1211-
new->d_name.len);
1212-
err = PTR_ERR(newdentry);
1213-
if (IS_ERR(newdentry))
1214-
goto out_dput_old;
1211+
de = ovl_lookup_upper(ofs, new->d_name.name, new_upperdir,
1212+
new->d_name.len);
1213+
err = PTR_ERR(de);
1214+
if (IS_ERR(de))
1215+
goto out_unlock;
1216+
newdentry = de;
12151217

12161218
old_opaque = ovl_dentry_is_opaque(old);
12171219
new_opaque = ovl_dentry_is_opaque(new);
@@ -1220,49 +1222,49 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
12201222
if (d_inode(new) && ovl_dentry_upper(new)) {
12211223
if (opaquedir) {
12221224
if (newdentry != opaquedir)
1223-
goto out_dput;
1225+
goto out_unlock;
12241226
} else {
12251227
if (!ovl_matches_upper(new, newdentry))
1226-
goto out_dput;
1228+
goto out_unlock;
12271229
}
12281230
} else {
12291231
if (!d_is_negative(newdentry)) {
12301232
if (!new_opaque || !ovl_upper_is_whiteout(ofs, newdentry))
1231-
goto out_dput;
1233+
goto out_unlock;
12321234
} else {
12331235
if (flags & RENAME_EXCHANGE)
1234-
goto out_dput;
1236+
goto out_unlock;
12351237
}
12361238
}
12371239

12381240
if (olddentry == trap)
1239-
goto out_dput;
1241+
goto out_unlock;
12401242
if (newdentry == trap)
1241-
goto out_dput;
1243+
goto out_unlock;
12421244

12431245
if (olddentry->d_inode == newdentry->d_inode)
1244-
goto out_dput;
1246+
goto out_unlock;
12451247

12461248
err = 0;
12471249
if (ovl_type_merge_or_lower(old))
12481250
err = ovl_set_redirect(old, samedir);
12491251
else if (is_dir && !old_opaque && ovl_type_merge(new->d_parent))
12501252
err = ovl_set_opaque_xerr(old, olddentry, -EXDEV);
12511253
if (err)
1252-
goto out_dput;
1254+
goto out_unlock;
12531255

12541256
if (!overwrite && ovl_type_merge_or_lower(new))
12551257
err = ovl_set_redirect(new, samedir);
12561258
else if (!overwrite && new_is_dir && !new_opaque &&
12571259
ovl_type_merge(old->d_parent))
12581260
err = ovl_set_opaque_xerr(new, newdentry, -EXDEV);
12591261
if (err)
1260-
goto out_dput;
1262+
goto out_unlock;
12611263

12621264
err = ovl_do_rename(ofs, old_upperdir, olddentry,
12631265
new_upperdir, newdentry, flags);
12641266
if (err)
1265-
goto out_dput;
1267+
goto out_unlock;
12661268

12671269
if (cleanup_whiteout)
12681270
ovl_cleanup(ofs, old_upperdir->d_inode, newdentry);
@@ -1284,10 +1286,6 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
12841286
if (d_inode(new) && ovl_dentry_upper(new))
12851287
ovl_copyattr(d_inode(new));
12861288

1287-
out_dput:
1288-
dput(newdentry);
1289-
out_dput_old:
1290-
dput(olddentry);
12911289
out_unlock:
12921290
unlock_rename(new_upperdir, old_upperdir);
12931291
out_revert_creds:
@@ -1297,6 +1295,8 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
12971295
else
12981296
ovl_drop_write(old);
12991297
out:
1298+
dput(newdentry);
1299+
dput(olddentry);
13001300
dput(opaquedir);
13011301
ovl_cache_free(&list);
13021302
return err;

0 commit comments

Comments
 (0)