mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
introduce fd_file(), convert all accessors to it.
For any changes of struct fd representation we need to
turn existing accesses to fields into calls of wrappers.
Accesses to struct fd::flags are very few (3 in linux/file.h,
1 in net/socket.c, 3 in fs/overlayfs/file.c and 3 more in
explicit initializers).
Those can be dealt with in the commit converting to
new layout; accesses to struct fd::file are too many for that.
This commit converts (almost) all of f.file to
fd_file(f). It's not entirely mechanical ('file' is used as
a member name more than just in struct fd) and it does not
even attempt to distinguish the uses in pointer context from
those in boolean context; the latter will be eventually turned
into a separate helper (fd_empty()).
NOTE: mass conversion to fd_empty(), tempting as it
might be, is a bad idea; better do that piecewise in commit
that convert from fdget...() to CLASS(...).
[conflicts in fs/fhandle.c, kernel/bpf/syscall.c, mm/memcontrol.c
caught by git; fs/stat.c one got caught by git grep]
[fs/xattr.c conflict]
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
@@ -160,10 +160,10 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
|
||||
.count = count
|
||||
};
|
||||
|
||||
if (!arg.file)
|
||||
if (!fd_file(arg))
|
||||
return -EBADF;
|
||||
|
||||
error = iterate_dir(arg.file, &buf.ctx);
|
||||
error = iterate_dir(fd_file(arg), &buf.ctx);
|
||||
if (error >= 0)
|
||||
error = buf.error;
|
||||
if (count != buf.count)
|
||||
|
||||
@@ -239,19 +239,19 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
|
||||
struct flock64 flock;
|
||||
long err = -EBADF;
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
goto out;
|
||||
|
||||
switch (cmd) {
|
||||
case F_GETLK64:
|
||||
case F_OFD_GETLK:
|
||||
err = security_file_fcntl(f.file, cmd, arg);
|
||||
err = security_file_fcntl(fd_file(f), cmd, arg);
|
||||
if (err)
|
||||
break;
|
||||
err = get_oabi_flock(&flock, argp);
|
||||
if (err)
|
||||
break;
|
||||
err = fcntl_getlk64(f.file, cmd, &flock);
|
||||
err = fcntl_getlk64(fd_file(f), cmd, &flock);
|
||||
if (!err)
|
||||
err = put_oabi_flock(&flock, argp);
|
||||
break;
|
||||
@@ -259,13 +259,13 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
|
||||
case F_SETLKW64:
|
||||
case F_OFD_SETLK:
|
||||
case F_OFD_SETLKW:
|
||||
err = security_file_fcntl(f.file, cmd, arg);
|
||||
err = security_file_fcntl(fd_file(f), cmd, arg);
|
||||
if (err)
|
||||
break;
|
||||
err = get_oabi_flock(&flock, argp);
|
||||
if (err)
|
||||
break;
|
||||
err = fcntl_setlk64(fd, f.file, cmd, &flock);
|
||||
err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
|
||||
break;
|
||||
default:
|
||||
err = sys_fcntl64(fd, cmd, arg);
|
||||
|
||||
@@ -118,12 +118,12 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
||||
struct fd f;
|
||||
|
||||
f = fdget(tablefd);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EBADF;
|
||||
|
||||
rcu_read_lock();
|
||||
list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) {
|
||||
if (stt == f.file->private_data) {
|
||||
if (stt == fd_file(f)->private_data) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1938,11 +1938,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
||||
|
||||
r = -EBADF;
|
||||
f = fdget(cap->args[0]);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
break;
|
||||
|
||||
r = -EPERM;
|
||||
dev = kvm_device_from_filp(f.file);
|
||||
dev = kvm_device_from_filp(fd_file(f));
|
||||
if (dev)
|
||||
r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
|
||||
|
||||
@@ -1957,11 +1957,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
||||
|
||||
r = -EBADF;
|
||||
f = fdget(cap->args[0]);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
break;
|
||||
|
||||
r = -EPERM;
|
||||
dev = kvm_device_from_filp(f.file);
|
||||
dev = kvm_device_from_filp(fd_file(f));
|
||||
if (dev) {
|
||||
if (xics_on_xive())
|
||||
r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]);
|
||||
@@ -1980,7 +1980,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
||||
|
||||
r = -EBADF;
|
||||
f = fdget(cap->args[0]);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
break;
|
||||
|
||||
r = -ENXIO;
|
||||
@@ -1990,7 +1990,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
||||
}
|
||||
|
||||
r = -EPERM;
|
||||
dev = kvm_device_from_filp(f.file);
|
||||
dev = kvm_device_from_filp(fd_file(f));
|
||||
if (dev)
|
||||
r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
|
||||
cap->args[1]);
|
||||
|
||||
@@ -66,8 +66,8 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
|
||||
if (flags & SPU_CREATE_AFFINITY_SPU) {
|
||||
struct fd neighbor = fdget(neighbor_fd);
|
||||
ret = -EBADF;
|
||||
if (neighbor.file) {
|
||||
ret = calls->create_thread(name, flags, mode, neighbor.file);
|
||||
if (fd_file(neighbor)) {
|
||||
ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
|
||||
fdput(neighbor);
|
||||
}
|
||||
} else
|
||||
@@ -89,8 +89,8 @@ SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus)
|
||||
|
||||
ret = -EBADF;
|
||||
arg = fdget(fd);
|
||||
if (arg.file) {
|
||||
ret = calls->spu_run(arg.file, unpc, ustatus);
|
||||
if (fd_file(arg)) {
|
||||
ret = calls->spu_run(fd_file(arg), unpc, ustatus);
|
||||
fdput(arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -895,10 +895,10 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
|
||||
{
|
||||
struct fd f = fdget(attribute_fd);
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EINVAL;
|
||||
|
||||
if (f.file->f_op != &sgx_provision_fops) {
|
||||
if (fd_file(f)->f_op != &sgx_provision_fops) {
|
||||
fdput(f);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -534,10 +534,10 @@ static int __sev_issue_cmd(int fd, int id, void *data, int *error)
|
||||
int ret;
|
||||
|
||||
f = fdget(fd);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EBADF;
|
||||
|
||||
ret = sev_issue_cmd_external_user(f.file, id, data, error);
|
||||
ret = sev_issue_cmd_external_user(fd_file(f), id, data, error);
|
||||
|
||||
fdput(f);
|
||||
return ret;
|
||||
@@ -2078,15 +2078,15 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
||||
bool charged = false;
|
||||
int ret;
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EBADF;
|
||||
|
||||
if (!file_is_kvm(f.file)) {
|
||||
if (!file_is_kvm(fd_file(f))) {
|
||||
ret = -EBADF;
|
||||
goto out_fput;
|
||||
}
|
||||
|
||||
source_kvm = f.file->private_data;
|
||||
source_kvm = fd_file(f)->private_data;
|
||||
ret = sev_lock_two_vms(kvm, source_kvm);
|
||||
if (ret)
|
||||
goto out_fput;
|
||||
@@ -2801,15 +2801,15 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
||||
struct kvm_sev_info *source_sev, *mirror_sev;
|
||||
int ret;
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EBADF;
|
||||
|
||||
if (!file_is_kvm(f.file)) {
|
||||
if (!file_is_kvm(fd_file(f))) {
|
||||
ret = -EBADF;
|
||||
goto e_source_fput;
|
||||
}
|
||||
|
||||
source_kvm = f.file->private_data;
|
||||
source_kvm = fd_file(f)->private_data;
|
||||
ret = sev_lock_two_vms(kvm, source_kvm);
|
||||
if (ret)
|
||||
goto e_source_fput;
|
||||
|
||||
@@ -43,10 +43,10 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
|
||||
uint32_t id;
|
||||
int r;
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EINVAL;
|
||||
|
||||
r = amdgpu_file_to_fpriv(f.file, &fpriv);
|
||||
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
||||
if (r) {
|
||||
fdput(f);
|
||||
return r;
|
||||
@@ -72,10 +72,10 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
|
||||
struct amdgpu_ctx *ctx;
|
||||
int r;
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EINVAL;
|
||||
|
||||
r = amdgpu_file_to_fpriv(f.file, &fpriv);
|
||||
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
||||
if (r) {
|
||||
fdput(f);
|
||||
return r;
|
||||
|
||||
@@ -715,16 +715,16 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
|
||||
struct fd f = fdget(fd);
|
||||
int ret;
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EINVAL;
|
||||
|
||||
if (f.file->f_op != &drm_syncobj_file_fops) {
|
||||
if (fd_file(f)->f_op != &drm_syncobj_file_fops) {
|
||||
fdput(f);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* take a reference to put in the idr */
|
||||
syncobj = f.file->private_data;
|
||||
syncobj = fd_file(f)->private_data;
|
||||
drm_syncobj_get(syncobj);
|
||||
|
||||
idr_preload(GFP_KERNEL);
|
||||
|
||||
@@ -1624,13 +1624,13 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
|
||||
|
||||
/* Get current fd to protect against it being closed */
|
||||
f = fdget(cmd.fd);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -ENOENT;
|
||||
if (f.file->f_op != &ucma_fops) {
|
||||
if (fd_file(f)->f_op != &ucma_fops) {
|
||||
ret = -EINVAL;
|
||||
goto file_put;
|
||||
}
|
||||
cur_file = f.file->private_data;
|
||||
cur_file = fd_file(f)->private_data;
|
||||
|
||||
/* Validate current fd and prevent destruction of id. */
|
||||
ctx = ucma_get_ctx(cur_file, cmd.id);
|
||||
|
||||
@@ -584,12 +584,12 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
|
||||
if (cmd.fd != -1) {
|
||||
/* search for file descriptor */
|
||||
f = fdget(cmd.fd);
|
||||
if (!f.file) {
|
||||
if (!fd_file(f)) {
|
||||
ret = -EBADF;
|
||||
goto err_tree_mutex_unlock;
|
||||
}
|
||||
|
||||
inode = file_inode(f.file);
|
||||
inode = file_inode(fd_file(f));
|
||||
xrcd = find_xrcd(ibudev, inode);
|
||||
if (!xrcd && !(cmd.oflags & O_CREAT)) {
|
||||
/* no file descriptor. Need CREATE flag */
|
||||
@@ -632,7 +632,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
|
||||
atomic_inc(&xrcd->usecnt);
|
||||
}
|
||||
|
||||
if (f.file)
|
||||
if (fd_file(f))
|
||||
fdput(f);
|
||||
|
||||
mutex_unlock(&ibudev->xrcd_tree_mutex);
|
||||
@@ -648,7 +648,7 @@ err:
|
||||
uobj_alloc_abort(&obj->uobject, attrs);
|
||||
|
||||
err_tree_mutex_unlock:
|
||||
if (f.file)
|
||||
if (fd_file(f))
|
||||
fdput(f);
|
||||
|
||||
mutex_unlock(&ibudev->xrcd_tree_mutex);
|
||||
|
||||
@@ -254,12 +254,12 @@ media_request_get_by_fd(struct media_device *mdev, int request_fd)
|
||||
return ERR_PTR(-EBADR);
|
||||
|
||||
f = fdget(request_fd);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
goto err_no_req_fd;
|
||||
|
||||
if (f.file->f_op != &request_fops)
|
||||
if (fd_file(f)->f_op != &request_fops)
|
||||
goto err_fput;
|
||||
req = f.file->private_data;
|
||||
req = fd_file(f)->private_data;
|
||||
if (req->mdev != mdev)
|
||||
goto err_fput;
|
||||
|
||||
|
||||
@@ -820,20 +820,20 @@ struct rc_dev *rc_dev_get_from_fd(int fd, bool write)
|
||||
struct lirc_fh *fh;
|
||||
struct rc_dev *dev;
|
||||
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return ERR_PTR(-EBADF);
|
||||
|
||||
if (f.file->f_op != &lirc_fops) {
|
||||
if (fd_file(f)->f_op != &lirc_fops) {
|
||||
fdput(f);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
if (write && !(f.file->f_mode & FMODE_WRITE)) {
|
||||
if (write && !(fd_file(f)->f_mode & FMODE_WRITE)) {
|
||||
fdput(f);
|
||||
return ERR_PTR(-EPERM);
|
||||
}
|
||||
|
||||
fh = f.file->private_data;
|
||||
fh = fd_file(f)->private_data;
|
||||
dev = fh->rc;
|
||||
|
||||
get_device(&dev->dev);
|
||||
|
||||
@@ -112,7 +112,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
|
||||
return -EFAULT;
|
||||
|
||||
f = fdget(fd);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EBADF;
|
||||
|
||||
mutex_lock(&group->group_lock);
|
||||
@@ -125,13 +125,13 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
container = vfio_container_from_file(f.file);
|
||||
container = vfio_container_from_file(fd_file(f));
|
||||
if (container) {
|
||||
ret = vfio_container_attach_group(container, group);
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
iommufd = iommufd_ctx_from_file(f.file);
|
||||
iommufd = iommufd_ctx_from_file(fd_file(f));
|
||||
if (!IS_ERR(iommufd)) {
|
||||
if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&
|
||||
group->type == VFIO_NO_IOMMU)
|
||||
|
||||
@@ -134,12 +134,12 @@ int vfio_virqfd_enable(void *opaque,
|
||||
INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject);
|
||||
|
||||
irqfd = fdget(fd);
|
||||
if (!irqfd.file) {
|
||||
if (!fd_file(irqfd)) {
|
||||
ret = -EBADF;
|
||||
goto err_fd;
|
||||
}
|
||||
|
||||
ctx = eventfd_ctx_fileget(irqfd.file);
|
||||
ctx = eventfd_ctx_fileget(fd_file(irqfd));
|
||||
if (IS_ERR(ctx)) {
|
||||
ret = PTR_ERR(ctx);
|
||||
goto err_ctx;
|
||||
@@ -171,7 +171,7 @@ int vfio_virqfd_enable(void *opaque,
|
||||
init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
|
||||
init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
|
||||
|
||||
events = vfs_poll(irqfd.file, &virqfd->pt);
|
||||
events = vfs_poll(fd_file(irqfd), &virqfd->pt);
|
||||
|
||||
/*
|
||||
* Check if there was an event already pending on the eventfd
|
||||
|
||||
@@ -125,12 +125,12 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
|
||||
INIT_WORK(&irqfd->shutdown, hsm_irqfd_shutdown_work);
|
||||
|
||||
f = fdget(args->fd);
|
||||
if (!f.file) {
|
||||
if (!fd_file(f)) {
|
||||
ret = -EBADF;
|
||||
goto out;
|
||||
}
|
||||
|
||||
eventfd = eventfd_ctx_fileget(f.file);
|
||||
eventfd = eventfd_ctx_fileget(fd_file(f));
|
||||
if (IS_ERR(eventfd)) {
|
||||
ret = PTR_ERR(eventfd);
|
||||
goto fail;
|
||||
@@ -157,7 +157,7 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
|
||||
mutex_unlock(&vm->irqfds_lock);
|
||||
|
||||
/* Check the pending event in this stage */
|
||||
events = vfs_poll(f.file, &irqfd->pt);
|
||||
events = vfs_poll(fd_file(f), &irqfd->pt);
|
||||
|
||||
if (events & EPOLLIN)
|
||||
acrn_irqfd_inject(irqfd);
|
||||
|
||||
@@ -959,12 +959,12 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
|
||||
INIT_WORK(&kirqfd->shutdown, irqfd_shutdown);
|
||||
|
||||
f = fdget(irqfd->fd);
|
||||
if (!f.file) {
|
||||
if (!fd_file(f)) {
|
||||
ret = -EBADF;
|
||||
goto error_kfree;
|
||||
}
|
||||
|
||||
kirqfd->eventfd = eventfd_ctx_fileget(f.file);
|
||||
kirqfd->eventfd = eventfd_ctx_fileget(fd_file(f));
|
||||
if (IS_ERR(kirqfd->eventfd)) {
|
||||
ret = PTR_ERR(kirqfd->eventfd);
|
||||
goto error_fd_put;
|
||||
@@ -995,7 +995,7 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
|
||||
* Check if there was an event already pending on the eventfd before we
|
||||
* registered, and trigger it as if we didn't miss it.
|
||||
*/
|
||||
events = vfs_poll(f.file, &kirqfd->pt);
|
||||
events = vfs_poll(fd_file(f), &kirqfd->pt);
|
||||
if (events & EPOLLIN)
|
||||
irqfd_inject(kirqfd);
|
||||
|
||||
@@ -1345,12 +1345,12 @@ static int privcmd_ioeventfd_assign(struct privcmd_ioeventfd *ioeventfd)
|
||||
return -ENOMEM;
|
||||
|
||||
f = fdget(ioeventfd->event_fd);
|
||||
if (!f.file) {
|
||||
if (!fd_file(f)) {
|
||||
ret = -EBADF;
|
||||
goto error_kfree;
|
||||
}
|
||||
|
||||
kioeventfd->eventfd = eventfd_ctx_fileget(f.file);
|
||||
kioeventfd->eventfd = eventfd_ctx_fileget(fd_file(f));
|
||||
fdput(f);
|
||||
|
||||
if (IS_ERR(kioeventfd->eventfd)) {
|
||||
|
||||
@@ -1312,12 +1312,12 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
|
||||
} else {
|
||||
struct fd src = fdget(fd);
|
||||
struct inode *src_inode;
|
||||
if (!src.file) {
|
||||
if (!fd_file(src)) {
|
||||
ret = -EINVAL;
|
||||
goto out_drop_write;
|
||||
}
|
||||
|
||||
src_inode = file_inode(src.file);
|
||||
src_inode = file_inode(fd_file(src));
|
||||
if (src_inode->i_sb != file_inode(file)->i_sb) {
|
||||
btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
|
||||
"Snapshot src from another FS");
|
||||
|
||||
@@ -127,9 +127,9 @@ static int coda_parse_fd(struct fs_context *fc, int fd)
|
||||
int idx;
|
||||
|
||||
f = fdget(fd);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return -EBADF;
|
||||
inode = file_inode(f.file);
|
||||
inode = file_inode(fd_file(f));
|
||||
if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) {
|
||||
fdput(f);
|
||||
return invalf(fc, "code: Not coda psdev");
|
||||
|
||||
@@ -349,9 +349,9 @@ struct eventfd_ctx *eventfd_ctx_fdget(int fd)
|
||||
{
|
||||
struct eventfd_ctx *ctx;
|
||||
struct fd f = fdget(fd);
|
||||
if (!f.file)
|
||||
if (!fd_file(f))
|
||||
return ERR_PTR(-EBADF);
|
||||
ctx = eventfd_ctx_fileget(f.file);
|
||||
ctx = eventfd_ctx_fileget(fd_file(f));
|
||||
fdput(f);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user