Use the scoped ovl cred guard. Reviewed-by: Amir Goldstein Signed-off-by: Christian Brauner --- fs/overlayfs/dir.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 1a801fa40dd1..3dbca78aa1bb 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -1323,7 +1323,7 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir, static int ovl_create_tmpfile(struct file *file, struct dentry *dentry, struct inode *inode, umode_t mode) { - const struct cred *old_cred, *new_cred = NULL; + const struct cred *new_cred __free(put_cred) = NULL; struct path realparentpath; struct file *realfile; struct ovl_file *of; @@ -1332,13 +1332,10 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry, int flags = file->f_flags | OVL_OPEN_FLAGS; int err; - old_cred = ovl_override_creds(dentry->d_sb); + scoped_class(override_creds_ovl, old_cred, dentry->d_sb) { new_cred = ovl_setup_cred_for_create(dentry, inode, mode, old_cred); - err = PTR_ERR(new_cred); - if (IS_ERR(new_cred)) { - new_cred = NULL; - goto out_revert_creds; - } + if (IS_ERR(new_cred)) + return PTR_ERR(new_cred); ovl_path_upper(dentry->d_parent, &realparentpath); realfile = backing_tmpfile_open(&file->f_path, flags, &realparentpath, @@ -1346,13 +1343,12 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry, err = PTR_ERR_OR_ZERO(realfile); pr_debug("tmpfile/open(%pd2, 0%o) = %i\n", realparentpath.dentry, mode, err); if (err) - goto out_revert_creds; + return err; of = ovl_file_alloc(realfile); if (!of) { fput(realfile); - err = -ENOMEM; - goto out_revert_creds; + return -ENOMEM; } /* ovl_instantiate() consumes the newdentry reference on success */ @@ -1364,9 +1360,7 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry, dput(newdentry); ovl_file_free(of); } -out_revert_creds: - ovl_revert_creds(old_cred); - put_cred(new_cred); + } return err; } -- 2.47.3