History

Merge tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/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.

Linus Torvalds committed 2 years ago

Commit f8ffbc32 parents f8eb5bd de12c3383 files · +562 −559Browse files

Unified · Split

83 files
  1. arch/alpha/kernel/osf_sys.c +2 −2
  2. arch/arm/kernel/sys_oabi-compat.c +5 −5
  3. arch/powerpc/kvm/book3s_64_vio.c +2 −2
  4. arch/powerpc/kvm/powerpc.c +6 −6
  5. arch/powerpc/platforms/cell/spu_syscalls.c +4 −4
  6. arch/x86/kernel/cpu/sgx/main.c +2 −2
  7. arch/x86/kvm/svm/sev.c +8 −8
  8. drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +4 −4
  9. drivers/gpu/drm/drm_syncobj.c +3 −3
  10. drivers/infiniband/core/ucma.c +3 −3
  11. drivers/infiniband/core/uverbs_cmd.c +5 −5
  12. drivers/media/mc/mc-request.c +3 −3
  13. drivers/media/rc/lirc_dev.c +4 −4
  14. drivers/vfio/group.c +3 −3
  15. drivers/vfio/virqfd.c +3 −3
  16. drivers/virt/acrn/irqfd.c +3 −3
  17. drivers/xen/privcmd.c +5 −5
  18. fs/btrfs/ioctl.c +2 −2
  19. fs/eventfd.c +2 −2
  20. fs/eventpoll.c +15 −15
  21. fs/ext4/ioctl.c +3 −3
  22. fs/f2fs/file.c +3 −3
  23. fs/fcntl.c +19 −19
  24. fs/fhandle.c +2 −2
  25. fs/file.c +13 −13
  26. fs/fsopen.c +3 −3
  27. fs/fuse/dev.c +3 −3
  28. fs/ioctl.c +15 −15
  29. fs/kernel_read_file.c +2 −2
  30. fs/locks.c +7 −7
  31. fs/namei.c +5 −5
  32. fs/namespace.c +9 −9
  33. fs/notify/fanotify/fanotify_user.c +6 −6
  34. fs/notify/inotify/inotify_user.c +6 −6
  35. fs/ocfs2/cluster/heartbeat.c +3 −3
  36. fs/open.c +12 −12
  37. fs/overlayfs/file.c +35 −33
  38. fs/quota/quota.c +4 −4
  39. fs/read_write.c +59 −59
  40. fs/readdir.c +10 −10
  41. fs/remap_range.c +1 −1
  42. fs/select.c +4 −4
  43. fs/signalfd.c +3 −3
  44. fs/smb/client/ioctl.c +4 −4
  45. fs/splice.c +11 −11
  46. fs/stat.c +4 −4
  47. fs/statfs.c +2 −2
  48. fs/sync.c +7 −7
  49. fs/timerfd.c +4 −4
  50. fs/utimes.c +2 −2
  51. fs/xattr.c +18 −18
  52. fs/xfs/xfs_exchrange.c +4 −4
  53. fs/xfs/xfs_handle.c +3 −3
  54. fs/xfs/xfs_ioctl.c +14 −14
  55. include/linux/cleanup.h +1 −1
  56. include/linux/file.h +27 −26
  57. io_uring/sqpoll.c +5 −5
  58. ipc/mqueue.c +25 −25
  59. kernel/bpf/bpf_inode_storage.c +7 −7
  60. kernel/bpf/btf.c +3 −3
  61. kernel/bpf/syscall.c +21 −21
  62. kernel/bpf/token.c +5 −5
  63. kernel/cgroup/cgroup.c +2 −2
  64. kernel/events/core.c +7 −7
  65. kernel/module/main.c +1 −1
  66. kernel/nsproxy.c +6 −6
  67. kernel/pid.c +5 −5
  68. kernel/signal.c +3 −3
  69. kernel/sys.c +5 −5
  70. kernel/taskstats.c +2 −2
  71. kernel/watch_queue.c +2 −2
  72. mm/fadvise.c +2 −2
  73. mm/filemap.c +3 −3
  74. mm/memcontrol-v1.c +6 −6
  75. mm/readahead.c +5 −5
  76. net/core/net_namespace.c +3 −3
  77. net/socket.c +7 −7
  78. security/integrity/ima/ima_main.c +2 −2
  79. security/landlock/syscalls.c +11 −11
  80. security/loadpin/loadpin.c +2 −2
  81. sound/core/pcm_native.c +3 −3
  82. virt/kvm/eventfd.c +3 −3
  83. virt/kvm/vfio.c +4 −4
arch/alpha/kernel/osf_sys.c+2−2
@@ -160,10 +160,10 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd, · 159 unmodified lines
160160 .count = count
161161 };
162162
163− if (!arg.file)
163+ if (!fd_file(arg))
164164 return -EBADF;
165165
166− error = iterate_dir(arg.file, &buf.ctx);
166+ error = iterate_dir(fd_file(arg), &buf.ctx);
167167 if (error >= 0)
168168 error = buf.error;
169169 if (count != buf.count)
arch/arm/kernel/sys_oabi-compat.c+5−5
@@ -239,19 +239,19 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd, · 238 unmodified lines
239239 struct flock64 flock;
240240 long err = -EBADF;
241241
242− if (!f.file)
242+ if (!fd_file(f))
243243 goto out;
244244
245245 switch (cmd) {
246246 case F_GETLK64:
247247 case F_OFD_GETLK:
248− err = security_file_fcntl(f.file, cmd, arg);
248+ err = security_file_fcntl(fd_file(f), cmd, arg);
249249 if (err)
250250 break;
251251 err = get_oabi_flock(&flock, argp);
252252 if (err)
253253 break;
254− err = fcntl_getlk64(f.file, cmd, &flock);
254+ err = fcntl_getlk64(fd_file(f), cmd, &flock);
255255 if (!err)
256256 err = put_oabi_flock(&flock, argp);
257257 break;
@@ -259,13 +259,13 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd, · 1 unmodified line
259259 case F_SETLKW64:
260260 case F_OFD_SETLK:
261261 case F_OFD_SETLKW:
262− err = security_file_fcntl(f.file, cmd, arg);
262+ err = security_file_fcntl(fd_file(f), cmd, arg);
263263 if (err)
264264 break;
265265 err = get_oabi_flock(&flock, argp);
266266 if (err)
267267 break;
268− err = fcntl_setlk64(fd, f.file, cmd, &flock);
268+ err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
269269 break;
270270 default:
271271 err = sys_fcntl64(fd, cmd, arg);
arch/powerpc/kvm/book3s_64_vio.c+2−2
@@ -118,12 +118,12 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd, · 117 unmodified lines
118118 struct fd f;
119119
120120 f = fdget(tablefd);
121− if (!f.file)
121+ if (!fd_file(f))
122122 return -EBADF;
123123
124124 rcu_read_lock();
125125 list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) {
126− if (stt == f.file->private_data) {
126+ if (stt == fd_file(f)->private_data) {
127127 found = true;
128128 break;
129129 }
arch/powerpc/kvm/powerpc.c+6−6
@@ -1938,11 +1938,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, · 1937 unmodified lines
19381938
19391939 r = -EBADF;
19401940 f = fdget(cap->args[0]);
1941− if (!f.file)
1941+ if (!fd_file(f))
19421942 break;
19431943
19441944 r = -EPERM;
1945− dev = kvm_device_from_filp(f.file);
1945+ dev = kvm_device_from_filp(fd_file(f));
19461946 if (dev)
19471947 r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
19481948
@@ -1957,11 +1957,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, · 8 unmodified lines
19571957
19581958 r = -EBADF;
19591959 f = fdget(cap->args[0]);
1960− if (!f.file)
1960+ if (!fd_file(f))
19611961 break;
19621962
19631963 r = -EPERM;
1964− dev = kvm_device_from_filp(f.file);
1964+ dev = kvm_device_from_filp(fd_file(f));
19651965 if (dev) {
19661966 if (xics_on_xive())
19671967 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, · 12 unmodified lines
19801980
19811981 r = -EBADF;
19821982 f = fdget(cap->args[0]);
1983− if (!f.file)
1983+ if (!fd_file(f))
19841984 break;
19851985
19861986 r = -ENXIO;
@@ -1990,7 +1990,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, · 3 unmodified lines
19901990 }
19911991
19921992 r = -EPERM;
1993− dev = kvm_device_from_filp(f.file);
1993+ dev = kvm_device_from_filp(fd_file(f));
19941994 if (dev)
19951995 r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
19961996 cap->args[1]);
arch/powerpc/platforms/cell/spu_syscalls.c+4−4
@@ -66,8 +66,8 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags, · 65 unmodified lines
6666 if (flags & SPU_CREATE_AFFINITY_SPU) {
6767 struct fd neighbor = fdget(neighbor_fd);
6868 ret = -EBADF;
69− if (neighbor.file) {
70− ret = calls->create_thread(name, flags, mode, neighbor.file);
69+ if (fd_file(neighbor)) {
70+ ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
7171 fdput(neighbor);
7272 }
7373 } else
@@ -89,8 +89,8 @@ SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus) · 15 unmodified lines
8989
9090 ret = -EBADF;
9191 arg = fdget(fd);
92− if (arg.file) {
93− ret = calls->spu_run(arg.file, unpc, ustatus);
92+ if (fd_file(arg)) {
93+ ret = calls->spu_run(fd_file(arg), unpc, ustatus);
9494 fdput(arg);
9595 }
9696
arch/x86/kernel/cpu/sgx/main.c+2−2
@@ -903,10 +903,10 @@ int sgx_set_attribute(unsigned long *allowed_attributes, · 902 unmodified lines
903903 {
904904 struct fd f = fdget(attribute_fd);
905905
906− if (!f.file)
906+ if (!fd_file(f))
907907 return -EINVAL;
908908
909− if (f.file->f_op != &sgx_provision_fops) {
909+ if (fd_file(f)->f_op != &sgx_provision_fops) {
910910 fdput(f);
911911 return -EINVAL;
912912 }
arch/x86/kvm/svm/sev.c+8−8
@@ -534,10 +534,10 @@ static int __sev_issue_cmd(int fd, int id, void *data, int *error) · 533 unmodified lines
534534 int ret;
535535
536536 f = fdget(fd);
537− if (!f.file)
537+ if (!fd_file(f))
538538 return -EBADF;
539539
540− ret = sev_issue_cmd_external_user(f.file, id, data, error);
540+ ret = sev_issue_cmd_external_user(fd_file(f), id, data, error);
541541
542542 fdput(f);
543543 return ret;
@@ -2078,15 +2078,15 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd) · 1534 unmodified lines
20782078 bool charged = false;
20792079 int ret;
20802080
2081− if (!f.file)
2081+ if (!fd_file(f))
20822082 return -EBADF;
20832083
2084− if (!file_is_kvm(f.file)) {
2084+ if (!file_is_kvm(fd_file(f))) {
20852085 ret = -EBADF;
20862086 goto out_fput;
20872087 }
20882088
2089− source_kvm = f.file->private_data;
2089+ source_kvm = fd_file(f)->private_data;
20902090 ret = sev_lock_two_vms(kvm, source_kvm);
20912091 if (ret)
20922092 goto out_fput;
@@ -2803,15 +2803,15 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd) · 710 unmodified lines
28032803 struct kvm_sev_info *source_sev, *mirror_sev;
28042804 int ret;
28052805
2806− if (!f.file)
2806+ if (!fd_file(f))
28072807 return -EBADF;
28082808
2809− if (!file_is_kvm(f.file)) {
2809+ if (!file_is_kvm(fd_file(f))) {
28102810 ret = -EBADF;
28112811 goto e_source_fput;
28122812 }
28132813
2814− source_kvm = f.file->private_data;
2814+ source_kvm = fd_file(f)->private_data;
28152815 ret = sev_lock_two_vms(kvm, source_kvm);
28162816 if (ret)
28172817 goto e_source_fput;
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c+4−4
@@ -42,10 +42,10 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, · 41 unmodified lines
4242 uint32_t id;
4343 int r;
4444
45− if (!f.file)
45+ if (!fd_file(f))
4646 return -EINVAL;
4747
48− r = amdgpu_file_to_fpriv(f.file, &fpriv);
48+ r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
4949 if (r) {
5050 fdput(f);
5151 return r;
@@ -71,10 +71,10 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev, · 19 unmodified lines
7171 struct amdgpu_ctx *ctx;
7272 int r;
7373
74− if (!f.file)
74+ if (!fd_file(f))
7575 return -EINVAL;
7676
77− r = amdgpu_file_to_fpriv(f.file, &fpriv);
77+ r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
7878 if (r) {
7979 fdput(f);
8080 return r;
drivers/gpu/drm/drm_syncobj.c+3−3
@@ -715,16 +715,16 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, · 714 unmodified lines
715715 struct fd f = fdget(fd);
716716 int ret;
717717
718− if (!f.file)
718+ if (!fd_file(f))
719719 return -EINVAL;
720720
721− if (f.file->f_op != &drm_syncobj_file_fops) {
721+ if (fd_file(f)->f_op != &drm_syncobj_file_fops) {
722722 fdput(f);
723723 return -EINVAL;
724724 }
725725
726726 /* take a reference to put in the idr */
727− syncobj = f.file->private_data;
727+ syncobj = fd_file(f)->private_data;
728728 drm_syncobj_get(syncobj);
729729
730730 idr_preload(GFP_KERNEL);
drivers/infiniband/core/ucma.c+3−3
@@ -1624,13 +1624,13 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file, · 1623 unmodified lines
16241624
16251625 /* Get current fd to protect against it being closed */
16261626 f = fdget(cmd.fd);
1627− if (!f.file)
1627+ if (!fd_file(f))
16281628 return -ENOENT;
1629− if (f.file->f_op != &ucma_fops) {
1629+ if (fd_file(f)->f_op != &ucma_fops) {
16301630 ret = -EINVAL;
16311631 goto file_put;
16321632 }
1633− cur_file = f.file->private_data;
1633+ cur_file = fd_file(f)->private_data;
16341634
16351635 /* Validate current fd and prevent destruction of id. */
16361636 ctx = ucma_get_ctx(cur_file, cmd.id);
drivers/infiniband/core/uverbs_cmd.c+5−5
@@ -572,7 +572,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs) · 571 unmodified lines
572572 struct inode *inode = NULL;
573573 int new_xrcd = 0;
574574 struct ib_device *ib_dev;
575− struct fd f = {};
575+ struct fd f = EMPTY_FD;
576576 int ret;
577577
578578 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
@@ -584,12 +584,12 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs) · 5 unmodified lines
584584 if (cmd.fd != -1) {
585585 /* search for file descriptor */
586586 f = fdget(cmd.fd);
587− if (!f.file) {
587+ if (!fd_file(f)) {
588588 ret = -EBADF;
589589 goto err_tree_mutex_unlock;
590590 }
591591
592− inode = file_inode(f.file);
592+ inode = file_inode(fd_file(f));
593593 xrcd = find_xrcd(ibudev, inode);
594594 if (!xrcd && !(cmd.oflags & O_CREAT)) {
595595 /* no file descriptor. Need CREATE flag */
@@ -632,7 +632,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs) · 36 unmodified lines
632632 atomic_inc(&xrcd->usecnt);
633633 }
634634
635− if (f.file)
635+ if (fd_file(f))
636636 fdput(f);
637637
638638 mutex_unlock(&ibudev->xrcd_tree_mutex);
@@ -648,7 +648,7 @@ err: · 9 unmodified lines
648648 uobj_alloc_abort(&obj->uobject, attrs);
649649
650650 err_tree_mutex_unlock:
651− if (f.file)
651+ if (fd_file(f))
652652 fdput(f);
653653
654654 mutex_unlock(&ibudev->xrcd_tree_mutex);
drivers/media/mc/mc-request.c+3−3
@@ -254,12 +254,12 @@ media_request_get_by_fd(struct media_device *mdev, int request_fd) · 253 unmodified lines
254254 return ERR_PTR(-EBADR);
255255
256256 f = fdget(request_fd);
257− if (!f.file)
257+ if (!fd_file(f))
258258 goto err_no_req_fd;
259259
260− if (f.file->f_op != &request_fops)
260+ if (fd_file(f)->f_op != &request_fops)
261261 goto err_fput;
262− req = f.file->private_data;
262+ req = fd_file(f)->private_data;
263263 if (req->mdev != mdev)
264264 goto err_fput;
265265
drivers/media/rc/lirc_dev.c+4−4
@@ -820,20 +820,20 @@ struct rc_dev *rc_dev_get_from_fd(int fd, bool write) · 819 unmodified lines
820820 struct lirc_fh *fh;
821821 struct rc_dev *dev;
822822
823− if (!f.file)
823+ if (!fd_file(f))
824824 return ERR_PTR(-EBADF);
825825
826− if (f.file->f_op != &lirc_fops) {
826+ if (fd_file(f)->f_op != &lirc_fops) {
827827 fdput(f);
828828 return ERR_PTR(-EINVAL);
829829 }
830830
831− if (write && !(f.file->f_mode & FMODE_WRITE)) {
831+ if (write && !(fd_file(f)->f_mode & FMODE_WRITE)) {
832832 fdput(f);
833833 return ERR_PTR(-EPERM);
834834 }
835835
836− fh = f.file->private_data;
836+ fh = fd_file(f)->private_data;
837837 dev = fh->rc;
838838
839839 get_device(&dev->dev);
drivers/vfio/group.c+3−3
@@ -112,7 +112,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group, · 111 unmodified lines
112112 return -EFAULT;
113113
114114 f = fdget(fd);
115− if (!f.file)
115+ if (!fd_file(f))
116116 return -EBADF;
117117
118118 mutex_lock(&group->group_lock);
@@ -125,13 +125,13 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group, · 6 unmodified lines
125125 goto out_unlock;
126126 }
127127
128− container = vfio_container_from_file(f.file);
128+ container = vfio_container_from_file(fd_file(f));
129129 if (container) {
130130 ret = vfio_container_attach_group(container, group);
131131 goto out_unlock;
132132 }
133133
134− iommufd = iommufd_ctx_from_file(f.file);
134+ iommufd = iommufd_ctx_from_file(fd_file(f));
135135 if (!IS_ERR(iommufd)) {
136136 if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&
137137 group->type == VFIO_NO_IOMMU)
drivers/vfio/virqfd.c+3−3
@@ -134,12 +134,12 @@ int vfio_virqfd_enable(void *opaque, · 133 unmodified lines
134134 INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject);
135135
136136 irqfd = fdget(fd);
137− if (!irqfd.file) {
137+ if (!fd_file(irqfd)) {
138138 ret = -EBADF;
139139 goto err_fd;
140140 }
141141
142− ctx = eventfd_ctx_fileget(irqfd.file);
142+ ctx = eventfd_ctx_fileget(fd_file(irqfd));
143143 if (IS_ERR(ctx)) {
144144 ret = PTR_ERR(ctx);
145145 goto err_ctx;
@@ -171,7 +171,7 @@ int vfio_virqfd_enable(void *opaque, · 25 unmodified lines
171171 init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
172172 init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
173173
174− events = vfs_poll(irqfd.file, &virqfd->pt);
174+ events = vfs_poll(fd_file(irqfd), &virqfd->pt);
175175
176176 /*
177177 * Check if there was an event already pending on the eventfd
drivers/virt/acrn/irqfd.c+3−3
@@ -125,12 +125,12 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args) · 124 unmodified lines
125125 INIT_WORK(&irqfd->shutdown, hsm_irqfd_shutdown_work);
126126
127127 f = fdget(args->fd);
128− if (!f.file) {
128+ if (!fd_file(f)) {
129129 ret = -EBADF;
130130 goto out;
131131 }
132132
133− eventfd = eventfd_ctx_fileget(f.file);
133+ eventfd = eventfd_ctx_fileget(fd_file(f));
134134 if (IS_ERR(eventfd)) {
135135 ret = PTR_ERR(eventfd);
136136 goto fail;
@@ -157,7 +157,7 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args) · 20 unmodified lines
157157 mutex_unlock(&vm->irqfds_lock);
158158
159159 /* Check the pending event in this stage */
160− events = vfs_poll(f.file, &irqfd->pt);
160+ events = vfs_poll(fd_file(f), &irqfd->pt);
161161
162162 if (events & EPOLLIN)
163163 acrn_irqfd_inject(irqfd);
drivers/xen/privcmd.c+5−5
@@ -959,12 +959,12 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd) · 958 unmodified lines
959959 INIT_WORK(&kirqfd->shutdown, irqfd_shutdown);
960960
961961 f = fdget(irqfd->fd);
962− if (!f.file) {
962+ if (!fd_file(f)) {
963963 ret = -EBADF;
964964 goto error_kfree;
965965 }
966966
967− kirqfd->eventfd = eventfd_ctx_fileget(f.file);
967+ kirqfd->eventfd = eventfd_ctx_fileget(fd_file(f));
968968 if (IS_ERR(kirqfd->eventfd)) {
969969 ret = PTR_ERR(kirqfd->eventfd);
970970 goto error_fd_put;
@@ -995,7 +995,7 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd) · 24 unmodified lines
995995 * Check if there was an event already pending on the eventfd before we
996996 * registered, and trigger it as if we didn't miss it.
997997 */
998− events = vfs_poll(f.file, &kirqfd->pt);
998+ events = vfs_poll(fd_file(f), &kirqfd->pt);
999999 if (events & EPOLLIN)
10001000 irqfd_inject(kirqfd);
10011001
@@ -1345,12 +1345,12 @@ static int privcmd_ioeventfd_assign(struct privcmd_ioeventfd *ioeventfd) · 343 unmodified lines
13451345 return -ENOMEM;
13461346
13471347 f = fdget(ioeventfd->event_fd);
1348− if (!f.file) {
1348+ if (!fd_file(f)) {
13491349 ret = -EBADF;
13501350 goto error_kfree;
13511351 }
13521352
1353− kioeventfd->eventfd = eventfd_ctx_fileget(f.file);
1353+ kioeventfd->eventfd = eventfd_ctx_fileget(fd_file(f));
13541354 fdput(f);
13551355
13561356 if (IS_ERR(kioeventfd->eventfd)) {
fs/btrfs/ioctl.c+2−2
@@ -1310,12 +1310,12 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, · 1309 unmodified lines
13101310 } else {
13111311 struct fd src = fdget(fd);
13121312 struct inode *src_inode;
1313− if (!src.file) {
1313+ if (!fd_file(src)) {
13141314 ret = -EINVAL;
13151315 goto out_drop_write;
13161316 }
13171317
1318− src_inode = file_inode(src.file);
1318+ src_inode = file_inode(fd_file(src));
13191319 if (src_inode->i_sb != file_inode(file)->i_sb) {
13201320 btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
13211321 "Snapshot src from another FS");
fs/eventfd.c+2−2
@@ -349,9 +349,9 @@ struct eventfd_ctx *eventfd_ctx_fdget(int fd) · 348 unmodified lines
349349 {
350350 struct eventfd_ctx *ctx;
351351 struct fd f = fdget(fd);
352− if (!f.file)
352+ if (!fd_file(f))
353353 return ERR_PTR(-EBADF);
354− ctx = eventfd_ctx_fileget(f.file);
354+ ctx = eventfd_ctx_fileget(fd_file(f));
355355 fdput(f);
356356 return ctx;
357357 }
fs/eventpoll.c+15−15
@@ -2261,17 +2261,17 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 2260 unmodified lines
22612261
22622262 error = -EBADF;
22632263 f = fdget(epfd);
2264− if (!f.file)
2264+ if (!fd_file(f))
22652265 goto error_return;
22662266
22672267 /* Get the "struct file *" for the target file */
22682268 tf = fdget(fd);
2269− if (!tf.file)
2269+ if (!fd_file(tf))
22702270 goto error_fput;
22712271
22722272 /* The target file descriptor must support poll */
22732273 error = -EPERM;
2274− if (!file_can_poll(tf.file))
2274+ if (!file_can_poll(fd_file(tf)))
22752275 goto error_tgt_fput;
22762276
22772277 /* Check if EPOLLWAKEUP is allowed */
@@ -2284,7 +2284,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 6 unmodified lines
22842284 * adding an epoll file descriptor inside itself.
22852285 */
22862286 error = -EINVAL;
2287− if (f.file == tf.file || !is_file_epoll(f.file))
2287+ if (fd_file(f) == fd_file(tf) || !is_file_epoll(fd_file(f)))
22882288 goto error_tgt_fput;
22892289
22902290 /*
@@ -2295,7 +2295,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 4 unmodified lines
22952295 if (ep_op_has_event(op) && (epds->events & EPOLLEXCLUSIVE)) {
22962296 if (op == EPOLL_CTL_MOD)
22972297 goto error_tgt_fput;
2298− if (op == EPOLL_CTL_ADD && (is_file_epoll(tf.file) ||
2298+ if (op == EPOLL_CTL_ADD && (is_file_epoll(fd_file(tf)) ||
22992299 (epds->events & ~EPOLLEXCLUSIVE_OK_BITS)))
23002300 goto error_tgt_fput;
23012301 }
@@ -2304,7 +2304,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 2 unmodified lines
23042304 * At this point it is safe to assume that the "private_data" contains
23052305 * our own data structure.
23062306 */
2307− ep = f.file->private_data;
2307+ ep = fd_file(f)->private_data;
23082308
23092309 /*
23102310 * When we insert an epoll file descriptor inside another epoll file
@@ -2325,16 +2325,16 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 14 unmodified lines
23252325 if (error)
23262326 goto error_tgt_fput;
23272327 if (op == EPOLL_CTL_ADD) {
2328− if (READ_ONCE(f.file->f_ep) || ep->gen == loop_check_gen ||
2329− is_file_epoll(tf.file)) {
2328+ if (READ_ONCE(fd_file(f)->f_ep) || ep->gen == loop_check_gen ||
2329+ is_file_epoll(fd_file(tf))) {
23302330 mutex_unlock(&ep->mtx);
23312331 error = epoll_mutex_lock(&epnested_mutex, 0, nonblock);
23322332 if (error)
23332333 goto error_tgt_fput;
23342334 loop_check_gen++;
23352335 full_check = 1;
2336− if (is_file_epoll(tf.file)) {
2337− tep = tf.file->private_data;
2336+ if (is_file_epoll(fd_file(tf))) {
2337+ tep = fd_file(tf)->private_data;
23382338 error = -ELOOP;
23392339 if (ep_loop_check(ep, tep) != 0)
23402340 goto error_tgt_fput;
@@ -2350,14 +2350,14 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 9 unmodified lines
23502350 * above, we can be sure to be able to use the item looked up by
23512351 * ep_find() till we release the mutex.
23522352 */
2353− epi = ep_find(ep, tf.file, fd);
2353+ epi = ep_find(ep, fd_file(tf), fd);
23542354
23552355 error = -EINVAL;
23562356 switch (op) {
23572357 case EPOLL_CTL_ADD:
23582358 if (!epi) {
23592359 epds->events |= EPOLLERR | EPOLLHUP;
2360− error = ep_insert(ep, epds, tf.file, fd, full_check);
2360+ error = ep_insert(ep, epds, fd_file(tf), fd, full_check);
23612361 } else
23622362 error = -EEXIST;
23632363 break;
@@ -2438,7 +2438,7 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events, · 74 unmodified lines
24382438
24392439 /* Get the "struct file *" for the eventpoll file */
24402440 f = fdget(epfd);
2441− if (!f.file)
2441+ if (!fd_file(f))
24422442 return -EBADF;
24432443
24442444 /*
@@ -2446,14 +2446,14 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events, · 1 unmodified line
24462446 * the user passed to us _is_ an eventpoll file.
24472447 */
24482448 error = -EINVAL;
2449− if (!is_file_epoll(f.file))
2449+ if (!is_file_epoll(fd_file(f)))
24502450 goto error_fput;
24512451
24522452 /*
24532453 * At this point it is safe to assume that the "private_data" contains
24542454 * our own data structure.
24552455 */
2456− ep = f.file->private_data;
2456+ ep = fd_file(f)->private_data;
24572457
24582458 /* Time to fish for events ... */
24592459 error = ep_poll(ep, events, maxevents, to);
fs/ext4/ioctl.c+3−3
@@ -1343,10 +1343,10 @@ group_extend_out: · 1342 unmodified lines
13431343 me.moved_len = 0;
13441344
13451345 donor = fdget(me.donor_fd);
1346− if (!donor.file)
1346+ if (!fd_file(donor))
13471347 return -EBADF;
13481348
1349− if (!(donor.file->f_mode & FMODE_WRITE)) {
1349+ if (!(fd_file(donor)->f_mode & FMODE_WRITE)) {
13501350 err = -EBADF;
13511351 goto mext_out;
13521352 }
@@ -1367,7 +1367,7 @@ group_extend_out: · 14 unmodified lines
13671367 if (err)
13681368 goto mext_out;
13691369
1370− err = ext4_move_extents(filp, donor.file, me.orig_start,
1370+ err = ext4_move_extents(filp, fd_file(donor), me.orig_start,
13711371 me.donor_start, me.len, &me.moved_len);
13721372 mnt_drop_write_file(filp);
13731373
fs/f2fs/file.c+3−3
@@ -3014,10 +3014,10 @@ static int __f2fs_ioc_move_range(struct file *filp, · 3013 unmodified lines
30143014 return -EBADF;
30153015
30163016 dst = fdget(range->dst_fd);
3017− if (!dst.file)
3017+ if (!fd_file(dst))
30183018 return -EBADF;
30193019
3020− if (!(dst.file->f_mode & FMODE_WRITE)) {
3020+ if (!(fd_file(dst)->f_mode & FMODE_WRITE)) {
30213021 err = -EBADF;
30223022 goto err_out;
30233023 }
@@ -3026,7 +3026,7 @@ static int __f2fs_ioc_move_range(struct file *filp, · 2 unmodified lines
30263026 if (err)
30273027 goto err_out;
30283028
3029− err = f2fs_move_file_range(filp, range->pos_in, dst.file,
3029+ err = f2fs_move_file_range(filp, range->pos_in, fd_file(dst),
30303030 range->pos_out, range->len);
30313031
30323032 mnt_drop_write_file(filp);
fs/fcntl.c+19−19
@@ -405,7 +405,7 @@ static long f_dupfd_query(int fd, struct file *filp) · 404 unmodified lines
405405 * overkill, but given our lockless file pointer lookup, the
406406 * alternatives are complicated.
407407 */
408− return f.file == filp;
408+ return fd_file(f) == filp;
409409 }
410410
411411 /* Let the caller figure out whether a given file was just created. */
@@ -573,17 +573,17 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) · 161 unmodified lines
573573 struct fd f = fdget_raw(fd);
574574 long err = -EBADF;
575575
576− if (!f.file)
576+ if (!fd_file(f))
577577 goto out;
578578
579− if (unlikely(f.file->f_mode & FMODE_PATH)) {
579+ if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
580580 if (!check_fcntl_cmd(cmd))
581581 goto out1;
582582 }
583583
584− err = security_file_fcntl(f.file, cmd, arg);
584+ err = security_file_fcntl(fd_file(f), cmd, arg);
585585 if (!err)
586− err = do_fcntl(fd, cmd, arg, f.file);
586+ err = do_fcntl(fd, cmd, arg, fd_file(f));
587587
588588 out1:
589589 fdput(f);
@@ -600,15 +600,15 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, · 10 unmodified lines
600600 struct flock64 flock;
601601 long err = -EBADF;
602602
603− if (!f.file)
603+ if (!fd_file(f))
604604 goto out;
605605
606− if (unlikely(f.file->f_mode & FMODE_PATH)) {
606+ if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
607607 if (!check_fcntl_cmd(cmd))
608608 goto out1;
609609 }
610610
611− err = security_file_fcntl(f.file, cmd, arg);
611+ err = security_file_fcntl(fd_file(f), cmd, arg);
612612 if (err)
613613 goto out1;
614614
@@ -618,7 +618,7 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, · 3 unmodified lines
618618 err = -EFAULT;
619619 if (copy_from_user(&flock, argp, sizeof(flock)))
620620 break;
621− err = fcntl_getlk64(f.file, cmd, &flock);
621+ err = fcntl_getlk64(fd_file(f), cmd, &flock);
622622 if (!err && copy_to_user(argp, &flock, sizeof(flock)))
623623 err = -EFAULT;
624624 break;
@@ -629,10 +629,10 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, · 4 unmodified lines
629629 err = -EFAULT;
630630 if (copy_from_user(&flock, argp, sizeof(flock)))
631631 break;
632− err = fcntl_setlk64(fd, f.file, cmd, &flock);
632+ err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
633633 break;
634634 default:
635− err = do_fcntl(fd, cmd, arg, f.file);
635+ err = do_fcntl(fd, cmd, arg, fd_file(f));
636636 break;
637637 }
638638 out1:
@@ -737,15 +737,15 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 98 unmodified lines
737737 struct flock flock;
738738 long err = -EBADF;
739739
740− if (!f.file)
740+ if (!fd_file(f))
741741 return err;
742742
743− if (unlikely(f.file->f_mode & FMODE_PATH)) {
743+ if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
744744 if (!check_fcntl_cmd(cmd))
745745 goto out_put;
746746 }
747747
748− err = security_file_fcntl(f.file, cmd, arg);
748+ err = security_file_fcntl(fd_file(f), cmd, arg);
749749 if (err)
750750 goto out_put;
751751
@@ -754,7 +754,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 2 unmodified lines
754754 err = get_compat_flock(&flock, compat_ptr(arg));
755755 if (err)
756756 break;
757− err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock);
757+ err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock);
758758 if (err)
759759 break;
760760 err = fixup_compat_flock(&flock);
@@ -766,7 +766,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 5 unmodified lines
766766 err = get_compat_flock64(&flock, compat_ptr(arg));
767767 if (err)
768768 break;
769− err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock);
769+ err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock);
770770 if (!err)
771771 err = put_compat_flock64(&flock, compat_ptr(arg));
772772 break;
@@ -775,7 +775,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 2 unmodified lines
775775 err = get_compat_flock(&flock, compat_ptr(arg));
776776 if (err)
777777 break;
778− err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock);
778+ err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock);
779779 break;
780780 case F_SETLK64:
781781 case F_SETLKW64:
@@ -784,10 +784,10 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 2 unmodified lines
784784 err = get_compat_flock64(&flock, compat_ptr(arg));
785785 if (err)
786786 break;
787− err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock);
787+ err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock);
788788 break;
789789 default:
790− err = do_fcntl(fd, cmd, arg, f.file);
790+ err = do_fcntl(fd, cmd, arg, fd_file(f));
791791 break;
792792 }
793793 out_put:
fs/fhandle.c+2−2
@@ -140,9 +140,9 @@ static int get_path_from_fd(int fd, struct path *root) · 139 unmodified lines
140140 spin_unlock(&fs->lock);
141141 } else {
142142 struct fd f = fdget(fd);
143− if (!f.file)
143+ if (!fd_file(f))
144144 return -EBADF;
145− *root = f.file->f_path;
145+ *root = fd_file(f)->f_path;
146146 path_get(root);
147147 fdput(f);
148148 }
fs/file.c+13−13
@@ -1124,7 +1124,7 @@ EXPORT_SYMBOL(task_lookup_next_fdget_rcu); · 1123 unmodified lines
11241124 * The fput_needed flag returned by fget_light should be passed to the
11251125 * corresponding fput_light.
11261126 */
1127−static unsigned long __fget_light(unsigned int fd, fmode_t mask)
1127+static inline struct fd __fget_light(unsigned int fd, fmode_t mask)
11281128 {
11291129 struct files_struct *files = current->files;
11301130 struct file *file;
@@ -1141,22 +1141,22 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask) · 10 unmodified lines
11411141 if (likely(atomic_read_acquire(&files->count) == 1)) {
11421142 file = files_lookup_fd_raw(files, fd);
11431143 if (!file || unlikely(file->f_mode & mask))
1144− return 0;
1145− return (unsigned long)file;
1144+ return EMPTY_FD;
1145+ return BORROWED_FD(file);
11461146 } else {
11471147 file = __fget_files(files, fd, mask);
11481148 if (!file)
1149− return 0;
1150− return FDPUT_FPUT | (unsigned long)file;
1149+ return EMPTY_FD;
1150+ return CLONED_FD(file);
11511151 }
11521152 }
1153−unsigned long __fdget(unsigned int fd)
1153+struct fd fdget(unsigned int fd)
11541154 {
11551155 return __fget_light(fd, FMODE_PATH);
11561156 }
1157−EXPORT_SYMBOL(__fdget);
1157+EXPORT_SYMBOL(fdget);
11581158
1159−unsigned long __fdget_raw(unsigned int fd)
1159+struct fd fdget_raw(unsigned int fd)
11601160 {
11611161 return __fget_light(fd, 0);
11621162 }
@@ -1177,16 +1177,16 @@ static inline bool file_needs_f_pos_lock(struct file *file) · 14 unmodified lines
11771177 (file_count(file) > 1 || file->f_op->iterate_shared);
11781178 }
11791179
1180−unsigned long __fdget_pos(unsigned int fd)
1180+struct fd fdget_pos(unsigned int fd)
11811181 {
1182− unsigned long v = __fdget(fd);
1183− struct file *file = (struct file *)(v & ~3);
1182+ struct fd f = fdget(fd);
1183+ struct file *file = fd_file(f);
11841184
11851185 if (file && file_needs_f_pos_lock(file)) {
1186− v |= FDPUT_POS_UNLOCK;
1186+ f.word |= FDPUT_POS_UNLOCK;
11871187 mutex_lock(&file->f_pos_lock);
11881188 }
1189− return v;
1189+ return f;
11901190 }
11911191
11921192 void __f_unlock_pos(struct file *f)
fs/fsopen.c+3−3
@@ -394,13 +394,13 @@ SYSCALL_DEFINE5(fsconfig, · 393 unmodified lines
394394 }
395395
396396 f = fdget(fd);
397− if (!f.file)
397+ if (!fd_file(f))
398398 return -EBADF;
399399 ret = -EINVAL;
400− if (f.file->f_op != &fscontext_fops)
400+ if (fd_file(f)->f_op != &fscontext_fops)
401401 goto out_f;
402402
403− fc = f.file->private_data;
403+ fc = fd_file(f)->private_data;
404404 if (fc->ops == &legacy_fs_context_ops) {
405405 switch (cmd) {
406406 case FSCONFIG_SET_BINARY:
fs/fuse/dev.c+3−3
@@ -2329,15 +2329,15 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp) · 2328 unmodified lines
23292329 return -EFAULT;
23302330
23312331 f = fdget(oldfd);
2332− if (!f.file)
2332+ if (!fd_file(f))
23332333 return -EINVAL;
23342334
23352335 /*
23362336 * Check against file->f_op because CUSE
23372337 * uses the same ioctl handler.
23382338 */
2339− if (f.file->f_op == file->f_op)
2340− fud = fuse_get_dev(f.file);
2339+ if (fd_file(f)->f_op == file->f_op)
2340+ fud = fuse_get_dev(fd_file(f));
23412341
23422342 res = -EINVAL;
23432343 if (fud) {
fs/ioctl.c+15−15
@@ -235,9 +235,9 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd, · 234 unmodified lines
235235 loff_t cloned;
236236 int ret;
237237
238− if (!src_file.file)
238+ if (!fd_file(src_file))
239239 return -EBADF;
240− cloned = vfs_clone_file_range(src_file.file, off, dst_file, destoff,
240+ cloned = vfs_clone_file_range(fd_file(src_file), off, dst_file, destoff,
241241 olen, 0);
242242 if (cloned < 0)
243243 ret = cloned;
@@ -895,16 +895,16 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) · 651 unmodified lines
895895 struct fd f = fdget(fd);
896896 int error;
897897
898− if (!f.file)
898+ if (!fd_file(f))
899899 return -EBADF;
900900
901− error = security_file_ioctl(f.file, cmd, arg);
901+ error = security_file_ioctl(fd_file(f), cmd, arg);
902902 if (error)
903903 goto out;
904904
905− error = do_vfs_ioctl(f.file, fd, cmd, arg);
905+ error = do_vfs_ioctl(fd_file(f), fd, cmd, arg);
906906 if (error == -ENOIOCTLCMD)
907− error = vfs_ioctl(f.file, cmd, arg);
907+ error = vfs_ioctl(fd_file(f), cmd, arg);
908908
909909 out:
910910 fdput(f);
@@ -953,32 +953,32 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, · 42 unmodified lines
953953 struct fd f = fdget(fd);
954954 int error;
955955
956− if (!f.file)
956+ if (!fd_file(f))
957957 return -EBADF;
958958
959− error = security_file_ioctl_compat(f.file, cmd, arg);
959+ error = security_file_ioctl_compat(fd_file(f), cmd, arg);
960960 if (error)
961961 goto out;
962962
963963 switch (cmd) {
964964 /* FICLONE takes an int argument, so don't use compat_ptr() */
965965 case FICLONE:
966− error = ioctl_file_clone(f.file, arg, 0, 0, 0);
966+ error = ioctl_file_clone(fd_file(f), arg, 0, 0, 0);
967967 break;
968968
969969 #if defined(CONFIG_X86_64)
970970 /* these get messy on amd64 due to alignment differences */
971971 case FS_IOC_RESVSP_32:
972972 case FS_IOC_RESVSP64_32:
973− error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg));
973+ error = compat_ioctl_preallocate(fd_file(f), 0, compat_ptr(arg));
974974 break;
975975 case FS_IOC_UNRESVSP_32:
976976 case FS_IOC_UNRESVSP64_32:
977− error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE,
977+ error = compat_ioctl_preallocate(fd_file(f), FALLOC_FL_PUNCH_HOLE,
978978 compat_ptr(arg));
979979 break;
980980 case FS_IOC_ZERO_RANGE_32:
981− error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE,
981+ error = compat_ioctl_preallocate(fd_file(f), FALLOC_FL_ZERO_RANGE,
982982 compat_ptr(arg));
983983 break;
984984 #endif
@@ -998,13 +998,13 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, · 13 unmodified lines
998998 * argument.
999999 */
10001000 default:
1001− error = do_vfs_ioctl(f.file, fd, cmd,
1001+ error = do_vfs_ioctl(fd_file(f), fd, cmd,
10021002 (unsigned long)compat_ptr(arg));
10031003 if (error != -ENOIOCTLCMD)
10041004 break;
10051005
1006− if (f.file->f_op->compat_ioctl)
1007− error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
1006+ if (fd_file(f)->f_op->compat_ioctl)
1007+ error = fd_file(f)->f_op->compat_ioctl(fd_file(f), cmd, arg);
10081008 if (error == -ENOIOCTLCMD)
10091009 error = -ENOTTY;
10101010 break;
fs/kernel_read_file.c+2−2
@@ -178,10 +178,10 @@ ssize_t kernel_read_file_from_fd(int fd, loff_t offset, void **buf, · 177 unmodified lines
178178 struct fd f = fdget(fd);
179179 ssize_t ret = -EBADF;
180180
181− if (!f.file || !(f.file->f_mode & FMODE_READ))
181+ if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
182182 goto out;
183183
184− ret = kernel_read_file(f.file, offset, buf, buf_size, file_size, id);
184+ ret = kernel_read_file(fd_file(f), offset, buf, buf_size, file_size, id);
185185 out:
186186 fdput(f);
187187 return ret;
fs/locks.c+7−7
@@ -2157,15 +2157,15 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) · 2156 unmodified lines
21572157
21582158 error = -EBADF;
21592159 f = fdget(fd);
2160− if (!f.file)
2160+ if (!fd_file(f))
21612161 return error;
21622162
2163− if (type != F_UNLCK && !(f.file->f_mode & (FMODE_READ | FMODE_WRITE)))
2163+ if (type != F_UNLCK && !(fd_file(f)->f_mode & (FMODE_READ | FMODE_WRITE)))
21642164 goto out_putf;
21652165
2166− flock_make_lock(f.file, &fl, type);
2166+ flock_make_lock(fd_file(f), &fl, type);
21672167
2168− error = security_file_lock(f.file, fl.c.flc_type);
2168+ error = security_file_lock(fd_file(f), fl.c.flc_type);
21692169 if (error)
21702170 goto out_putf;
21712171
@@ -2173,12 +2173,12 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) · 1 unmodified line
21732173 if (can_sleep)
21742174 fl.c.flc_flags |= FL_SLEEP;
21752175
2176− if (f.file->f_op->flock)
2177− error = f.file->f_op->flock(f.file,
2176+ if (fd_file(f)->f_op->flock)
2177+ error = fd_file(f)->f_op->flock(fd_file(f),
21782178 (can_sleep) ? F_SETLKW : F_SETLK,
21792179 &fl);
21802180 else
2181− error = locks_lock_file_wait(f.file, &fl);
2181+ error = locks_lock_file_wait(fd_file(f), &fl);
21822182
21832183 locks_release_private(&fl);
21842184 out_putf:
fs/namei.c+5−5
@@ -2506,25 +2506,25 @@ static const char *path_init(struct nameidata *nd, unsigned flags) · 2505 unmodified lines
25062506 struct fd f = fdget_raw(nd->dfd);
25072507 struct dentry *dentry;
25082508
2509− if (!f.file)
2509+ if (!fd_file(f))
25102510 return ERR_PTR(-EBADF);
25112511
25122512 if (flags & LOOKUP_LINKAT_EMPTY) {
2513− if (f.file->f_cred != current_cred() &&
2514− !ns_capable(f.file->f_cred->user_ns, CAP_DAC_READ_SEARCH)) {
2513+ if (fd_file(f)->f_cred != current_cred() &&
2514+ !ns_capable(fd_file(f)->f_cred->user_ns, CAP_DAC_READ_SEARCH)) {
25152515 fdput(f);
25162516 return ERR_PTR(-ENOENT);
25172517 }
25182518 }
25192519
2520− dentry = f.file->f_path.dentry;
2520+ dentry = fd_file(f)->f_path.dentry;
25212521
25222522 if (*s && unlikely(!d_can_lookup(dentry))) {
25232523 fdput(f);
25242524 return ERR_PTR(-ENOTDIR);
25252525 }
25262526
2527− nd->path = f.file->f_path;
2527+ nd->path = fd_file(f)->f_path;
25282528 if (flags & LOOKUP_RCU) {
25292529 nd->inode = nd->path.dentry->d_inode;
25302530 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
fs/namespace.c+9−9
@@ -4134,14 +4134,14 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags, · 4133 unmodified lines
41344134 }
41354135
41364136 f = fdget(fs_fd);
4137− if (!f.file)
4137+ if (!fd_file(f))
41384138 return -EBADF;
41394139
41404140 ret = -EINVAL;
4141− if (f.file->f_op != &fscontext_fops)
4141+ if (fd_file(f)->f_op != &fscontext_fops)
41424142 goto err_fsfd;
41434143
4144− fc = f.file->private_data;
4144+ fc = fd_file(f)->private_data;
41454145
41464146 ret = mutex_lock_interruptible(&fc->uapi_mutex);
41474147 if (ret < 0)
@@ -4684,15 +4684,15 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize, · 536 unmodified lines
46844684 return -EINVAL;
46854685
46864686 f = fdget(attr->userns_fd);
4687− if (!f.file)
4687+ if (!fd_file(f))
46884688 return -EBADF;
46894689
4690− if (!proc_ns_file(f.file)) {
4690+ if (!proc_ns_file(fd_file(f))) {
46914691 err = -EINVAL;
46924692 goto out_fput;
46934693 }
46944694
4695− ns = get_proc_ns(file_inode(f.file));
4695+ ns = get_proc_ns(file_inode(fd_file(f)));
46964696 if (ns->ops->type != CLONE_NEWUSER) {
46974697 err = -EINVAL;
46984698 goto out_fput;
@@ -5292,13 +5292,13 @@ static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq · 593 unmodified lines
52925292 struct ns_common *ns;
52935293
52945294 CLASS(fd, f)(kreq->spare);
5295− if (!f.file)
5295+ if (fd_empty(f))
52965296 return ERR_PTR(-EBADF);
52975297
5298− if (!proc_ns_file(f.file))
5298+ if (!proc_ns_file(fd_file(f)))
52995299 return ERR_PTR(-EINVAL);
53005300
5301− ns = get_proc_ns(file_inode(f.file));
5301+ ns = get_proc_ns(file_inode(fd_file(f)));
53025302 if (ns->ops->type != CLONE_NEWNS)
53035303 return ERR_PTR(-EINVAL);
53045304
fs/notify/fanotify/fanotify_user.c+6−6
@@ -1006,17 +1006,17 @@ static int fanotify_find_path(int dfd, const char __user *filename, · 1005 unmodified lines
10061006 struct fd f = fdget(dfd);
10071007
10081008 ret = -EBADF;
1009− if (!f.file)
1009+ if (!fd_file(f))
10101010 goto out;
10111011
10121012 ret = -ENOTDIR;
10131013 if ((flags & FAN_MARK_ONLYDIR) &&
1014− !(S_ISDIR(file_inode(f.file)->i_mode))) {
1014+ !(S_ISDIR(file_inode(fd_file(f))->i_mode))) {
10151015 fdput(f);
10161016 goto out;
10171017 }
10181018
1019− *path = f.file->f_path;
1019+ *path = fd_file(f)->f_path;
10201020 path_get(path);
10211021 fdput(f);
10221022 } else {
@@ -1753,14 +1753,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, · 730 unmodified lines
17531753 }
17541754
17551755 f = fdget(fanotify_fd);
1756− if (unlikely(!f.file))
1756+ if (unlikely(!fd_file(f)))
17571757 return -EBADF;
17581758
17591759 /* verify that this is indeed an fanotify instance */
17601760 ret = -EINVAL;
1761− if (unlikely(f.file->f_op != &fanotify_fops))
1761+ if (unlikely(fd_file(f)->f_op != &fanotify_fops))
17621762 goto fput_and_out;
1763− group = f.file->private_data;
1763+ group = fd_file(f)->private_data;
17641764
17651765 /*
17661766 * An unprivileged user is not allowed to setup mount nor filesystem
fs/notify/inotify/inotify_user.c+6−6
@@ -753,7 +753,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname, · 752 unmodified lines
753753 return -EINVAL;
754754
755755 f = fdget(fd);
756− if (unlikely(!f.file))
756+ if (unlikely(!fd_file(f)))
757757 return -EBADF;
758758
759759 /* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */
@@ -763,7 +763,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname, · 3 unmodified lines
763763 }
764764
765765 /* verify that this is indeed an inotify instance */
766− if (unlikely(f.file->f_op != &inotify_fops)) {
766+ if (unlikely(fd_file(f)->f_op != &inotify_fops)) {
767767 ret = -EINVAL;
768768 goto fput_and_out;
769769 }
@@ -780,7 +780,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname, · 10 unmodified lines
780780
781781 /* inode held in place by reference to path; group by fget on fd */
782782 inode = path.dentry->d_inode;
783− group = f.file->private_data;
783+ group = fd_file(f)->private_data;
784784
785785 /* create/update an inode mark */
786786 ret = inotify_update_watch(group, inode, mask);
@@ -798,14 +798,14 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd) · 11 unmodified lines
798798 int ret = -EINVAL;
799799
800800 f = fdget(fd);
801− if (unlikely(!f.file))
801+ if (unlikely(!fd_file(f)))
802802 return -EBADF;
803803
804804 /* verify that this is indeed an inotify instance */
805− if (unlikely(f.file->f_op != &inotify_fops))
805+ if (unlikely(fd_file(f)->f_op != &inotify_fops))
806806 goto out;
807807
808− group = f.file->private_data;
808+ group = fd_file(f)->private_data;
809809
810810 i_mark = inotify_idr_find(group, wd);
811811 if (unlikely(!i_mark))
fs/ocfs2/cluster/heartbeat.c+3−3
@@ -1785,17 +1785,17 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, · 1784 unmodified lines
17851785 goto out;
17861786
17871787 f = fdget(fd);
1788− if (f.file == NULL)
1788+ if (fd_file(f) == NULL)
17891789 goto out;
17901790
17911791 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||
17921792 reg->hr_block_bytes == 0)
17931793 goto out2;
17941794
1795− if (!S_ISBLK(f.file->f_mapping->host->i_mode))
1795+ if (!S_ISBLK(fd_file(f)->f_mapping->host->i_mode))
17961796 goto out2;
17971797
1798− reg->hr_bdev_file = bdev_file_open_by_dev(f.file->f_mapping->host->i_rdev,
1798+ reg->hr_bdev_file = bdev_file_open_by_dev(fd_file(f)->f_mapping->host->i_rdev,
17991799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);
18001800 if (IS_ERR(reg->hr_bdev_file)) {
18011801 ret = PTR_ERR(reg->hr_bdev_file);
fs/open.c+12−12
@@ -193,10 +193,10 @@ long do_sys_ftruncate(unsigned int fd, loff_t length, int small) · 192 unmodified lines
193193 if (length < 0)
194194 return -EINVAL;
195195 f = fdget(fd);
196− if (!f.file)
196+ if (!fd_file(f))
197197 return -EBADF;
198198
199− error = do_ftruncate(f.file, length, small);
199+ error = do_ftruncate(fd_file(f), length, small);
200200
201201 fdput(f);
202202 return error;
@@ -352,8 +352,8 @@ int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len) · 149 unmodified lines
352352 struct fd f = fdget(fd);
353353 int error = -EBADF;
354354
355− if (f.file) {
356− error = vfs_fallocate(f.file, mode, offset, len);
355+ if (fd_file(f)) {
356+ error = vfs_fallocate(fd_file(f), mode, offset, len);
357357 fdput(f);
358358 }
359359 return error;
@@ -584,16 +584,16 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd) · 224 unmodified lines
584584 int error;
585585
586586 error = -EBADF;
587− if (!f.file)
587+ if (!fd_file(f))
588588 goto out;
589589
590590 error = -ENOTDIR;
591− if (!d_can_lookup(f.file->f_path.dentry))
591+ if (!d_can_lookup(fd_file(f)->f_path.dentry))
592592 goto out_putf;
593593
594− error = file_permission(f.file, MAY_EXEC | MAY_CHDIR);
594+ error = file_permission(fd_file(f), MAY_EXEC | MAY_CHDIR);
595595 if (!error)
596− set_fs_pwd(current->fs, &f.file->f_path);
596+ set_fs_pwd(current->fs, &fd_file(f)->f_path);
597597 out_putf:
598598 fdput(f);
599599 out:
@@ -674,8 +674,8 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode) · 74 unmodified lines
674674 struct fd f = fdget(fd);
675675 int err = -EBADF;
676676
677− if (f.file) {
678− err = vfs_fchmod(f.file, mode);
677+ if (fd_file(f)) {
678+ err = vfs_fchmod(fd_file(f), mode);
679679 fdput(f);
680680 }
681681 return err;
@@ -868,8 +868,8 @@ int ksys_fchown(unsigned int fd, uid_t user, gid_t group) · 186 unmodified lines
868868 struct fd f = fdget(fd);
869869 int error = -EBADF;
870870
871− if (f.file) {
872− error = vfs_fchown(f.file, user, group);
871+ if (fd_file(f)) {
872+ error = vfs_fchown(fd_file(f), user, group);
873873 fdput(f);
874874 }
875875 return error;
fs/overlayfs/file.c+35−33
@@ -93,11 +93,11 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, · 92 unmodified lines
9393 bool allow_meta)
9494 {
9595 struct dentry *dentry = file_dentry(file);
96+ struct file *realfile = file->private_data;
9697 struct path realpath;
9798 int err;
9899
99− real->flags = 0;
100− real->file = file->private_data;
100+ real->word = (unsigned long)realfile;
101101
102102 if (allow_meta) {
103103 ovl_path_real(dentry, &realpath);
@@ -113,16 +113,17 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, · 9 unmodified lines
113113 return -EIO;
114114
115115 /* Has it been copied up since we'd opened it? */
116− if (unlikely(file_inode(real->file) != d_inode(realpath.dentry))) {
117− real->flags = FDPUT_FPUT;
118− real->file = ovl_open_realfile(file, &realpath);
119−
120− return PTR_ERR_OR_ZERO(real->file);
116+ if (unlikely(file_inode(realfile) != d_inode(realpath.dentry))) {
117+ struct file *f = ovl_open_realfile(file, &realpath);
118+ if (IS_ERR(f))
119+ return PTR_ERR(f);
120+ real->word = (unsigned long)ovl_open_realfile(file, &realpath) | FDPUT_FPUT;
121+ return 0;
121122 }
122123
123124 /* Did the flags change since open? */
124− if (unlikely((file->f_flags ^ real->file->f_flags) & ~OVL_OPEN_FLAGS))
125− return ovl_change_flags(real->file, file->f_flags);
125+ if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS))
126+ return ovl_change_flags(realfile, file->f_flags);
126127
127128 return 0;
128129 }
@@ -130,10 +131,11 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, · 1 unmodified line
130131 static int ovl_real_fdget(const struct file *file, struct fd *real)
131132 {
132133 if (d_is_dir(file_dentry(file))) {
133− real->flags = 0;
134− real->file = ovl_dir_real_file(file, false);
135−
136− return PTR_ERR_OR_ZERO(real->file);
134+ struct file *f = ovl_dir_real_file(file, false);
135+ if (IS_ERR(f))
136+ return PTR_ERR(f);
137+ real->word = (unsigned long)f;
138+ return 0;
137139 }
138140
139141 return ovl_real_fdget_meta(file, real, false);
@@ -209,13 +211,13 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence) · 69 unmodified lines
209211 * files, so we use the real file to perform seeks.
210212 */
211213 ovl_inode_lock(inode);
212− real.file->f_pos = file->f_pos;
214+ fd_file(real)->f_pos = file->f_pos;
213215
214216 old_cred = ovl_override_creds(inode->i_sb);
215− ret = vfs_llseek(real.file, offset, whence);
217+ ret = vfs_llseek(fd_file(real), offset, whence);
216218 revert_creds(old_cred);
217219
218− file->f_pos = real.file->f_pos;
220+ file->f_pos = fd_file(real)->f_pos;
219221 ovl_inode_unlock(inode);
220222
221223 fdput(real);
@@ -275,7 +277,7 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) · 53 unmodified lines
275277 if (ret)
276278 return ret;
277279
278− ret = backing_file_read_iter(real.file, iter, iocb, iocb->ki_flags,
280+ ret = backing_file_read_iter(fd_file(real), iter, iocb, iocb->ki_flags,
279281 &ctx);
280282 fdput(real);
281283
@@ -314,7 +316,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) · 32 unmodified lines
314316 * this property in case it is set by the issuer.
315317 */
316318 ifl &= ~IOCB_DIO_CALLER_COMP;
317− ret = backing_file_write_iter(real.file, iter, iocb, ifl, &ctx);
319+ ret = backing_file_write_iter(fd_file(real), iter, iocb, ifl, &ctx);
318320 fdput(real);
319321
320322 out_unlock:
@@ -339,7 +341,7 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, · 18 unmodified lines
339341 if (ret)
340342 return ret;
341343
342− ret = backing_file_splice_read(real.file, ppos, pipe, len, flags, &ctx);
344+ ret = backing_file_splice_read(fd_file(real), ppos, pipe, len, flags, &ctx);
343345 fdput(real);
344346
345347 return ret;
@@ -348,7 +350,7 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, · 2 unmodified lines
348350 /*
349351 * Calling iter_file_splice_write() directly from overlay's f_op may deadlock
350352 * due to lock order inversion between pipe->mutex in iter_file_splice_write()
351− * and file_start_write(real.file) in ovl_write_iter().
353+ * and file_start_write(fd_file(real)) in ovl_write_iter().
352354 *
353355 * So do everything ovl_write_iter() does and call iter_file_splice_write() on
354356 * the real file.
@@ -373,7 +375,7 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, · 18 unmodified lines
373375 if (ret)
374376 goto out_unlock;
375377
376− ret = backing_file_splice_write(pipe, real.file, ppos, len, flags, &ctx);
378+ ret = backing_file_splice_write(pipe, fd_file(real), ppos, len, flags, &ctx);
377379 fdput(real);
378380
379381 out_unlock:
@@ -397,9 +399,9 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) · 17 unmodified lines
397399 return ret;
398400
399401 /* Don't sync lower file for fear of receiving EROFS error */
400− if (file_inode(real.file) == ovl_inode_upper(file_inode(file))) {
402+ if (file_inode(fd_file(real)) == ovl_inode_upper(file_inode(file))) {
401403 old_cred = ovl_override_creds(file_inode(file)->i_sb);
402− ret = vfs_fsync_range(real.file, start, end, datasync);
404+ ret = vfs_fsync_range(fd_file(real), start, end, datasync);
403405 revert_creds(old_cred);
404406 }
405407
@@ -439,7 +441,7 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len · 33 unmodified lines
439441 goto out_unlock;
440442
441443 old_cred = ovl_override_creds(file_inode(file)->i_sb);
442− ret = vfs_fallocate(real.file, mode, offset, len);
444+ ret = vfs_fallocate(fd_file(real), mode, offset, len);
443445 revert_creds(old_cred);
444446
445447 /* Update size */
@@ -464,7 +466,7 @@ static int ovl_fadvise(struct file *file, loff_t offset, loff_t len, int advice) · 18 unmodified lines
464466 return ret;
465467
466468 old_cred = ovl_override_creds(file_inode(file)->i_sb);
467− ret = vfs_fadvise(real.file, offset, len, advice);
469+ ret = vfs_fadvise(fd_file(real), offset, len, advice);
468470 revert_creds(old_cred);
469471
470472 fdput(real);
@@ -509,18 +511,18 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, · 38 unmodified lines
509511 old_cred = ovl_override_creds(file_inode(file_out)->i_sb);
510512 switch (op) {
511513 case OVL_COPY:
512− ret = vfs_copy_file_range(real_in.file, pos_in,
513− real_out.file, pos_out, len, flags);
514+ ret = vfs_copy_file_range(fd_file(real_in), pos_in,
515+ fd_file(real_out), pos_out, len, flags);
514516 break;
515517
516518 case OVL_CLONE:
517− ret = vfs_clone_file_range(real_in.file, pos_in,
518− real_out.file, pos_out, len, flags);
519+ ret = vfs_clone_file_range(fd_file(real_in), pos_in,
520+ fd_file(real_out), pos_out, len, flags);
519521 break;
520522
521523 case OVL_DEDUPE:
522− ret = vfs_dedupe_file_range_one(real_in.file, pos_in,
523− real_out.file, pos_out, len,
524+ ret = vfs_dedupe_file_range_one(fd_file(real_in), pos_in,
525+ fd_file(real_out), pos_out, len,
524526 flags);
525527 break;
526528 }
@@ -583,9 +585,9 @@ static int ovl_flush(struct file *file, fl_owner_t id) · 56 unmodified lines
583585 if (err)
584586 return err;
585587
586− if (real.file->f_op->flush) {
588+ if (fd_file(real)->f_op->flush) {
587589 old_cred = ovl_override_creds(file_inode(file)->i_sb);
588− err = real.file->f_op->flush(real.file, id);
590+ err = fd_file(real)->f_op->flush(fd_file(real), id);
589591 revert_creds(old_cred);
590592 }
591593 fdput(real);
fs/quota/quota.c+4−4
@@ -980,7 +980,7 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd, · 979 unmodified lines
980980 int ret;
981981
982982 f = fdget_raw(fd);
983− if (!f.file)
983+ if (!fd_file(f))
984984 return -EBADF;
985985
986986 ret = -EINVAL;
@@ -988,12 +988,12 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd, · 1 unmodified line
988988 goto out;
989989
990990 if (quotactl_cmd_write(cmds)) {
991− ret = mnt_want_write(f.file->f_path.mnt);
991+ ret = mnt_want_write(fd_file(f)->f_path.mnt);
992992 if (ret)
993993 goto out;
994994 }
995995
996− sb = f.file->f_path.mnt->mnt_sb;
996+ sb = fd_file(f)->f_path.mnt->mnt_sb;
997997 if (quotactl_cmd_onoff(cmds))
998998 down_write(&sb->s_umount);
999999 else
@@ -1007,7 +1007,7 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd, · 7 unmodified lines
10071007 up_read(&sb->s_umount);
10081008
10091009 if (quotactl_cmd_write(cmds))
1010− mnt_drop_write(f.file->f_path.mnt);
1010+ mnt_drop_write(fd_file(f)->f_path.mnt);
10111011 out:
10121012 fdput(f);
10131013 return ret;
fs/read_write.c+59−59
@@ -387,12 +387,12 @@ static off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence) · 386 unmodified lines
387387 {
388388 off_t retval;
389389 struct fd f = fdget_pos(fd);
390− if (!f.file)
390+ if (!fd_file(f))
391391 return -EBADF;
392392
393393 retval = -EINVAL;
394394 if (whence <= SEEK_MAX) {
395− loff_t res = vfs_llseek(f.file, offset, whence);
395+ loff_t res = vfs_llseek(fd_file(f), offset, whence);
396396 retval = res;
397397 if (res != (loff_t)retval)
398398 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
@@ -423,14 +423,14 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high, · 24 unmodified lines
423423 struct fd f = fdget_pos(fd);
424424 loff_t offset;
425425
426− if (!f.file)
426+ if (!fd_file(f))
427427 return -EBADF;
428428
429429 retval = -EINVAL;
430430 if (whence > SEEK_MAX)
431431 goto out_putf;
432432
433− offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,
433+ offset = vfs_llseek(fd_file(f), ((loff_t) offset_high << 32) | offset_low,
434434 whence);
435435
436436 retval = (int)offset;
@@ -703,15 +703,15 @@ ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count) · 266 unmodified lines
703703 struct fd f = fdget_pos(fd);
704704 ssize_t ret = -EBADF;
705705
706− if (f.file) {
707− loff_t pos, *ppos = file_ppos(f.file);
706+ if (fd_file(f)) {
707+ loff_t pos, *ppos = file_ppos(fd_file(f));
708708 if (ppos) {
709709 pos = *ppos;
710710 ppos = &pos;
711711 }
712− ret = vfs_read(f.file, buf, count, ppos);
712+ ret = vfs_read(fd_file(f), buf, count, ppos);
713713 if (ret >= 0 && ppos)
714− f.file->f_pos = pos;
714+ fd_file(f)->f_pos = pos;
715715 fdput_pos(f);
716716 }
717717 return ret;
@@ -727,15 +727,15 @@ ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count) · 9 unmodified lines
727727 struct fd f = fdget_pos(fd);
728728 ssize_t ret = -EBADF;
729729
730− if (f.file) {
731− loff_t pos, *ppos = file_ppos(f.file);
730+ if (fd_file(f)) {
731+ loff_t pos, *ppos = file_ppos(fd_file(f));
732732 if (ppos) {
733733 pos = *ppos;
734734 ppos = &pos;
735735 }
736− ret = vfs_write(f.file, buf, count, ppos);
736+ ret = vfs_write(fd_file(f), buf, count, ppos);
737737 if (ret >= 0 && ppos)
738− f.file->f_pos = pos;
738+ fd_file(f)->f_pos = pos;
739739 fdput_pos(f);
740740 }
741741
@@ -758,10 +758,10 @@ ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count, · 16 unmodified lines
758758 return -EINVAL;
759759
760760 f = fdget(fd);
761− if (f.file) {
761+ if (fd_file(f)) {
762762 ret = -ESPIPE;
763− if (f.file->f_mode & FMODE_PREAD)
764− ret = vfs_read(f.file, buf, count, &pos);
763+ if (fd_file(f)->f_mode & FMODE_PREAD)
764+ ret = vfs_read(fd_file(f), buf, count, &pos);
765765 fdput(f);
766766 }
767767
@@ -792,10 +792,10 @@ ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf, · 24 unmodified lines
792792 return -EINVAL;
793793
794794 f = fdget(fd);
795− if (f.file) {
795+ if (fd_file(f)) {
796796 ret = -ESPIPE;
797− if (f.file->f_mode & FMODE_PWRITE)
798− ret = vfs_write(f.file, buf, count, &pos);
797+ if (fd_file(f)->f_mode & FMODE_PWRITE)
798+ ret = vfs_write(fd_file(f), buf, count, &pos);
799799 fdput(f);
800800 }
801801
@@ -1078,15 +1078,15 @@ static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec, · 276 unmodified lines
10781078 struct fd f = fdget_pos(fd);
10791079 ssize_t ret = -EBADF;
10801080
1081− if (f.file) {
1082− loff_t pos, *ppos = file_ppos(f.file);
1081+ if (fd_file(f)) {
1082+ loff_t pos, *ppos = file_ppos(fd_file(f));
10831083 if (ppos) {
10841084 pos = *ppos;
10851085 ppos = &pos;
10861086 }
1087− ret = vfs_readv(f.file, vec, vlen, ppos, flags);
1087+ ret = vfs_readv(fd_file(f), vec, vlen, ppos, flags);
10881088 if (ret >= 0 && ppos)
1089− f.file->f_pos = pos;
1089+ fd_file(f)->f_pos = pos;
10901090 fdput_pos(f);
10911091 }
10921092
@@ -1102,15 +1102,15 @@ static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec, · 9 unmodified lines
11021102 struct fd f = fdget_pos(fd);
11031103 ssize_t ret = -EBADF;
11041104
1105− if (f.file) {
1106− loff_t pos, *ppos = file_ppos(f.file);
1105+ if (fd_file(f)) {
1106+ loff_t pos, *ppos = file_ppos(fd_file(f));
11071107 if (ppos) {
11081108 pos = *ppos;
11091109 ppos = &pos;
11101110 }
1111− ret = vfs_writev(f.file, vec, vlen, ppos, flags);
1111+ ret = vfs_writev(fd_file(f), vec, vlen, ppos, flags);
11121112 if (ret >= 0 && ppos)
1113− f.file->f_pos = pos;
1113+ fd_file(f)->f_pos = pos;
11141114 fdput_pos(f);
11151115 }
11161116
@@ -1136,10 +1136,10 @@ static ssize_t do_preadv(unsigned long fd, const struct iovec __user *vec, · 19 unmodified lines
11361136 return -EINVAL;
11371137
11381138 f = fdget(fd);
1139− if (f.file) {
1139+ if (fd_file(f)) {
11401140 ret = -ESPIPE;
1141− if (f.file->f_mode & FMODE_PREAD)
1142− ret = vfs_readv(f.file, vec, vlen, &pos, flags);
1141+ if (fd_file(f)->f_mode & FMODE_PREAD)
1142+ ret = vfs_readv(fd_file(f), vec, vlen, &pos, flags);
11431143 fdput(f);
11441144 }
11451145
@@ -1159,10 +1159,10 @@ static ssize_t do_pwritev(unsigned long fd, const struct iovec __user *vec, · 13 unmodified lines
11591159 return -EINVAL;
11601160
11611161 f = fdget(fd);
1162− if (f.file) {
1162+ if (fd_file(f)) {
11631163 ret = -ESPIPE;
1164− if (f.file->f_mode & FMODE_PWRITE)
1165− ret = vfs_writev(f.file, vec, vlen, &pos, flags);
1164+ if (fd_file(f)->f_mode & FMODE_PWRITE)
1165+ ret = vfs_writev(fd_file(f), vec, vlen, &pos, flags);
11661166 fdput(f);
11671167 }
11681168
@@ -1328,19 +1328,19 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, · 159 unmodified lines
13281328 */
13291329 retval = -EBADF;
13301330 in = fdget(in_fd);
1331− if (!in.file)
1331+ if (!fd_file(in))
13321332 goto out;
1333− if (!(in.file->f_mode & FMODE_READ))
1333+ if (!(fd_file(in)->f_mode & FMODE_READ))
13341334 goto fput_in;
13351335 retval = -ESPIPE;
13361336 if (!ppos) {
1337− pos = in.file->f_pos;
1337+ pos = fd_file(in)->f_pos;
13381338 } else {
13391339 pos = *ppos;
1340− if (!(in.file->f_mode & FMODE_PREAD))
1340+ if (!(fd_file(in)->f_mode & FMODE_PREAD))
13411341 goto fput_in;
13421342 }
1343− retval = rw_verify_area(READ, in.file, &pos, count);
1343+ retval = rw_verify_area(READ, fd_file(in), &pos, count);
13441344 if (retval < 0)
13451345 goto fput_in;
13461346 if (count > MAX_RW_COUNT)
@@ -1351,13 +1351,13 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, · 4 unmodified lines
13511351 */
13521352 retval = -EBADF;
13531353 out = fdget(out_fd);
1354− if (!out.file)
1354+ if (!fd_file(out))
13551355 goto fput_in;
1356− if (!(out.file->f_mode & FMODE_WRITE))
1356+ if (!(fd_file(out)->f_mode & FMODE_WRITE))
13571357 goto fput_out;
1358− in_inode = file_inode(in.file);
1359− out_inode = file_inode(out.file);
1360− out_pos = out.file->f_pos;
1358+ in_inode = file_inode(fd_file(in));
1359+ out_inode = file_inode(fd_file(out));
1360+ out_pos = fd_file(out)->f_pos;
13611361
13621362 if (!max)
13631363 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
@@ -1377,33 +1377,33 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, · 13 unmodified lines
13771377 * and the application is arguably buggy if it doesn't expect
13781378 * EAGAIN on a non-blocking file descriptor.
13791379 */
1380− if (in.file->f_flags & O_NONBLOCK)
1380+ if (fd_file(in)->f_flags & O_NONBLOCK)
13811381 fl = SPLICE_F_NONBLOCK;
13821382 #endif
1383− opipe = get_pipe_info(out.file, true);
1383+ opipe = get_pipe_info(fd_file(out), true);
13841384 if (!opipe) {
1385− retval = rw_verify_area(WRITE, out.file, &out_pos, count);
1385+ retval = rw_verify_area(WRITE, fd_file(out), &out_pos, count);
13861386 if (retval < 0)
13871387 goto fput_out;
1388− retval = do_splice_direct(in.file, &pos, out.file, &out_pos,
1388+ retval = do_splice_direct(fd_file(in), &pos, fd_file(out), &out_pos,
13891389 count, fl);
13901390 } else {
1391− if (out.file->f_flags & O_NONBLOCK)
1391+ if (fd_file(out)->f_flags & O_NONBLOCK)
13921392 fl |= SPLICE_F_NONBLOCK;
13931393
1394− retval = splice_file_to_pipe(in.file, opipe, &pos, count, fl);
1394+ retval = splice_file_to_pipe(fd_file(in), opipe, &pos, count, fl);
13951395 }
13961396
13971397 if (retval > 0) {
13981398 add_rchar(current, retval);
13991399 add_wchar(current, retval);
1400− fsnotify_access(in.file);
1401− fsnotify_modify(out.file);
1402− out.file->f_pos = out_pos;
1400+ fsnotify_access(fd_file(in));
1401+ fsnotify_modify(fd_file(out));
1402+ fd_file(out)->f_pos = out_pos;
14031403 if (ppos)
14041404 *ppos = pos;
14051405 else
1406− in.file->f_pos = pos;
1406+ fd_file(in)->f_pos = pos;
14071407 }
14081408
14091409 inc_syscr(current);
@@ -1676,11 +1676,11 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, · 266 unmodified lines
16761676 ssize_t ret = -EBADF;
16771677
16781678 f_in = fdget(fd_in);
1679− if (!f_in.file)
1679+ if (!fd_file(f_in))
16801680 goto out2;
16811681
16821682 f_out = fdget(fd_out);
1683− if (!f_out.file)
1683+ if (!fd_file(f_out))
16841684 goto out1;
16851685
16861686 ret = -EFAULT;
@@ -1688,21 +1688,21 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, · 1 unmodified line
16881688 if (copy_from_user(&pos_in, off_in, sizeof(loff_t)))
16891689 goto out;
16901690 } else {
1691− pos_in = f_in.file->f_pos;
1691+ pos_in = fd_file(f_in)->f_pos;
16921692 }
16931693
16941694 if (off_out) {
16951695 if (copy_from_user(&pos_out, off_out, sizeof(loff_t)))
16961696 goto out;
16971697 } else {
1698− pos_out = f_out.file->f_pos;
1698+ pos_out = fd_file(f_out)->f_pos;
16991699 }
17001700
17011701 ret = -EINVAL;
17021702 if (flags != 0)
17031703 goto out;
17041704
1705− ret = vfs_copy_file_range(f_in.file, pos_in, f_out.file, pos_out, len,
1705+ ret = vfs_copy_file_range(fd_file(f_in), pos_in, fd_file(f_out), pos_out, len,
17061706 flags);
17071707 if (ret > 0) {
17081708 pos_in += ret;
@@ -1712,14 +1712,14 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, · 3 unmodified lines
17121712 if (copy_to_user(off_in, &pos_in, sizeof(loff_t)))
17131713 ret = -EFAULT;
17141714 } else {
1715− f_in.file->f_pos = pos_in;
1715+ fd_file(f_in)->f_pos = pos_in;
17161716 }
17171717
17181718 if (off_out) {
17191719 if (copy_to_user(off_out, &pos_out, sizeof(loff_t)))
17201720 ret = -EFAULT;
17211721 } else {
1722− f_out.file->f_pos = pos_out;
1722+ fd_file(f_out)->f_pos = pos_out;
17231723 }
17241724 }
17251725
fs/readdir.c+10−10
@@ -225,10 +225,10 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd, · 224 unmodified lines
225225 .dirent = dirent
226226 };
227227
228− if (!f.file)
228+ if (!fd_file(f))
229229 return -EBADF;
230230
231− error = iterate_dir(f.file, &buf.ctx);
231+ error = iterate_dir(fd_file(f), &buf.ctx);
232232 if (buf.result)
233233 error = buf.result;
234234
@@ -318,10 +318,10 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd, · 83 unmodified lines
318318 int error;
319319
320320 f = fdget_pos(fd);
321− if (!f.file)
321+ if (!fd_file(f))
322322 return -EBADF;
323323
324− error = iterate_dir(f.file, &buf.ctx);
324+ error = iterate_dir(fd_file(f), &buf.ctx);
325325 if (error >= 0)
326326 error = buf.error;
327327 if (buf.prev_reclen) {
@@ -401,10 +401,10 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, · 73 unmodified lines
401401 int error;
402402
403403 f = fdget_pos(fd);
404− if (!f.file)
404+ if (!fd_file(f))
405405 return -EBADF;
406406
407− error = iterate_dir(f.file, &buf.ctx);
407+ error = iterate_dir(fd_file(f), &buf.ctx);
408408 if (error >= 0)
409409 error = buf.error;
410410 if (buf.prev_reclen) {
@@ -483,10 +483,10 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd, · 72 unmodified lines
483483 .dirent = dirent
484484 };
485485
486− if (!f.file)
486+ if (!fd_file(f))
487487 return -EBADF;
488488
489− error = iterate_dir(f.file, &buf.ctx);
489+ error = iterate_dir(fd_file(f), &buf.ctx);
490490 if (buf.result)
491491 error = buf.result;
492492
@@ -569,10 +569,10 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd, · 76 unmodified lines
569569 int error;
570570
571571 f = fdget_pos(fd);
572− if (!f.file)
572+ if (!fd_file(f))
573573 return -EBADF;
574574
575− error = iterate_dir(f.file, &buf.ctx);
575+ error = iterate_dir(fd_file(f), &buf.ctx);
576576 if (error >= 0)
577577 error = buf.error;
578578 if (buf.prev_reclen) {
fs/remap_range.c+1−1
@@ -537,7 +537,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) · 536 unmodified lines
537537
538538 for (i = 0, info = same->info; i < count; i++, info++) {
539539 struct fd dst_fd = fdget(info->dest_fd);
540− struct file *dst_file = dst_fd.file;
540+ struct file *dst_file = fd_file(dst_fd);
541541
542542 if (!dst_file) {
543543 info->status = -EBADF;
fs/select.c+4−4
@@ -529,10 +529,10 @@ static noinline_for_stack int do_select(int n, fd_set_bits *fds, struct timespec · 528 unmodified lines
529529 continue;
530530 mask = EPOLLNVAL;
531531 f = fdget(i);
532− if (f.file) {
532+ if (fd_file(f)) {
533533 wait_key_set(wait, in, out, bit,
534534 busy_flag);
535− mask = vfs_poll(f.file, wait);
535+ mask = vfs_poll(fd_file(f), wait);
536536
537537 fdput(f);
538538 }
@@ -863,13 +863,13 @@ static inline __poll_t do_pollfd(struct pollfd *pollfd, poll_table *pwait, · 324 unmodified lines
863863 goto out;
864864 mask = EPOLLNVAL;
865865 f = fdget(fd);
866− if (!f.file)
866+ if (!fd_file(f))
867867 goto out;
868868
869869 /* userland u16 ->events contains POLL... bitmap */
870870 filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP;
871871 pwait->_key = filter | busy_flag;
872− mask = vfs_poll(f.file, pwait);
872+ mask = vfs_poll(fd_file(f), pwait);
873873 if (mask & busy_flag)
874874 *can_busy_poll = true;
875875 mask &= filter; /* Mask out unneeded events. */
fs/signalfd.c+3−3
@@ -289,10 +289,10 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags) · 288 unmodified lines
289289 fd_install(ufd, file);
290290 } else {
291291 struct fd f = fdget(ufd);
292− if (!f.file)
292+ if (!fd_file(f))
293293 return -EBADF;
294− ctx = f.file->private_data;
295− if (f.file->f_op != &signalfd_fops) {
294+ ctx = fd_file(f)->private_data;
295+ if (fd_file(f)->f_op != &signalfd_fops) {
296296 fdput(f);
297297 return -EINVAL;
298298 }
fs/smb/client/ioctl.c+4−4
@@ -90,23 +90,23 @@ static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file, · 89 unmodified lines
9090 }
9191
9292 src_file = fdget(srcfd);
93− if (!src_file.file) {
93+ if (!fd_file(src_file)) {
9494 rc = -EBADF;
9595 goto out_drop_write;
9696 }
9797
98− if (src_file.file->f_op->unlocked_ioctl != cifs_ioctl) {
98+ if (fd_file(src_file)->f_op->unlocked_ioctl != cifs_ioctl) {
9999 rc = -EBADF;
100100 cifs_dbg(VFS, "src file seems to be from a different filesystem type\n");
101101 goto out_fput;
102102 }
103103
104− src_inode = file_inode(src_file.file);
104+ src_inode = file_inode(fd_file(src_file));
105105 rc = -EINVAL;
106106 if (S_ISDIR(src_inode->i_mode))
107107 goto out_fput;
108108
109− rc = cifs_file_copychunk_range(xid, src_file.file, 0, dst_file, 0,
109+ rc = cifs_file_copychunk_range(xid, fd_file(src_file), 0, dst_file, 0,
110110 src_inode->i_size, 0);
111111 if (rc > 0)
112112 rc = 0;
fs/splice.c+11−11
@@ -1566,11 +1566,11 @@ static ssize_t vmsplice_to_pipe(struct file *file, struct iov_iter *iter, · 1565 unmodified lines
15661566
15671567 static int vmsplice_type(struct fd f, int *type)
15681568 {
1569− if (!f.file)
1569+ if (!fd_file(f))
15701570 return -EBADF;
1571− if (f.file->f_mode & FMODE_WRITE) {
1571+ if (fd_file(f)->f_mode & FMODE_WRITE) {
15721572 *type = ITER_SOURCE;
1573− } else if (f.file->f_mode & FMODE_READ) {
1573+ } else if (fd_file(f)->f_mode & FMODE_READ) {
15741574 *type = ITER_DEST;
15751575 } else {
15761576 fdput(f);
@@ -1621,9 +1621,9 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov, · 44 unmodified lines
16211621 if (!iov_iter_count(&iter))
16221622 error = 0;
16231623 else if (type == ITER_SOURCE)
1624− error = vmsplice_to_pipe(f.file, &iter, flags);
1624+ error = vmsplice_to_pipe(fd_file(f), &iter, flags);
16251625 else
1626− error = vmsplice_to_user(f.file, &iter, flags);
1626+ error = vmsplice_to_user(fd_file(f), &iter, flags);
16271627
16281628 kfree(iov);
16291629 out_fdput:
@@ -1646,10 +1646,10 @@ SYSCALL_DEFINE6(splice, int, fd_in, loff_t __user *, off_in, · 16 unmodified lines
16461646
16471647 error = -EBADF;
16481648 in = fdget(fd_in);
1649− if (in.file) {
1649+ if (fd_file(in)) {
16501650 out = fdget(fd_out);
1651− if (out.file) {
1652− error = __do_splice(in.file, off_in, out.file, off_out,
1651+ if (fd_file(out)) {
1652+ error = __do_splice(fd_file(in), off_in, fd_file(out), off_out,
16531653 len, flags);
16541654 fdput(out);
16551655 }
@@ -2016,10 +2016,10 @@ SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags) · 360 unmodified lines
20162016
20172017 error = -EBADF;
20182018 in = fdget(fdin);
2019− if (in.file) {
2019+ if (fd_file(in)) {
20202020 out = fdget(fdout);
2021− if (out.file) {
2022− error = do_tee(in.file, out.file, len, flags);
2021+ if (fd_file(out)) {
2022+ error = do_tee(fd_file(in), fd_file(out), len, flags);
20232023 fdput(out);
20242024 }
20252025 fdput(in);
fs/stat.c+4−4
@@ -224,9 +224,9 @@ int vfs_fstat(int fd, struct kstat *stat) · 223 unmodified lines
224224 int error;
225225
226226 f = fdget_raw(fd);
227− if (!f.file)
227+ if (!fd_file(f))
228228 return -EBADF;
229− error = vfs_getattr(&f.file->f_path, stat, STATX_BASIC_STATS, 0);
229+ error = vfs_getattr(&fd_file(f)->f_path, stat, STATX_BASIC_STATS, 0);
230230 fdput(f);
231231 return error;
232232 }
@@ -277,9 +277,9 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat, · 44 unmodified lines
277277 u32 request_mask)
278278 {
279279 CLASS(fd_raw, f)(fd);
280− if (!f.file)
280+ if (!fd_file(f))
281281 return -EBADF;
282− return vfs_statx_path(&f.file->f_path, flags, stat, request_mask);
282+ return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask);
283283 }
284284
285285 /**
fs/statfs.c+2−2
@@ -116,8 +116,8 @@ int fd_statfs(int fd, struct kstatfs *st) · 115 unmodified lines
116116 {
117117 struct fd f = fdget_raw(fd);
118118 int error = -EBADF;
119− if (f.file) {
120− error = vfs_statfs(&f.file->f_path, st);
119+ if (fd_file(f)) {
120+ error = vfs_statfs(&fd_file(f)->f_path, st);
121121 fdput(f);
122122 }
123123 return error;
fs/sync.c+7−7
@@ -152,15 +152,15 @@ SYSCALL_DEFINE1(syncfs, int, fd) · 151 unmodified lines
152152 struct super_block *sb;
153153 int ret, ret2;
154154
155− if (!f.file)
155+ if (!fd_file(f))
156156 return -EBADF;
157− sb = f.file->f_path.dentry->d_sb;
157+ sb = fd_file(f)->f_path.dentry->d_sb;
158158
159159 down_read(&sb->s_umount);
160160 ret = sync_filesystem(sb);
161161 up_read(&sb->s_umount);
162162
163− ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);
163+ ret2 = errseq_check_and_advance(&sb->s_wb_err, &fd_file(f)->f_sb_err);
164164
165165 fdput(f);
166166 return ret ? ret : ret2;
@@ -208,8 +208,8 @@ static int do_fsync(unsigned int fd, int datasync) · 41 unmodified lines
208208 struct fd f = fdget(fd);
209209 int ret = -EBADF;
210210
211− if (f.file) {
212− ret = vfs_fsync(f.file, datasync);
211+ if (fd_file(f)) {
212+ ret = vfs_fsync(fd_file(f), datasync);
213213 fdput(f);
214214 }
215215 return ret;
@@ -360,8 +360,8 @@ int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes, · 144 unmodified lines
360360
361361 ret = -EBADF;
362362 f = fdget(fd);
363− if (f.file)
364− ret = sync_file_range(f.file, offset, nbytes, flags);
363+ if (fd_file(f))
364+ ret = sync_file_range(fd_file(f), offset, nbytes, flags);
365365
366366 fdput(f);
367367 return ret;
fs/timerfd.c+4−4
@@ -397,9 +397,9 @@ static const struct file_operations timerfd_fops = { · 396 unmodified lines
397397 static int timerfd_fget(int fd, struct fd *p)
398398 {
399399 struct fd f = fdget(fd);
400− if (!f.file)
400+ if (!fd_file(f))
401401 return -EBADF;
402− if (f.file->f_op != &timerfd_fops) {
402+ if (fd_file(f)->f_op != &timerfd_fops) {
403403 fdput(f);
404404 return -EINVAL;
405405 }
@@ -482,7 +482,7 @@ static int do_timerfd_settime(int ufd, int flags, · 76 unmodified lines
482482 ret = timerfd_fget(ufd, &f);
483483 if (ret)
484484 return ret;
485− ctx = f.file->private_data;
485+ ctx = fd_file(f)->private_data;
486486
487487 if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) {
488488 fdput(f);
@@ -546,7 +546,7 @@ static int do_timerfd_gettime(int ufd, struct itimerspec64 *t) · 57 unmodified lines
546546 int ret = timerfd_fget(ufd, &f);
547547 if (ret)
548548 return ret;
549− ctx = f.file->private_data;
549+ ctx = fd_file(f)->private_data;
550550
551551 spin_lock_irq(&ctx->wqh.lock);
552552 if (ctx->expired && ctx->tintv) {
fs/utimes.c+2−2
@@ -115,9 +115,9 @@ static int do_utimes_fd(int fd, struct timespec64 *times, int flags) · 114 unmodified lines
115115 return -EINVAL;
116116
117117 f = fdget(fd);
118− if (!f.file)
118+ if (!fd_file(f))
119119 return -EBADF;
120− error = vfs_utimes(&f.file->f_path, times);
120+ error = vfs_utimes(&fd_file(f)->f_path, times);
121121 fdput(f);
122122 return error;
123123 }
fs/xattr.c+18−18
@@ -697,19 +697,19 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name, · 696 unmodified lines
697697 int error;
698698
699699 CLASS(fd, f)(fd);
700− if (!f.file)
700+ if (!fd_file(f))
701701 return -EBADF;
702702
703− audit_file(f.file);
703+ audit_file(fd_file(f));
704704 error = setxattr_copy(name, &ctx);
705705 if (error)
706706 return error;
707707
708− error = mnt_want_write_file(f.file);
708+ error = mnt_want_write_file(fd_file(f));
709709 if (!error) {
710− error = do_setxattr(file_mnt_idmap(f.file),
711− f.file->f_path.dentry, &ctx);
712− mnt_drop_write_file(f.file);
710+ error = do_setxattr(file_mnt_idmap(fd_file(f)),
711+ fd_file(f)->f_path.dentry, &ctx);
712+ mnt_drop_write_file(fd_file(f));
713713 }
714714 kvfree(ctx.kvalue);
715715 return error;
@@ -812,10 +812,10 @@ SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, · 96 unmodified lines
812812 struct fd f = fdget(fd);
813813 ssize_t error = -EBADF;
814814
815− if (!f.file)
815+ if (!fd_file(f))
816816 return error;
817− audit_file(f.file);
818− error = getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry,
817+ audit_file(fd_file(f));
818+ error = getxattr(file_mnt_idmap(fd_file(f)), fd_file(f)->f_path.dentry,
819819 name, value, size);
820820 fdput(f);
821821 return error;
@@ -888,10 +888,10 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size) · 66 unmodified lines
888888 struct fd f = fdget(fd);
889889 ssize_t error = -EBADF;
890890
891− if (!f.file)
891+ if (!fd_file(f))
892892 return error;
893− audit_file(f.file);
894− error = listxattr(f.file->f_path.dentry, list, size);
893+ audit_file(fd_file(f));
894+ error = listxattr(fd_file(f)->f_path.dentry, list, size);
895895 fdput(f);
896896 return error;
897897 }
@@ -954,9 +954,9 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) · 56 unmodified lines
954954 char kname[XATTR_NAME_MAX + 1];
955955 int error = -EBADF;
956956
957− if (!f.file)
957+ if (!fd_file(f))
958958 return error;
959− audit_file(f.file);
959+ audit_file(fd_file(f));
960960
961961 error = strncpy_from_user(kname, name, sizeof(kname));
962962 if (error == 0 || error == sizeof(kname))
@@ -964,11 +964,11 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) · 1 unmodified line
964964 if (error < 0)
965965 return error;
966966
967− error = mnt_want_write_file(f.file);
967+ error = mnt_want_write_file(fd_file(f));
968968 if (!error) {
969− error = removexattr(file_mnt_idmap(f.file),
970− f.file->f_path.dentry, kname);
971− mnt_drop_write_file(f.file);
969+ error = removexattr(file_mnt_idmap(fd_file(f)),
970+ fd_file(f)->f_path.dentry, kname);
971+ mnt_drop_write_file(fd_file(f));
972972 }
973973 fdput(f);
974974 return error;
fs/xfs/xfs_exchrange.c+4−4
@@ -829,9 +829,9 @@ xfs_ioc_exchange_range( · 828 unmodified lines
829829 fxr.flags = args.flags;
830830
831831 file1 = fdget(args.file1_fd);
832− if (!file1.file)
832+ if (!fd_file(file1))
833833 return -EBADF;
834− fxr.file1 = file1.file;
834+ fxr.file1 = fd_file(file1);
835835
836836 error = xfs_exchange_range(&fxr);
837837 fdput(file1);
@@ -935,9 +935,9 @@ xfs_ioc_commit_range( · 97 unmodified lines
935935 fxr.file2_ctime.tv_nsec = kern_f->file2_ctime_nsec;
936936
937937 file1 = fdget(args.file1_fd);
938− if (!file1.file)
938+ if (fd_empty(file1))
939939 return -EBADF;
940− fxr.file1 = file1.file;
940+ fxr.file1 = fd_file(file1);
941941
942942 error = xfs_exchange_range(&fxr);
943943 fdput(file1);
fs/xfs/xfs_handle.c+3−3
@@ -85,16 +85,16 @@ xfs_find_handle( · 84 unmodified lines
8585 int hsize;
8686 xfs_handle_t handle;
8787 struct inode *inode;
88− struct fd f = {NULL};
88+ struct fd f = EMPTY_FD;
8989 struct path path;
9090 int error;
9191 struct xfs_inode *ip;
9292
9393 if (cmd == XFS_IOC_FD_TO_HANDLE) {
9494 f = fdget(hreq->fd);
95− if (!f.file)
95+ if (!fd_file(f))
9696 return -EBADF;
97− inode = file_inode(f.file);
97+ inode = file_inode(fd_file(f));
9898 } else {
9999 error = user_path_at(AT_FDCWD, hreq->path, 0, &path);
100100 if (error)
fs/xfs/xfs_ioctl.c+14−14
@@ -886,33 +886,33 @@ xfs_ioc_swapext( · 885 unmodified lines
886886
887887 /* Pull information for the target fd */
888888 f = fdget((int)sxp->sx_fdtarget);
889− if (!f.file) {
889+ if (!fd_file(f)) {
890890 error = -EINVAL;
891891 goto out;
892892 }
893893
894− if (!(f.file->f_mode & FMODE_WRITE) ||
895− !(f.file->f_mode & FMODE_READ) ||
896− (f.file->f_flags & O_APPEND)) {
894+ if (!(fd_file(f)->f_mode & FMODE_WRITE) ||
895+ !(fd_file(f)->f_mode & FMODE_READ) ||
896+ (fd_file(f)->f_flags & O_APPEND)) {
897897 error = -EBADF;
898898 goto out_put_file;
899899 }
900900
901901 tmp = fdget((int)sxp->sx_fdtmp);
902− if (!tmp.file) {
902+ if (!fd_file(tmp)) {
903903 error = -EINVAL;
904904 goto out_put_file;
905905 }
906906
907− if (!(tmp.file->f_mode & FMODE_WRITE) ||
908− !(tmp.file->f_mode & FMODE_READ) ||
909− (tmp.file->f_flags & O_APPEND)) {
907+ if (!(fd_file(tmp)->f_mode & FMODE_WRITE) ||
908+ !(fd_file(tmp)->f_mode & FMODE_READ) ||
909+ (fd_file(tmp)->f_flags & O_APPEND)) {
910910 error = -EBADF;
911911 goto out_put_tmp_file;
912912 }
913913
914− if (IS_SWAPFILE(file_inode(f.file)) ||
915− IS_SWAPFILE(file_inode(tmp.file))) {
914+ if (IS_SWAPFILE(file_inode(fd_file(f))) ||
915+ IS_SWAPFILE(file_inode(fd_file(tmp)))) {
916916 error = -EINVAL;
917917 goto out_put_tmp_file;
918918 }
@@ -922,14 +922,14 @@ xfs_ioc_swapext( · 3 unmodified lines
922922 * before we cast and access them as XFS structures as we have no
923923 * control over what the user passes us here.
924924 */
925− if (f.file->f_op != &xfs_file_operations ||
926− tmp.file->f_op != &xfs_file_operations) {
925+ if (fd_file(f)->f_op != &xfs_file_operations ||
926+ fd_file(tmp)->f_op != &xfs_file_operations) {
927927 error = -EINVAL;
928928 goto out_put_tmp_file;
929929 }
930930
931− ip = XFS_I(file_inode(f.file));
932− tip = XFS_I(file_inode(tmp.file));
931+ ip = XFS_I(file_inode(fd_file(f)));
932+ tip = XFS_I(file_inode(fd_file(tmp)));
933933
934934 if (ip->i_mount != tip->i_mount) {
935935 error = -EINVAL;
include/linux/cleanup.h+1−1
@@ -98,7 +98,7 @@ const volatile void * __must_check_fn(const volatile void *val) · 97 unmodified lines
9898 * DEFINE_CLASS(fdget, struct fd, fdput(_T), fdget(fd), int fd)
9999 *
100100 * CLASS(fdget, f)(fd);
101− * if (!f.file)
101+ * if (!fd_file(f))
102102 * return -EBADF;
103103 *
104104 * // use 'f' without concern
include/linux/file.h+27−26
@@ -36,51 +36,52 @@ static inline void fput_light(struct file *file, int fput_needed) · 35 unmodified lines
3636 fput(file);
3737 }
3838
39+/* either a reference to struct file + flags
40+ * (cloned vs. borrowed, pos locked), with
41+ * flags stored in lower bits of value,
42+ * or empty (represented by 0).
43+ */
3944 struct fd {
40− struct file *file;
41− unsigned int flags;
45+ unsigned long word;
4246 };
4347 #define FDPUT_FPUT 1
4448 #define FDPUT_POS_UNLOCK 2
4549
46−static inline void fdput(struct fd fd)
50+#define fd_file(f) ((struct file *)((f).word & ~(FDPUT_FPUT|FDPUT_POS_UNLOCK)))
51+static inline bool fd_empty(struct fd f)
4752 {
48− if (fd.flags & FDPUT_FPUT)
49− fput(fd.file);
53+ return unlikely(!f.word);
5054 }
5155
52−extern struct file *fget(unsigned int fd);
53−extern struct file *fget_raw(unsigned int fd);
54−extern struct file *fget_task(struct task_struct *task, unsigned int fd);
55−extern unsigned long __fdget(unsigned int fd);
56−extern unsigned long __fdget_raw(unsigned int fd);
57−extern unsigned long __fdget_pos(unsigned int fd);
58−extern void __f_unlock_pos(struct file *);
59−
60−static inline struct fd __to_fd(unsigned long v)
56+#define EMPTY_FD (struct fd){0}
57+static inline struct fd BORROWED_FD(struct file *f)
6158 {
62− return (struct fd){(struct file *)(v & ~3),v & 3};
59+ return (struct fd){(unsigned long)f};
6360 }
64−
65−static inline struct fd fdget(unsigned int fd)
61+static inline struct fd CLONED_FD(struct file *f)
6662 {
67− return __to_fd(__fdget(fd));
63+ return (struct fd){(unsigned long)f | FDPUT_FPUT};
6864 }
6965
70−static inline struct fd fdget_raw(unsigned int fd)
66+static inline void fdput(struct fd fd)
7167 {
72− return __to_fd(__fdget_raw(fd));
68+ if (fd.word & FDPUT_FPUT)
69+ fput(fd_file(fd));
7370 }
7471
75−static inline struct fd fdget_pos(int fd)
76−{
77− return __to_fd(__fdget_pos(fd));
78−}
72+extern struct file *fget(unsigned int fd);
73+extern struct file *fget_raw(unsigned int fd);
74+extern struct file *fget_task(struct task_struct *task, unsigned int fd);
75+extern void __f_unlock_pos(struct file *);
76+
77+struct fd fdget(unsigned int fd);
78+struct fd fdget_raw(unsigned int fd);
79+struct fd fdget_pos(unsigned int fd);
7980
8081 static inline void fdput_pos(struct fd f)
8182 {
82− if (f.flags & FDPUT_POS_UNLOCK)
83− __f_unlock_pos(f.file);
83+ if (f.word & FDPUT_POS_UNLOCK)
84+ __f_unlock_pos(fd_file(f));
8485 fdput(f);
8586 }
8687
io_uring/sqpoll.c+5−5
@@ -109,14 +109,14 @@ static struct io_sq_data *io_attach_sq_data(struct io_uring_params *p) · 108 unmodified lines
109109 struct fd f;
110110
111111 f = fdget(p->wq_fd);
112− if (!f.file)
112+ if (!fd_file(f))
113113 return ERR_PTR(-ENXIO);
114− if (!io_is_uring_fops(f.file)) {
114+ if (!io_is_uring_fops(fd_file(f))) {
115115 fdput(f);
116116 return ERR_PTR(-EINVAL);
117117 }
118118
119− ctx_attach = f.file->private_data;
119+ ctx_attach = fd_file(f)->private_data;
120120 sqd = ctx_attach->sq_data;
121121 if (!sqd) {
122122 fdput(f);
@@ -419,9 +419,9 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx, · 296 unmodified lines
419419 struct fd f;
420420
421421 f = fdget(p->wq_fd);
422− if (!f.file)
422+ if (!fd_file(f))
423423 return -ENXIO;
424− if (!io_is_uring_fops(f.file)) {
424+ if (!io_is_uring_fops(fd_file(f))) {
425425 fdput(f);
426426 return -EINVAL;
427427 }
ipc/mqueue.c+25−25
@@ -1085,20 +1085,20 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr, · 1084 unmodified lines
10851085 audit_mq_sendrecv(mqdes, msg_len, msg_prio, ts);
10861086
10871087 f = fdget(mqdes);
1088− if (unlikely(!f.file)) {
1088+ if (unlikely(!fd_file(f))) {
10891089 ret = -EBADF;
10901090 goto out;
10911091 }
10921092
1093− inode = file_inode(f.file);
1094− if (unlikely(f.file->f_op != &mqueue_file_operations)) {
1093+ inode = file_inode(fd_file(f));
1094+ if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
10951095 ret = -EBADF;
10961096 goto out_fput;
10971097 }
10981098 info = MQUEUE_I(inode);
1099− audit_file(f.file);
1099+ audit_file(fd_file(f));
11001100
1101− if (unlikely(!(f.file->f_mode & FMODE_WRITE))) {
1101+ if (unlikely(!(fd_file(f)->f_mode & FMODE_WRITE))) {
11021102 ret = -EBADF;
11031103 goto out_fput;
11041104 }
@@ -1138,7 +1138,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr, · 33 unmodified lines
11381138 }
11391139
11401140 if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {
1141− if (f.file->f_flags & O_NONBLOCK) {
1141+ if (fd_file(f)->f_flags & O_NONBLOCK) {
11421142 ret = -EAGAIN;
11431143 } else {
11441144 wait.task = current;
@@ -1199,20 +1199,20 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr, · 54 unmodified lines
11991199 audit_mq_sendrecv(mqdes, msg_len, 0, ts);
12001200
12011201 f = fdget(mqdes);
1202− if (unlikely(!f.file)) {
1202+ if (unlikely(!fd_file(f))) {
12031203 ret = -EBADF;
12041204 goto out;
12051205 }
12061206
1207− inode = file_inode(f.file);
1208− if (unlikely(f.file->f_op != &mqueue_file_operations)) {
1207+ inode = file_inode(fd_file(f));
1208+ if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
12091209 ret = -EBADF;
12101210 goto out_fput;
12111211 }
12121212 info = MQUEUE_I(inode);
1213− audit_file(f.file);
1213+ audit_file(fd_file(f));
12141214
1215− if (unlikely(!(f.file->f_mode & FMODE_READ))) {
1215+ if (unlikely(!(fd_file(f)->f_mode & FMODE_READ))) {
12161216 ret = -EBADF;
12171217 goto out_fput;
12181218 }
@@ -1242,7 +1242,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr, · 23 unmodified lines
12421242 }
12431243
12441244 if (info->attr.mq_curmsgs == 0) {
1245− if (f.file->f_flags & O_NONBLOCK) {
1245+ if (fd_file(f)->f_flags & O_NONBLOCK) {
12461246 spin_unlock(&info->lock);
12471247 ret = -EAGAIN;
12481248 } else {
@@ -1356,11 +1356,11 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification) · 107 unmodified lines
13561356 /* and attach it to the socket */
13571357 retry:
13581358 f = fdget(notification->sigev_signo);
1359− if (!f.file) {
1359+ if (!fd_file(f)) {
13601360 ret = -EBADF;
13611361 goto out;
13621362 }
1363− sock = netlink_getsockbyfilp(f.file);
1363+ sock = netlink_getsockbyfilp(fd_file(f));
13641364 fdput(f);
13651365 if (IS_ERR(sock)) {
13661366 ret = PTR_ERR(sock);
@@ -1379,13 +1379,13 @@ retry: · 12 unmodified lines
13791379 }
13801380
13811381 f = fdget(mqdes);
1382− if (!f.file) {
1382+ if (!fd_file(f)) {
13831383 ret = -EBADF;
13841384 goto out;
13851385 }
13861386
1387− inode = file_inode(f.file);
1388− if (unlikely(f.file->f_op != &mqueue_file_operations)) {
1387+ inode = file_inode(fd_file(f));
1388+ if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
13891389 ret = -EBADF;
13901390 goto out_fput;
13911391 }
@@ -1460,31 +1460,31 @@ static int do_mq_getsetattr(int mqdes, struct mq_attr *new, struct mq_attr *old) · 68 unmodified lines
14601460 return -EINVAL;
14611461
14621462 f = fdget(mqdes);
1463− if (!f.file)
1463+ if (!fd_file(f))
14641464 return -EBADF;
14651465
1466− if (unlikely(f.file->f_op != &mqueue_file_operations)) {
1466+ if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
14671467 fdput(f);
14681468 return -EBADF;
14691469 }
14701470
1471− inode = file_inode(f.file);
1471+ inode = file_inode(fd_file(f));
14721472 info = MQUEUE_I(inode);
14731473
14741474 spin_lock(&info->lock);
14751475
14761476 if (old) {
14771477 *old = info->attr;
1478− old->mq_flags = f.file->f_flags & O_NONBLOCK;
1478+ old->mq_flags = fd_file(f)->f_flags & O_NONBLOCK;
14791479 }
14801480 if (new) {
14811481 audit_mq_getsetattr(mqdes, new);
1482− spin_lock(&f.file->f_lock);
1482+ spin_lock(&fd_file(f)->f_lock);
14831483 if (new->mq_flags & O_NONBLOCK)
1484− f.file->f_flags |= O_NONBLOCK;
1484+ fd_file(f)->f_flags |= O_NONBLOCK;
14851485 else
1486− f.file->f_flags &= ~O_NONBLOCK;
1487− spin_unlock(&f.file->f_lock);
1486+ fd_file(f)->f_flags &= ~O_NONBLOCK;
1487+ spin_unlock(&fd_file(f)->f_lock);
14881488
14891489 inode_set_atime_to_ts(inode, inode_set_ctime_current(inode));
14901490 }
kernel/bpf/bpf_inode_storage.c+7−7
@@ -80,10 +80,10 @@ static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key) · 79 unmodified lines
8080 struct bpf_local_storage_data *sdata;
8181 struct fd f = fdget_raw(*(int *)key);
8282
83− if (!f.file)
83+ if (!fd_file(f))
8484 return ERR_PTR(-EBADF);
8585
86− sdata = inode_storage_lookup(file_inode(f.file), map, true);
86+ sdata = inode_storage_lookup(file_inode(fd_file(f)), map, true);
8787 fdput(f);
8888 return sdata ? sdata->data : NULL;
8989 }
@@ -94,14 +94,14 @@ static long bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key, · 4 unmodified lines
9494 struct bpf_local_storage_data *sdata;
9595 struct fd f = fdget_raw(*(int *)key);
9696
97− if (!f.file)
97+ if (!fd_file(f))
9898 return -EBADF;
99− if (!inode_storage_ptr(file_inode(f.file))) {
99+ if (!inode_storage_ptr(file_inode(fd_file(f)))) {
100100 fdput(f);
101101 return -EBADF;
102102 }
103103
104− sdata = bpf_local_storage_update(file_inode(f.file),
104+ sdata = bpf_local_storage_update(file_inode(fd_file(f)),
105105 (struct bpf_local_storage_map *)map,
106106 value, map_flags, GFP_ATOMIC);
107107 fdput(f);
@@ -126,10 +126,10 @@ static long bpf_fd_inode_storage_delete_elem(struct bpf_map *map, void *key) · 18 unmodified lines
126126 struct fd f = fdget_raw(*(int *)key);
127127 int err;
128128
129− if (!f.file)
129+ if (!fd_file(f))
130130 return -EBADF;
131131
132− err = inode_storage_delete(file_inode(f.file), map);
132+ err = inode_storage_delete(file_inode(fd_file(f)), map);
133133 fdput(f);
134134 return err;
135135 }
kernel/bpf/btf.c+3−3
@@ -7715,15 +7715,15 @@ struct btf *btf_get_by_fd(int fd) · 7714 unmodified lines
77157715
77167716 f = fdget(fd);
77177717
7718− if (!f.file)
7718+ if (!fd_file(f))
77197719 return ERR_PTR(-EBADF);
77207720
7721− if (f.file->f_op != &btf_fops) {
7721+ if (fd_file(f)->f_op != &btf_fops) {
77227722 fdput(f);
77237723 return ERR_PTR(-EINVAL);
77247724 }
77257725
7726− btf = f.file->private_data;
7726+ btf = fd_file(f)->private_data;
77277727 refcount_inc(&btf->refcnt);
77287728 fdput(f);
77297729
kernel/bpf/syscall.c+21−21
@@ -837,7 +837,7 @@ static int bpf_map_release(struct inode *inode, struct file *filp) · 836 unmodified lines
837837
838838 static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f)
839839 {
840− fmode_t mode = f.file->f_mode;
840+ fmode_t mode = fd_file(f)->f_mode;
841841
842842 /* Our file permissions may have been overridden by global
843843 * map permissions facing syscall side.
@@ -1430,14 +1430,14 @@ put_token: · 586 unmodified lines
14301430 */
14311431 struct bpf_map *__bpf_map_get(struct fd f)
14321432 {
1433− if (!f.file)
1433+ if (!fd_file(f))
14341434 return ERR_PTR(-EBADF);
1435− if (f.file->f_op != &bpf_map_fops) {
1435+ if (fd_file(f)->f_op != &bpf_map_fops) {
14361436 fdput(f);
14371437 return ERR_PTR(-EINVAL);
14381438 }
14391439
1440− return f.file->private_data;
1440+ return fd_file(f)->private_data;
14411441 }
14421442
14431443 void bpf_map_inc(struct bpf_map *map)
@@ -1658,7 +1658,7 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr) · 214 unmodified lines
16581658 goto free_key;
16591659 }
16601660
1661− err = bpf_map_update_value(map, f.file, key, value, attr->flags);
1661+ err = bpf_map_update_value(map, fd_file(f), key, value, attr->flags);
16621662 if (!err)
16631663 maybe_wait_bpf_programs(map);
16641664
@@ -2416,14 +2416,14 @@ int bpf_prog_new_fd(struct bpf_prog *prog) · 751 unmodified lines
24162416
24172417 static struct bpf_prog *____bpf_prog_get(struct fd f)
24182418 {
2419− if (!f.file)
2419+ if (!fd_file(f))
24202420 return ERR_PTR(-EBADF);
2421− if (f.file->f_op != &bpf_prog_fops) {
2421+ if (fd_file(f)->f_op != &bpf_prog_fops) {
24222422 fdput(f);
24232423 return ERR_PTR(-EINVAL);
24242424 }
24252425
2426− return f.file->private_data;
2426+ return fd_file(f)->private_data;
24272427 }
24282428
24292429 void bpf_prog_add(struct bpf_prog *prog, int i)
@@ -3266,14 +3266,14 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd) · 836 unmodified lines
32663266 struct fd f = fdget(ufd);
32673267 struct bpf_link *link;
32683268
3269− if (!f.file)
3269+ if (!fd_file(f))
32703270 return ERR_PTR(-EBADF);
3271− if (f.file->f_op != &bpf_link_fops && f.file->f_op != &bpf_link_fops_poll) {
3271+ if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll) {
32723272 fdput(f);
32733273 return ERR_PTR(-EINVAL);
32743274 }
32753275
3276− link = f.file->private_data;
3276+ link = fd_file(f)->private_data;
32773277 bpf_link_inc(link);
32783278 fdput(f);
32793279
@@ -4989,19 +4989,19 @@ static int bpf_obj_get_info_by_fd(const union bpf_attr *attr, · 1709 unmodified lines
49894989 return -EINVAL;
49904990
49914991 f = fdget(ufd);
4992− if (!f.file)
4992+ if (!fd_file(f))
49934993 return -EBADFD;
49944994
4995− if (f.file->f_op == &bpf_prog_fops)
4996− err = bpf_prog_get_info_by_fd(f.file, f.file->private_data, attr,
4995+ if (fd_file(f)->f_op == &bpf_prog_fops)
4996+ err = bpf_prog_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
49974997 uattr);
4998− else if (f.file->f_op == &bpf_map_fops)
4999− err = bpf_map_get_info_by_fd(f.file, f.file->private_data, attr,
4998+ else if (fd_file(f)->f_op == &bpf_map_fops)
4999+ err = bpf_map_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
50005000 uattr);
5001− else if (f.file->f_op == &btf_fops)
5002− err = bpf_btf_get_info_by_fd(f.file, f.file->private_data, attr, uattr);
5003− else if (f.file->f_op == &bpf_link_fops || f.file->f_op == &bpf_link_fops_poll)
5004− err = bpf_link_get_info_by_fd(f.file, f.file->private_data,
5001+ else if (fd_file(f)->f_op == &btf_fops)
5002+ err = bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, uattr);
5003+ else if (fd_file(f)->f_op == &bpf_link_fops || fd_file(f)->f_op == &bpf_link_fops_poll)
5004+ err = bpf_link_get_info_by_fd(fd_file(f), fd_file(f)->private_data,
50055005 attr, uattr);
50065006 else
50075007 err = -EINVAL;
@@ -5222,7 +5222,7 @@ static int bpf_map_do_batch(const union bpf_attr *attr, · 214 unmodified lines
52225222 else if (cmd == BPF_MAP_LOOKUP_AND_DELETE_BATCH)
52235223 BPF_DO_BATCH(map->ops->map_lookup_and_delete_batch, map, attr, uattr);
52245224 else if (cmd == BPF_MAP_UPDATE_BATCH)
5225− BPF_DO_BATCH(map->ops->map_update_batch, map, f.file, attr, uattr);
5225+ BPF_DO_BATCH(map->ops->map_update_batch, map, fd_file(f), attr, uattr);
52265226 else
52275227 BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);
52285228 err_put:
kernel/bpf/token.c+5−5
@@ -122,10 +122,10 @@ int bpf_token_create(union bpf_attr *attr) · 121 unmodified lines
122122 int err, fd;
123123
124124 f = fdget(attr->token_create.bpffs_fd);
125− if (!f.file)
125+ if (!fd_file(f))
126126 return -EBADF;
127127
128− path = f.file->f_path;
128+ path = fd_file(f)->f_path;
129129 path_get(&path);
130130 fdput(f);
131131
@@ -235,14 +235,14 @@ struct bpf_token *bpf_token_get_from_fd(u32 ufd) · 103 unmodified lines
235235 struct fd f = fdget(ufd);
236236 struct bpf_token *token;
237237
238− if (!f.file)
238+ if (!fd_file(f))
239239 return ERR_PTR(-EBADF);
240− if (f.file->f_op != &bpf_token_fops) {
240+ if (fd_file(f)->f_op != &bpf_token_fops) {
241241 fdput(f);
242242 return ERR_PTR(-EINVAL);
243243 }
244244
245− token = f.file->private_data;
245+ token = fd_file(f)->private_data;
246246 bpf_token_inc(token);
247247 fdput(f);
248248
kernel/cgroup/cgroup.c+2−2
@@ -6968,10 +6968,10 @@ struct cgroup *cgroup_v1v2_get_from_fd(int fd) · 6967 unmodified lines
69686968 {
69696969 struct cgroup *cgrp;
69706970 struct fd f = fdget_raw(fd);
6971− if (!f.file)
6971+ if (!fd_file(f))
69726972 return ERR_PTR(-EBADF);
69736973
6974− cgrp = cgroup_v1v2_get_from_file(f.file);
6974+ cgrp = cgroup_v1v2_get_from_file(fd_file(f));
69756975 fdput(f);
69766976 return cgrp;
69776977 }
kernel/events/core.c+7−7
@@ -969,10 +969,10 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, · 968 unmodified lines
969969 struct fd f = fdget(fd);
970970 int ret = 0;
971971
972− if (!f.file)
972+ if (!fd_file(f))
973973 return -EBADF;
974974
975− css = css_tryget_online_from_dir(f.file->f_path.dentry,
975+ css = css_tryget_online_from_dir(fd_file(f)->f_path.dentry,
976976 &perf_event_cgrp_subsys);
977977 if (IS_ERR(css)) {
978978 ret = PTR_ERR(css);
@@ -6001,10 +6001,10 @@ static const struct file_operations perf_fops; · 5022 unmodified lines
60016001 static inline int perf_fget_light(int fd, struct fd *p)
60026002 {
60036003 struct fd f = fdget(fd);
6004− if (!f.file)
6004+ if (!fd_file(f))
60056005 return -EBADF;
60066006
6007− if (f.file->f_op != &perf_fops) {
6007+ if (fd_file(f)->f_op != &perf_fops) {
60086008 fdput(f);
60096009 return -EBADF;
60106010 }
@@ -6064,7 +6064,7 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon · 53 unmodified lines
60646064 ret = perf_fget_light(arg, &output);
60656065 if (ret)
60666066 return ret;
6067− output_event = output.file->private_data;
6067+ output_event = fd_file(output)->private_data;
60686068 ret = perf_event_set_output(event, output_event);
60696069 fdput(output);
60706070 } else {
@@ -12665,7 +12665,7 @@ SYSCALL_DEFINE5(perf_event_open, · 6594 unmodified lines
1266512665 struct perf_event_attr attr;
1266612666 struct perf_event_context *ctx;
1266712667 struct file *event_file = NULL;
12668− struct fd group = {NULL, 0};
12668+ struct fd group = EMPTY_FD;
1266912669 struct task_struct *task = NULL;
1267012670 struct pmu *pmu;
1267112671 int event_fd;
@@ -12740,7 +12740,7 @@ SYSCALL_DEFINE5(perf_event_open, · 68 unmodified lines
1274012740 err = perf_fget_light(group_fd, &group);
1274112741 if (err)
1274212742 goto err_fd;
12743− group_leader = group.file->private_data;
12743+ group_leader = fd_file(group)->private_data;
1274412744 if (flags & PERF_FLAG_FD_OUTPUT)
1274512745 output_event = group_leader;
1274612746 if (flags & PERF_FLAG_FD_NO_GROUP)
kernel/module/main.c+1−1
@@ -3234,7 +3234,7 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) · 3233 unmodified lines
32343234 return -EINVAL;
32353235
32363236 f = fdget(fd);
3237− err = idempotent_init_module(f.file, uargs, flags);
3237+ err = idempotent_init_module(fd_file(f), uargs, flags);
32383238 fdput(f);
32393239 return err;
32403240 }
kernel/nsproxy.c+6−6
@@ -550,15 +550,15 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags) · 549 unmodified lines
550550 struct nsset nsset = {};
551551 int err = 0;
552552
553− if (!f.file)
553+ if (!fd_file(f))
554554 return -EBADF;
555555
556− if (proc_ns_file(f.file)) {
557− ns = get_proc_ns(file_inode(f.file));
556+ if (proc_ns_file(fd_file(f))) {
557+ ns = get_proc_ns(file_inode(fd_file(f)));
558558 if (flags && (ns->ops->type != flags))
559559 err = -EINVAL;
560560 flags = ns->ops->type;
561− } else if (!IS_ERR(pidfd_pid(f.file))) {
561+ } else if (!IS_ERR(pidfd_pid(fd_file(f)))) {
562562 err = check_setns_flags(flags);
563563 } else {
564564 err = -EINVAL;
@@ -570,10 +570,10 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags) · 5 unmodified lines
570570 if (err)
571571 goto out;
572572
573− if (proc_ns_file(f.file))
573+ if (proc_ns_file(fd_file(f)))
574574 err = validate_ns(&nsset, ns);
575575 else
576− err = validate_nsset(&nsset, pidfd_pid(f.file));
576+ err = validate_nsset(&nsset, pidfd_pid(fd_file(f)));
577577 if (!err) {
578578 commit_nsset(&nsset);
579579 perf_event_namespaces(current);
kernel/pid.c+5−5
@@ -540,13 +540,13 @@ struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) · 539 unmodified lines
540540 struct pid *pid;
541541
542542 f = fdget(fd);
543− if (!f.file)
543+ if (!fd_file(f))
544544 return ERR_PTR(-EBADF);
545545
546− pid = pidfd_pid(f.file);
546+ pid = pidfd_pid(fd_file(f));
547547 if (!IS_ERR(pid)) {
548548 get_pid(pid);
549− *flags = f.file->f_flags;
549+ *flags = fd_file(f)->f_flags;
550550 }
551551
552552 fdput(f);
@@ -755,10 +755,10 @@ SYSCALL_DEFINE3(pidfd_getfd, int, pidfd, int, fd, · 202 unmodified lines
755755 return -EINVAL;
756756
757757 f = fdget(pidfd);
758− if (!f.file)
758+ if (!fd_file(f))
759759 return -EBADF;
760760
761− pid = pidfd_pid(f.file);
761+ pid = pidfd_pid(fd_file(f));
762762 if (IS_ERR(pid))
763763 ret = PTR_ERR(pid);
764764 else
kernel/signal.c+3−3
@@ -3941,11 +3941,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, · 3940 unmodified lines
39413941 return -EINVAL;
39423942
39433943 f = fdget(pidfd);
3944− if (!f.file)
3944+ if (!fd_file(f))
39453945 return -EBADF;
39463946
39473947 /* Is this a pidfd? */
3948− pid = pidfd_to_pid(f.file);
3948+ pid = pidfd_to_pid(fd_file(f));
39493949 if (IS_ERR(pid)) {
39503950 ret = PTR_ERR(pid);
39513951 goto err;
@@ -3958,7 +3958,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, · 6 unmodified lines
39583958 switch (flags) {
39593959 case 0:
39603960 /* Infer scope from the type of pidfd. */
3961− if (f.file->f_flags & PIDFD_THREAD)
3961+ if (fd_file(f)->f_flags & PIDFD_THREAD)
39623962 type = PIDTYPE_PID;
39633963 else
39643964 type = PIDTYPE_TGID;
kernel/sys.c+5−5
@@ -1916,10 +1916,10 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) · 1915 unmodified lines
19161916 int err;
19171917
19181918 exe = fdget(fd);
1919− if (!exe.file)
1919+ if (!fd_file(exe))
19201920 return -EBADF;
19211921
1922− inode = file_inode(exe.file);
1922+ inode = file_inode(fd_file(exe));
19231923
19241924 /*
19251925 * Because the original mm->exe_file points to executable file, make
@@ -1927,14 +1927,14 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) · 1 unmodified line
19271927 * overall picture.
19281928 */
19291929 err = -EACCES;
1930− if (!S_ISREG(inode->i_mode) || path_noexec(&exe.file->f_path))
1930+ if (!S_ISREG(inode->i_mode) || path_noexec(&fd_file(exe)->f_path))
19311931 goto exit;
19321932
1933− err = file_permission(exe.file, MAY_EXEC);
1933+ err = file_permission(fd_file(exe), MAY_EXEC);
19341934 if (err)
19351935 goto exit;
19361936
1937− err = replace_mm_exe_file(mm, exe.file);
1937+ err = replace_mm_exe_file(mm, fd_file(exe));
19381938 exit:
19391939 fdput(exe);
19401940 return err;
kernel/taskstats.c+2−2
@@ -419,7 +419,7 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info) · 418 unmodified lines
419419
420420 fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);
421421 f = fdget(fd);
422− if (!f.file)
422+ if (!fd_file(f))
423423 return 0;
424424
425425 size = nla_total_size(sizeof(struct cgroupstats));
@@ -440,7 +440,7 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info) · 14 unmodified lines
440440 stats = nla_data(na);
441441 memset(stats, 0, sizeof(*stats));
442442
443− rc = cgroupstats_build(stats, f.file->f_path.dentry);
443+ rc = cgroupstats_build(stats, fd_file(f)->f_path.dentry);
444444 if (rc < 0) {
445445 nlmsg_free(rep_skb);
446446 goto err;
kernel/watch_queue.c+2−2
@@ -666,8 +666,8 @@ struct watch_queue *get_watch_queue(int fd) · 665 unmodified lines
666666 struct fd f;
667667
668668 f = fdget(fd);
669− if (f.file) {
670− pipe = get_pipe_info(f.file, false);
669+ if (fd_file(f)) {
670+ pipe = get_pipe_info(fd_file(f), false);
671671 if (pipe && pipe->watch_queue) {
672672 wqueue = pipe->watch_queue;
673673 kref_get(&wqueue->usage);
mm/fadvise.c+2−2
@@ -193,10 +193,10 @@ int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice) · 192 unmodified lines
193193 struct fd f = fdget(fd);
194194 int ret;
195195
196− if (!f.file)
196+ if (!fd_file(f))
197197 return -EBADF;
198198
199− ret = vfs_fadvise(f.file, offset, len, advice);
199+ ret = vfs_fadvise(fd_file(f), offset, len, advice);
200200
201201 fdput(f);
202202 return ret;
mm/filemap.c+3−3
@@ -4423,7 +4423,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd, · 4422 unmodified lines
44234423 struct cachestat cs;
44244424 pgoff_t first_index, last_index;
44254425
4426− if (!f.file)
4426+ if (!fd_file(f))
44274427 return -EBADF;
44284428
44294429 if (copy_from_user(&csr, cstat_range,
@@ -4433,7 +4433,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd, · 3 unmodified lines
44334433 }
44344434
44354435 /* hugetlbfs is not supported */
4436− if (is_file_hugepages(f.file)) {
4436+ if (is_file_hugepages(fd_file(f))) {
44374437 fdput(f);
44384438 return -EOPNOTSUPP;
44394439 }
@@ -4447,7 +4447,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd, · 7 unmodified lines
44474447 last_index =
44484448 csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
44494449 memset(&cs, 0, sizeof(struct cachestat));
4450− mapping = f.file->f_mapping;
4450+ mapping = fd_file(f)->f_mapping;
44514451 filemap_cachestat(mapping, first_index, last_index, &cs);
44524452 fdput(f);
44534453
mm/memcontrol-v1.c+6−6
@@ -1947,26 +1947,26 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of, · 1946 unmodified lines
19471947 INIT_WORK(&event->remove, memcg_event_remove);
19481948
19491949 efile = fdget(efd);
1950− if (!efile.file) {
1950+ if (!fd_file(efile)) {
19511951 ret = -EBADF;
19521952 goto out_kfree;
19531953 }
19541954
1955− event->eventfd = eventfd_ctx_fileget(efile.file);
1955+ event->eventfd = eventfd_ctx_fileget(fd_file(efile));
19561956 if (IS_ERR(event->eventfd)) {
19571957 ret = PTR_ERR(event->eventfd);
19581958 goto out_put_efile;
19591959 }
19601960
19611961 cfile = fdget(cfd);
1962− if (!cfile.file) {
1962+ if (!fd_file(cfile)) {
19631963 ret = -EBADF;
19641964 goto out_put_eventfd;
19651965 }
19661966
19671967 /* the process need read permission on control file */
19681968 /* AV: shouldn't we check that it's been opened for read instead? */
1969− ret = file_permission(cfile.file, MAY_READ);
1969+ ret = file_permission(fd_file(cfile), MAY_READ);
19701970 if (ret < 0)
19711971 goto out_put_cfile;
19721972
@@ -1974,7 +1974,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of, · 1 unmodified line
19741974 * The control file must be a regular cgroup1 file. As a regular cgroup
19751975 * file can't be renamed, it's safe to access its name afterwards.
19761976 */
1977− cdentry = cfile.file->f_path.dentry;
1977+ cdentry = fd_file(cfile)->f_path.dentry;
19781978 if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) {
19791979 ret = -EINVAL;
19801980 goto out_put_cfile;
@@ -2032,7 +2032,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of, · 51 unmodified lines
20322032 if (ret)
20332033 goto out_put_css;
20342034
2035− vfs_poll(efile.file, &event->pt);
2035+ vfs_poll(fd_file(efile), &event->pt);
20362036
20372037 spin_lock_irq(&memcg->event_list_lock);
20382038 list_add(&event->list, &memcg->event_list);
mm/readahead.c+5−5
@@ -678,7 +678,7 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count) · 677 unmodified lines
678678
679679 ret = -EBADF;
680680 f = fdget(fd);
681− if (!f.file || !(f.file->f_mode & FMODE_READ))
681+ if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
682682 goto out;
683683
684684 /*
@@ -687,12 +687,12 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count) · 2 unmodified lines
687687 * on this file, then we must return -EINVAL.
688688 */
689689 ret = -EINVAL;
690− if (!f.file->f_mapping || !f.file->f_mapping->a_ops ||
691− (!S_ISREG(file_inode(f.file)->i_mode) &&
692− !S_ISBLK(file_inode(f.file)->i_mode)))
690+ if (!fd_file(f)->f_mapping || !fd_file(f)->f_mapping->a_ops ||
691+ (!S_ISREG(file_inode(fd_file(f))->i_mode) &&
692+ !S_ISBLK(file_inode(fd_file(f))->i_mode)))
693693 goto out;
694694
695− ret = vfs_fadvise(f.file, offset, count, POSIX_FADV_WILLNEED);
695+ ret = vfs_fadvise(fd_file(f), offset, count, POSIX_FADV_WILLNEED);
696696 out:
697697 fdput(f);
698698 return ret;
net/core/net_namespace.c+3−3
@@ -697,11 +697,11 @@ struct net *get_net_ns_by_fd(int fd) · 696 unmodified lines
697697 struct fd f = fdget(fd);
698698 struct net *net = ERR_PTR(-EINVAL);
699699
700− if (!f.file)
700+ if (!fd_file(f))
701701 return ERR_PTR(-EBADF);
702702
703− if (proc_ns_file(f.file)) {
704− struct ns_common *ns = get_proc_ns(file_inode(f.file));
703+ if (proc_ns_file(fd_file(f))) {
704+ struct ns_common *ns = get_proc_ns(file_inode(fd_file(f)));
705705 if (ns->ops == &netns_operations)
706706 net = get_net(container_of(ns, struct net, ns));
707707 }
net/socket.c+7−7
@@ -556,10 +556,10 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) · 555 unmodified lines
556556 struct socket *sock;
557557
558558 *err = -EBADF;
559− if (f.file) {
560− sock = sock_from_file(f.file);
559+ if (fd_file(f)) {
560+ sock = sock_from_file(fd_file(f));
561561 if (likely(sock)) {
562− *fput_needed = f.flags & FDPUT_FPUT;
562+ *fput_needed = f.word & FDPUT_FPUT;
563563 return sock;
564564 }
565565 *err = -ENOTSOCK;
@@ -2014,8 +2014,8 @@ int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr, · 1448 unmodified lines
20142014 struct fd f;
20152015
20162016 f = fdget(fd);
2017− if (f.file) {
2018− ret = __sys_accept4_file(f.file, upeer_sockaddr,
2017+ if (fd_file(f)) {
2018+ ret = __sys_accept4_file(fd_file(f), upeer_sockaddr,
20192019 upeer_addrlen, flags);
20202020 fdput(f);
20212021 }
@@ -2076,12 +2076,12 @@ int __sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen) · 54 unmodified lines
20762076 struct fd f;
20772077
20782078 f = fdget(fd);
2079− if (f.file) {
2079+ if (fd_file(f)) {
20802080 struct sockaddr_storage address;
20812081
20822082 ret = move_addr_to_kernel(uservaddr, addrlen, &address);
20832083 if (!ret)
2084− ret = __sys_connect_file(f.file, &address, addrlen, 0);
2084+ ret = __sys_connect_file(fd_file(f), &address, addrlen, 0);
20852085 fdput(f);
20862086 }
20872087
security/integrity/ima/ima_main.c+2−2
@@ -1068,10 +1068,10 @@ void ima_kexec_cmdline(int kernel_fd, const void *buf, int size) · 1067 unmodified lines
10681068 return;
10691069
10701070 f = fdget(kernel_fd);
1071− if (!f.file)
1071+ if (!fd_file(f))
10721072 return;
10731073
1074− process_buffer_measurement(file_mnt_idmap(f.file), file_inode(f.file),
1074+ process_buffer_measurement(file_mnt_idmap(fd_file(f)), file_inode(fd_file(f)),
10751075 buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,
10761076 NULL, false, NULL, 0);
10771077 fdput(f);
security/landlock/syscalls.c+11−11
@@ -238,19 +238,19 @@ static struct landlock_ruleset *get_ruleset_from_fd(const int fd, · 237 unmodified lines
238238 struct landlock_ruleset *ruleset;
239239
240240 ruleset_f = fdget(fd);
241− if (!ruleset_f.file)
241+ if (!fd_file(ruleset_f))
242242 return ERR_PTR(-EBADF);
243243
244244 /* Checks FD type and access right. */
245− if (ruleset_f.file->f_op != &ruleset_fops) {
245+ if (fd_file(ruleset_f)->f_op != &ruleset_fops) {
246246 ruleset = ERR_PTR(-EBADFD);
247247 goto out_fdput;
248248 }
249− if (!(ruleset_f.file->f_mode & mode)) {
249+ if (!(fd_file(ruleset_f)->f_mode & mode)) {
250250 ruleset = ERR_PTR(-EPERM);
251251 goto out_fdput;
252252 }
253− ruleset = ruleset_f.file->private_data;
253+ ruleset = fd_file(ruleset_f)->private_data;
254254 if (WARN_ON_ONCE(ruleset->num_layers != 1)) {
255255 ruleset = ERR_PTR(-EINVAL);
256256 goto out_fdput;
@@ -277,22 +277,22 @@ static int get_path_from_fd(const s32 fd, struct path *const path) · 20 unmodified lines
277277
278278 /* Handles O_PATH. */
279279 f = fdget_raw(fd);
280− if (!f.file)
280+ if (!fd_file(f))
281281 return -EBADF;
282282 /*
283283 * Forbids ruleset FDs, internal filesystems (e.g. nsfs), including
284284 * pseudo filesystems that will never be mountable (e.g. sockfs,
285285 * pipefs).
286286 */
287− if ((f.file->f_op == &ruleset_fops) ||
288− (f.file->f_path.mnt->mnt_flags & MNT_INTERNAL) ||
289− (f.file->f_path.dentry->d_sb->s_flags & SB_NOUSER) ||
290− d_is_negative(f.file->f_path.dentry) ||
291− IS_PRIVATE(d_backing_inode(f.file->f_path.dentry))) {
287+ if ((fd_file(f)->f_op == &ruleset_fops) ||
288+ (fd_file(f)->f_path.mnt->mnt_flags & MNT_INTERNAL) ||
289+ (fd_file(f)->f_path.dentry->d_sb->s_flags & SB_NOUSER) ||
290+ d_is_negative(fd_file(f)->f_path.dentry) ||
291+ IS_PRIVATE(d_backing_inode(fd_file(f)->f_path.dentry))) {
292292 err = -EBADFD;
293293 goto out_fdput;
294294 }
295− *path = f.file->f_path;
295+ *path = fd_file(f)->f_path;
296296 path_get(path);
297297
298298 out_fdput:
security/loadpin/loadpin.c+2−2
@@ -296,7 +296,7 @@ static int read_trusted_verity_root_digests(unsigned int fd) · 295 unmodified lines
296296 return -EPERM;
297297
298298 f = fdget(fd);
299− if (!f.file)
299+ if (!fd_file(f))
300300 return -EINVAL;
301301
302302 data = kzalloc(SZ_4K, GFP_KERNEL);
@@ -305,7 +305,7 @@ static int read_trusted_verity_root_digests(unsigned int fd) · 2 unmodified lines
305305 goto err;
306306 }
307307
308− rc = kernel_read_file(f.file, 0, (void **)&data, SZ_4K - 1, NULL, READING_POLICY);
308+ rc = kernel_read_file(fd_file(f), 0, (void **)&data, SZ_4K - 1, NULL, READING_POLICY);
309309 if (rc < 0)
310310 goto err;
311311
sound/core/pcm_native.c+3−3
@@ -2250,12 +2250,12 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd) · 2249 unmodified lines
22502250 bool nonatomic = substream->pcm->nonatomic;
22512251 CLASS(fd, f)(fd);
22522252
2253− if (!f.file)
2253+ if (!fd_file(f))
22542254 return -EBADFD;
2255− if (!is_pcm_file(f.file))
2255+ if (!is_pcm_file(fd_file(f)))
22562256 return -EBADFD;
22572257
2258− pcm_file = f.file->private_data;
2258+ pcm_file = fd_file(f)->private_data;
22592259 substream1 = pcm_file->substream;
22602260
22612261 if (substream == substream1)
virt/kvm/eventfd.c+3−3
@@ -328,12 +328,12 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) · 327 unmodified lines
328328 seqcount_spinlock_init(&irqfd->irq_entry_sc, &kvm->irqfds.lock);
329329
330330 f = fdget(args->fd);
331− if (!f.file) {
331+ if (!fd_file(f)) {
332332 ret = -EBADF;
333333 goto out;
334334 }
335335
336− eventfd = eventfd_ctx_fileget(f.file);
336+ eventfd = eventfd_ctx_fileget(fd_file(f));
337337 if (IS_ERR(eventfd)) {
338338 ret = PTR_ERR(eventfd);
339339 goto fail;
@@ -420,7 +420,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) · 80 unmodified lines
420420 * Check if there was an event already pending on the eventfd
421421 * before we registered, and trigger it as if we didn't miss it.
422422 */
423− events = vfs_poll(f.file, &irqfd->pt);
423+ events = vfs_poll(fd_file(f), &irqfd->pt);
424424
425425 if (events & EPOLLIN)
426426 schedule_work(&irqfd->inject);
virt/kvm/vfio.c+4−4
@@ -194,7 +194,7 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd) · 193 unmodified lines
194194 int ret;
195195
196196 f = fdget(fd);
197− if (!f.file)
197+ if (!fd_file(f))
198198 return -EBADF;
199199
200200 ret = -ENOENT;
@@ -202,7 +202,7 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd) · 1 unmodified line
202202 mutex_lock(&kv->lock);
203203
204204 list_for_each_entry(kvf, &kv->file_list, node) {
205− if (kvf->file != f.file)
205+ if (kvf->file != fd_file(f))
206206 continue;
207207
208208 list_del(&kvf->node);
@@ -240,7 +240,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev, · 31 unmodified lines
240240 return -EFAULT;
241241
242242 f = fdget(param.groupfd);
243− if (!f.file)
243+ if (!fd_file(f))
244244 return -EBADF;
245245
246246 ret = -ENOENT;
@@ -248,7 +248,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev, · 1 unmodified line
248248 mutex_lock(&kv->lock);
249249
250250 list_for_each_entry(kvf, &kv->file_list, node) {
251− if (kvf->file != f.file)
251+ if (kvf->file != fd_file(f))
252252 continue;
253253
254254 if (!kvf->iommu_group) {