fdget(), trivial conversions

fdget() is the first thing done in scope, all matching fdput() are
immediately followed by leaving the scope.

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro
2024-07-19 20:17:58 -04:00
committed by CrazyCat
parent 9cb821d55f
commit ce6364d29a

View File

@@ -815,28 +815,23 @@ void __exit lirc_dev_exit(void)
struct rc_dev *rc_dev_get_from_fd(int fd, bool write)
{
struct fd f = fdget(fd);
CLASS(fd, f)(fd);
struct lirc_fh *fh;
struct rc_dev *dev;
if (!fd_file(f))
if (fd_empty(f))
return ERR_PTR(-EBADF);
if (fd_file(f)->f_op != &lirc_fops) {
fdput(f);
if (fd_file(f)->f_op != &lirc_fops)
return ERR_PTR(-EINVAL);
}
if (write && !(fd_file(f)->f_mode & FMODE_WRITE)) {
fdput(f);
if (write && !(fd_file(f)->f_mode & FMODE_WRITE))
return ERR_PTR(-EPERM);
}
fh = fd_file(f)->private_data;
dev = fh->rc;
get_device(&dev->dev);
fdput(f);
return dev;
}