Skip to content

Commit

Permalink
Merge tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/kernel/git/viro/vfs

Pull 'struct fd' updates from Al Viro:
 "Just the 'struct fd' layout change, with conversion to accessor
  helpers"

* tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  add struct fd constructors, get rid of __to_fd()
  struct fd: representation change
  introduce fd_file(), convert all accessors to it.
  • Loading branch information
torvalds committed Sep 23, 2024
2 parents f8eb5bd + de12c33 commit f8ffbc3
Show file tree
Hide file tree
Showing 83 changed files with 562 additions and 559 deletions.
4 changes: 2 additions & 2 deletions arch/alpha/kernel/osf_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions arch/arm/kernel/sys_oabi-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,33 @@ 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;
case F_SETLK64:
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);
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kvm/book3s_64_vio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions arch/powerpc/kvm/powerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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]);
Expand All @@ -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;
Expand All @@ -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]);
Expand Down
8 changes: 4 additions & 4 deletions arch/powerpc/platforms/cell/spu_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kernel/cpu/sgx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,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;
}
Expand Down
16 changes: 8 additions & 8 deletions arch/x86/kvm/svm/sev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2803,15 +2803,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;
Expand Down
8 changes: 4 additions & 4 deletions drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,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;
Expand All @@ -71,10 +71,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;
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/drm_syncobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions drivers/infiniband/core/ucma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions drivers/infiniband/core/uverbs_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
struct inode *inode = NULL;
int new_xrcd = 0;
struct ib_device *ib_dev;
struct fd f = {};
struct fd f = EMPTY_FD;
int ret;

ret = uverbs_request(attrs, &cmd, sizeof(cmd));
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
Expand All @@ -648,7 +648,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
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);
Expand Down
6 changes: 3 additions & 3 deletions drivers/media/mc/mc-request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions drivers/media/rc/lirc_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions drivers/vfio/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions drivers/vfio/virqfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit f8ffbc3

Please sign in to comment.