mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	fhandle: simplify error handling
Rely on our cleanup infrastructure. Link: https://lore.kernel.org/r/20241129-work-pidfs-file_handle-v1-2-87d803a42495@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
		
							parent
							
								
									d2ab36bb11
								
							
						
					
					
						commit
						f07c7cc468
					
				
					 1 changed files with 17 additions and 22 deletions
				
			
		
							
								
								
									
										35
									
								
								fs/fhandle.c
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								fs/fhandle.c
									
									
									
									
									
								
							| 
						 | 
					@ -261,19 +261,20 @@ static int do_handle_to_path(struct file_handle *handle, struct path *path,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int handle_dwords;
 | 
						int handle_dwords;
 | 
				
			||||||
	struct vfsmount *mnt = ctx->root.mnt;
 | 
						struct vfsmount *mnt = ctx->root.mnt;
 | 
				
			||||||
 | 
						struct dentry *dentry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* change the handle size to multiple of sizeof(u32) */
 | 
						/* change the handle size to multiple of sizeof(u32) */
 | 
				
			||||||
	handle_dwords = handle->handle_bytes >> 2;
 | 
						handle_dwords = handle->handle_bytes >> 2;
 | 
				
			||||||
	path->dentry = exportfs_decode_fh_raw(mnt,
 | 
						dentry = exportfs_decode_fh_raw(mnt, (struct fid *)handle->f_handle,
 | 
				
			||||||
					  (struct fid *)handle->f_handle,
 | 
					 | 
				
			||||||
					handle_dwords, handle->handle_type,
 | 
										handle_dwords, handle->handle_type,
 | 
				
			||||||
					  ctx->fh_flags,
 | 
										ctx->fh_flags, vfs_dentry_acceptable,
 | 
				
			||||||
					  vfs_dentry_acceptable, ctx);
 | 
										ctx);
 | 
				
			||||||
	if (IS_ERR_OR_NULL(path->dentry)) {
 | 
						if (IS_ERR_OR_NULL(dentry)) {
 | 
				
			||||||
		if (path->dentry == ERR_PTR(-ENOMEM))
 | 
							if (dentry == ERR_PTR(-ENOMEM))
 | 
				
			||||||
			return -ENOMEM;
 | 
								return -ENOMEM;
 | 
				
			||||||
		return -ESTALE;
 | 
							return -ESTALE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						path->dentry = dentry;
 | 
				
			||||||
	path->mnt = mntget(mnt);
 | 
						path->mnt = mntget(mnt);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -398,29 +399,23 @@ static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
 | 
				
			||||||
			   int open_flag)
 | 
								   int open_flag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	long retval = 0;
 | 
						long retval = 0;
 | 
				
			||||||
	struct path path;
 | 
						struct path path __free(path_put) = {};
 | 
				
			||||||
	struct file *file;
 | 
						struct file *file;
 | 
				
			||||||
	int fd;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	retval = handle_to_path(mountdirfd, ufh, &path, open_flag);
 | 
						retval = handle_to_path(mountdirfd, ufh, &path, open_flag);
 | 
				
			||||||
	if (retval)
 | 
						if (retval)
 | 
				
			||||||
		return retval;
 | 
							return retval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fd = get_unused_fd_flags(open_flag);
 | 
						CLASS(get_unused_fd, fd)(O_CLOEXEC);
 | 
				
			||||||
	if (fd < 0) {
 | 
						if (fd < 0)
 | 
				
			||||||
		path_put(&path);
 | 
					 | 
				
			||||||
		return fd;
 | 
							return fd;
 | 
				
			||||||
	}
 | 
					
 | 
				
			||||||
	file = file_open_root(&path, "", open_flag, 0);
 | 
						file = file_open_root(&path, "", open_flag, 0);
 | 
				
			||||||
	if (IS_ERR(file)) {
 | 
						if (IS_ERR(file))
 | 
				
			||||||
		put_unused_fd(fd);
 | 
							return PTR_ERR(file);
 | 
				
			||||||
		retval =  PTR_ERR(file);
 | 
					
 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		retval = fd;
 | 
					 | 
				
			||||||
	fd_install(fd, file);
 | 
						fd_install(fd, file);
 | 
				
			||||||
	}
 | 
						return take_fd(fd);
 | 
				
			||||||
	path_put(&path);
 | 
					 | 
				
			||||||
	return retval;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue