Skip to content

Commit f07c7cc

Browse files
committed
fhandle: simplify error handling
Rely on our cleanup infrastructure. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Amir Goldstein <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent d2ab36b commit f07c7cc

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

fs/fhandle.c

+17-22
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,20 @@ static int do_handle_to_path(struct file_handle *handle, struct path *path,
261261
{
262262
int handle_dwords;
263263
struct vfsmount *mnt = ctx->root.mnt;
264+
struct dentry *dentry;
264265

265266
/* change the handle size to multiple of sizeof(u32) */
266267
handle_dwords = handle->handle_bytes >> 2;
267-
path->dentry = exportfs_decode_fh_raw(mnt,
268-
(struct fid *)handle->f_handle,
269-
handle_dwords, handle->handle_type,
270-
ctx->fh_flags,
271-
vfs_dentry_acceptable, ctx);
272-
if (IS_ERR_OR_NULL(path->dentry)) {
273-
if (path->dentry == ERR_PTR(-ENOMEM))
268+
dentry = exportfs_decode_fh_raw(mnt, (struct fid *)handle->f_handle,
269+
handle_dwords, handle->handle_type,
270+
ctx->fh_flags, vfs_dentry_acceptable,
271+
ctx);
272+
if (IS_ERR_OR_NULL(dentry)) {
273+
if (dentry == ERR_PTR(-ENOMEM))
274274
return -ENOMEM;
275275
return -ESTALE;
276276
}
277+
path->dentry = dentry;
277278
path->mnt = mntget(mnt);
278279
return 0;
279280
}
@@ -398,29 +399,23 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
398399
int open_flag)
399400
{
400401
long retval = 0;
401-
struct path path;
402+
struct path path __free(path_put) = {};
402403
struct file *file;
403-
int fd;
404404

405405
retval = handle_to_path(mountdirfd, ufh, &path, open_flag);
406406
if (retval)
407407
return retval;
408408

409-
fd = get_unused_fd_flags(open_flag);
410-
if (fd < 0) {
411-
path_put(&path);
409+
CLASS(get_unused_fd, fd)(O_CLOEXEC);
410+
if (fd < 0)
412411
return fd;
413-
}
412+
414413
file = file_open_root(&path, "", open_flag, 0);
415-
if (IS_ERR(file)) {
416-
put_unused_fd(fd);
417-
retval = PTR_ERR(file);
418-
} else {
419-
retval = fd;
420-
fd_install(fd, file);
421-
}
422-
path_put(&path);
423-
return retval;
414+
if (IS_ERR(file))
415+
return PTR_ERR(file);
416+
417+
fd_install(fd, file);
418+
return take_fd(fd);
424419
}
425420

426421
/**

0 commit comments

Comments
 (0)