History

introduce fd_file(), convert all accessors to it.

For any changes of struct fd representation we need to turn existing accesses to fields into calls of wrappers. Accesses to struct fd::flags are very few (3 in linux/file.h, 1 in net/socket.c, 3 in fs/overlayfs/file.c and 3 more in explicit initializers). Those can be dealt with in the commit converting to new layout; accesses to struct fd::file are too many for that. This commit converts (almost) all of f.file to fd_file(f). It's not entirely mechanical ('file' is used as a member name more than just in struct fd) and it does not even attempt to distinguish the uses in pointer context from those in boolean context; the latter will be eventually turned into a separate helper (fd_empty()). NOTE: mass conversion to fd_empty(), tempting as it might be, is a bad idea; better do that piecewise in commit that convert from fdget...() to CLASS(...). [conflicts in fs/fhandle.c, kernel/bpf/syscall.c, mm/memcontrol.c caught by git; fs/stat.c one got caught by git grep] [fs/xattr.c conflict]

Al Viro committed 2 years ago

Commit 1da91ea1 parent 840029183 files · +504 −502Browse 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 +4 −4
  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/coda/inode.c +2 −2
  20. fs/eventfd.c +2 −2
  21. fs/eventpoll.c +15 −15
  22. fs/ext4/ioctl.c +3 −3
  23. fs/f2fs/file.c +3 −3
  24. fs/fcntl.c +19 −19
  25. fs/fhandle.c +2 −2
  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 +6 −6
  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 +20 −20
  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 +2 −2
  53. fs/xfs/xfs_handle.c +2 −2
  54. fs/xfs/xfs_ioctl.c +14 −14
  55. include/linux/cleanup.h +1 −1
  56. include/linux/file.h +4 −2
  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 +6 −6
  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 +6 −6
  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
160 .count = count160 .count = count
161 };161 };
162 162
163 if (!arg.file)163 if (!fd_file(arg))
164 return -EBADF;164 return -EBADF;
165 165
166 error = iterate_dir(arg.file, &buf.ctx);166 error = iterate_dir(fd_file(arg), &buf.ctx);
167 if (error >= 0)167 if (error >= 0)
168 error = buf.error;168 error = buf.error;
169 if (count != buf.count)169 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
239 struct flock64 flock;239 struct flock64 flock;
240 long err = -EBADF;240 long err = -EBADF;
241 241
242 if (!f.file)242 if (!fd_file(f))
243 goto out;243 goto out;
244 244
245 switch (cmd) {245 switch (cmd) {
246 case F_GETLK64:246 case F_GETLK64:
247 case F_OFD_GETLK:247 case F_OFD_GETLK:
248 err = security_file_fcntl(f.file, cmd, arg);248 err = security_file_fcntl(fd_file(f), cmd, arg);
249 if (err)249 if (err)
250 break;250 break;
251 err = get_oabi_flock(&flock, argp);251 err = get_oabi_flock(&flock, argp);
252 if (err)252 if (err)
253 break;253 break;
254 err = fcntl_getlk64(f.file, cmd, &flock);254 err = fcntl_getlk64(fd_file(f), cmd, &flock);
255 if (!err)255 if (!err)
256 err = put_oabi_flock(&flock, argp);256 err = put_oabi_flock(&flock, argp);
257 break;257 break;
@@ -259,13 +259,13 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd, · 1 unmodified line
259 case F_SETLKW64:259 case F_SETLKW64:
260 case F_OFD_SETLK:260 case F_OFD_SETLK:
261 case F_OFD_SETLKW:261 case F_OFD_SETLKW:
262 err = security_file_fcntl(f.file, cmd, arg);262 err = security_file_fcntl(fd_file(f), cmd, arg);
263 if (err)263 if (err)
264 break;264 break;
265 err = get_oabi_flock(&flock, argp);265 err = get_oabi_flock(&flock, argp);
266 if (err)266 if (err)
267 break;267 break;
268 err = fcntl_setlk64(fd, f.file, cmd, &flock);268 err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
269 break;269 break;
270 default:270 default:
271 err = sys_fcntl64(fd, cmd, arg);271 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
118 struct fd f;118 struct fd f;
119 119
120 f = fdget(tablefd);120 f = fdget(tablefd);
121 if (!f.file)121 if (!fd_file(f))
122 return -EBADF;122 return -EBADF;
123 123
124 rcu_read_lock();124 rcu_read_lock();
125 list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) {125 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) {
127 found = true;127 found = true;
128 break;128 break;
129 }129 }
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
1938 1938
1939 r = -EBADF;1939 r = -EBADF;
1940 f = fdget(cap->args[0]);1940 f = fdget(cap->args[0]);
1941 if (!f.file)1941 if (!fd_file(f))
1942 break;1942 break;
1943 1943
1944 r = -EPERM;1944 r = -EPERM;
1945 dev = kvm_device_from_filp(f.file);1945 dev = kvm_device_from_filp(fd_file(f));
1946 if (dev)1946 if (dev)
1947 r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);1947 r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
1948 1948
@@ -1957,11 +1957,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, · 8 unmodified lines
1957 1957
1958 r = -EBADF;1958 r = -EBADF;
1959 f = fdget(cap->args[0]);1959 f = fdget(cap->args[0]);
1960 if (!f.file)1960 if (!fd_file(f))
1961 break;1961 break;
1962 1962
1963 r = -EPERM;1963 r = -EPERM;
1964 dev = kvm_device_from_filp(f.file);1964 dev = kvm_device_from_filp(fd_file(f));
1965 if (dev) {1965 if (dev) {
1966 if (xics_on_xive())1966 if (xics_on_xive())
1967 r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]);1967 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
1980 1980
1981 r = -EBADF;1981 r = -EBADF;
1982 f = fdget(cap->args[0]);1982 f = fdget(cap->args[0]);
1983 if (!f.file)1983 if (!fd_file(f))
1984 break;1984 break;
1985 1985
1986 r = -ENXIO;1986 r = -ENXIO;
@@ -1990,7 +1990,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, · 3 unmodified lines
1990 }1990 }
1991 1991
1992 r = -EPERM;1992 r = -EPERM;
1993 dev = kvm_device_from_filp(f.file);1993 dev = kvm_device_from_filp(fd_file(f));
1994 if (dev)1994 if (dev)
1995 r = kvmppc_xive_native_connect_vcpu(dev, vcpu,1995 r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
1996 cap->args[1]);1996 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
66 if (flags & SPU_CREATE_AFFINITY_SPU) {66 if (flags & SPU_CREATE_AFFINITY_SPU) {
67 struct fd neighbor = fdget(neighbor_fd);67 struct fd neighbor = fdget(neighbor_fd);
68 ret = -EBADF;68 ret = -EBADF;
69 if (neighbor.file) {69 if (fd_file(neighbor)) {
70 ret = calls->create_thread(name, flags, mode, neighbor.file);70 ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
71 fdput(neighbor);71 fdput(neighbor);
72 }72 }
73 } else73 } else
@@ -89,8 +89,8 @@ SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus) · 15 unmodified lines
89 89
90 ret = -EBADF;90 ret = -EBADF;
91 arg = fdget(fd);91 arg = fdget(fd);
92 if (arg.file) {92 if (fd_file(arg)) {
93 ret = calls->spu_run(arg.file, unpc, ustatus);93 ret = calls->spu_run(fd_file(arg), unpc, ustatus);
94 fdput(arg);94 fdput(arg);
95 }95 }
96 96
arch/x86/kernel/cpu/sgx/main.c+2−2
@@ -895,10 +895,10 @@ int sgx_set_attribute(unsigned long *allowed_attributes, · 894 unmodified lines
895{895{
896 struct fd f = fdget(attribute_fd);896 struct fd f = fdget(attribute_fd);
897 897
898 if (!f.file)898 if (!fd_file(f))
899 return -EINVAL;899 return -EINVAL;
900 900
901 if (f.file->f_op != &sgx_provision_fops) {901 if (fd_file(f)->f_op != &sgx_provision_fops) {
902 fdput(f);902 fdput(f);
903 return -EINVAL;903 return -EINVAL;
904 }904 }
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
534 int ret;534 int ret;
535 535
536 f = fdget(fd);536 f = fdget(fd);
537 if (!f.file)537 if (!fd_file(f))
538 return -EBADF;538 return -EBADF;
539 539
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);
541 541
542 fdput(f);542 fdput(f);
543 return ret;543 return ret;
@@ -2078,15 +2078,15 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd) · 1534 unmodified lines
2078 bool charged = false;2078 bool charged = false;
2079 int ret;2079 int ret;
2080 2080
2081 if (!f.file)2081 if (!fd_file(f))
2082 return -EBADF;2082 return -EBADF;
2083 2083
2084 if (!file_is_kvm(f.file)) {2084 if (!file_is_kvm(fd_file(f))) {
2085 ret = -EBADF;2085 ret = -EBADF;
2086 goto out_fput;2086 goto out_fput;
2087 }2087 }
2088 2088
2089 source_kvm = f.file->private_data;2089 source_kvm = fd_file(f)->private_data;
2090 ret = sev_lock_two_vms(kvm, source_kvm);2090 ret = sev_lock_two_vms(kvm, source_kvm);
2091 if (ret)2091 if (ret)
2092 goto out_fput;2092 goto out_fput;
@@ -2801,15 +2801,15 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd) · 708 unmodified lines
2801 struct kvm_sev_info *source_sev, *mirror_sev;2801 struct kvm_sev_info *source_sev, *mirror_sev;
2802 int ret;2802 int ret;
2803 2803
2804 if (!f.file)2804 if (!fd_file(f))
2805 return -EBADF;2805 return -EBADF;
2806 2806
2807 if (!file_is_kvm(f.file)) {2807 if (!file_is_kvm(fd_file(f))) {
2808 ret = -EBADF;2808 ret = -EBADF;
2809 goto e_source_fput;2809 goto e_source_fput;
2810 }2810 }
2811 2811
2812 source_kvm = f.file->private_data;2812 source_kvm = fd_file(f)->private_data;
2813 ret = sev_lock_two_vms(kvm, source_kvm);2813 ret = sev_lock_two_vms(kvm, source_kvm);
2814 if (ret)2814 if (ret)
2815 goto e_source_fput;2815 goto e_source_fput;
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c+4−4
@@ -43,10 +43,10 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, · 42 unmodified lines
43 uint32_t id;43 uint32_t id;
44 int r;44 int r;
45 45
46 if (!f.file)46 if (!fd_file(f))
47 return -EINVAL;47 return -EINVAL;
48 48
49 r = amdgpu_file_to_fpriv(f.file, &fpriv);49 r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
50 if (r) {50 if (r) {
51 fdput(f);51 fdput(f);
52 return r;52 return r;
@@ -72,10 +72,10 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev, · 19 unmodified lines
72 struct amdgpu_ctx *ctx;72 struct amdgpu_ctx *ctx;
73 int r;73 int r;
74 74
75 if (!f.file)75 if (!fd_file(f))
76 return -EINVAL;76 return -EINVAL;
77 77
78 r = amdgpu_file_to_fpriv(f.file, &fpriv);78 r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
79 if (r) {79 if (r) {
80 fdput(f);80 fdput(f);
81 return r;81 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
715 struct fd f = fdget(fd);715 struct fd f = fdget(fd);
716 int ret;716 int ret;
717 717
718 if (!f.file)718 if (!fd_file(f))
719 return -EINVAL;719 return -EINVAL;
720 720
721 if (f.file->f_op != &drm_syncobj_file_fops) {721 if (fd_file(f)->f_op != &drm_syncobj_file_fops) {
722 fdput(f);722 fdput(f);
723 return -EINVAL;723 return -EINVAL;
724 }724 }
725 725
726 /* take a reference to put in the idr */726 /* take a reference to put in the idr */
727 syncobj = f.file->private_data;727 syncobj = fd_file(f)->private_data;
728 drm_syncobj_get(syncobj);728 drm_syncobj_get(syncobj);
729 729
730 idr_preload(GFP_KERNEL);730 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
1624 1624
1625 /* Get current fd to protect against it being closed */1625 /* Get current fd to protect against it being closed */
1626 f = fdget(cmd.fd);1626 f = fdget(cmd.fd);
1627 if (!f.file)1627 if (!fd_file(f))
1628 return -ENOENT;1628 return -ENOENT;
1629 if (f.file->f_op != &ucma_fops) {1629 if (fd_file(f)->f_op != &ucma_fops) {
1630 ret = -EINVAL;1630 ret = -EINVAL;
1631 goto file_put;1631 goto file_put;
1632 }1632 }
1633 cur_file = f.file->private_data;1633 cur_file = fd_file(f)->private_data;
1634 1634
1635 /* Validate current fd and prevent destruction of id. */1635 /* Validate current fd and prevent destruction of id. */
1636 ctx = ucma_get_ctx(cur_file, cmd.id);1636 ctx = ucma_get_ctx(cur_file, cmd.id);
drivers/infiniband/core/uverbs_cmd.c+4−4
@@ -584,12 +584,12 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs) · 583 unmodified lines
584 if (cmd.fd != -1) {584 if (cmd.fd != -1) {
585 /* search for file descriptor */585 /* search for file descriptor */
586 f = fdget(cmd.fd);586 f = fdget(cmd.fd);
587 if (!f.file) {587 if (!fd_file(f)) {
588 ret = -EBADF;588 ret = -EBADF;
589 goto err_tree_mutex_unlock;589 goto err_tree_mutex_unlock;
590 }590 }
591 591
592 inode = file_inode(f.file);592 inode = file_inode(fd_file(f));
593 xrcd = find_xrcd(ibudev, inode);593 xrcd = find_xrcd(ibudev, inode);
594 if (!xrcd && !(cmd.oflags & O_CREAT)) {594 if (!xrcd && !(cmd.oflags & O_CREAT)) {
595 /* no file descriptor. Need CREATE flag */595 /* no file descriptor. Need CREATE flag */
@@ -632,7 +632,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs) · 36 unmodified lines
632 atomic_inc(&xrcd->usecnt);632 atomic_inc(&xrcd->usecnt);
633 }633 }
634 634
635 if (f.file)635 if (fd_file(f))
636 fdput(f);636 fdput(f);
637 637
638 mutex_unlock(&ibudev->xrcd_tree_mutex);638 mutex_unlock(&ibudev->xrcd_tree_mutex);
@@ -648,7 +648,7 @@ err: · 9 unmodified lines
648 uobj_alloc_abort(&obj->uobject, attrs);648 uobj_alloc_abort(&obj->uobject, attrs);
649 649
650err_tree_mutex_unlock:650err_tree_mutex_unlock:
651 if (f.file)651 if (fd_file(f))
652 fdput(f);652 fdput(f);
653 653
654 mutex_unlock(&ibudev->xrcd_tree_mutex);654 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
254 return ERR_PTR(-EBADR);254 return ERR_PTR(-EBADR);
255 255
256 f = fdget(request_fd);256 f = fdget(request_fd);
257 if (!f.file)257 if (!fd_file(f))
258 goto err_no_req_fd;258 goto err_no_req_fd;
259 259
260 if (f.file->f_op != &request_fops)260 if (fd_file(f)->f_op != &request_fops)
261 goto err_fput;261 goto err_fput;
262 req = f.file->private_data;262 req = fd_file(f)->private_data;
263 if (req->mdev != mdev)263 if (req->mdev != mdev)
264 goto err_fput;264 goto err_fput;
265 265
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
820 struct lirc_fh *fh;820 struct lirc_fh *fh;
821 struct rc_dev *dev;821 struct rc_dev *dev;
822 822
823 if (!f.file)823 if (!fd_file(f))
824 return ERR_PTR(-EBADF);824 return ERR_PTR(-EBADF);
825 825
826 if (f.file->f_op != &lirc_fops) {826 if (fd_file(f)->f_op != &lirc_fops) {
827 fdput(f);827 fdput(f);
828 return ERR_PTR(-EINVAL);828 return ERR_PTR(-EINVAL);
829 }829 }
830 830
831 if (write && !(f.file->f_mode & FMODE_WRITE)) {831 if (write && !(fd_file(f)->f_mode & FMODE_WRITE)) {
832 fdput(f);832 fdput(f);
833 return ERR_PTR(-EPERM);833 return ERR_PTR(-EPERM);
834 }834 }
835 835
836 fh = f.file->private_data;836 fh = fd_file(f)->private_data;
837 dev = fh->rc;837 dev = fh->rc;
838 838
839 get_device(&dev->dev);839 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
112 return -EFAULT;112 return -EFAULT;
113 113
114 f = fdget(fd);114 f = fdget(fd);
115 if (!f.file)115 if (!fd_file(f))
116 return -EBADF;116 return -EBADF;
117 117
118 mutex_lock(&group->group_lock);118 mutex_lock(&group->group_lock);
@@ -125,13 +125,13 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group, · 6 unmodified lines
125 goto out_unlock;125 goto out_unlock;
126 }126 }
127 127
128 container = vfio_container_from_file(f.file);128 container = vfio_container_from_file(fd_file(f));
129 if (container) {129 if (container) {
130 ret = vfio_container_attach_group(container, group);130 ret = vfio_container_attach_group(container, group);
131 goto out_unlock;131 goto out_unlock;
132 }132 }
133 133
134 iommufd = iommufd_ctx_from_file(f.file);134 iommufd = iommufd_ctx_from_file(fd_file(f));
135 if (!IS_ERR(iommufd)) {135 if (!IS_ERR(iommufd)) {
136 if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&136 if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&
137 group->type == VFIO_NO_IOMMU)137 group->type == VFIO_NO_IOMMU)
drivers/vfio/virqfd.c+3−3
@@ -134,12 +134,12 @@ int vfio_virqfd_enable(void *opaque, · 133 unmodified lines
134 INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject);134 INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject);
135 135
136 irqfd = fdget(fd);136 irqfd = fdget(fd);
137 if (!irqfd.file) {137 if (!fd_file(irqfd)) {
138 ret = -EBADF;138 ret = -EBADF;
139 goto err_fd;139 goto err_fd;
140 }140 }
141 141
142 ctx = eventfd_ctx_fileget(irqfd.file);142 ctx = eventfd_ctx_fileget(fd_file(irqfd));
143 if (IS_ERR(ctx)) {143 if (IS_ERR(ctx)) {
144 ret = PTR_ERR(ctx);144 ret = PTR_ERR(ctx);
145 goto err_ctx;145 goto err_ctx;
@@ -171,7 +171,7 @@ int vfio_virqfd_enable(void *opaque, · 25 unmodified lines
171 init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);171 init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
172 init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);172 init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
173 173
174 events = vfs_poll(irqfd.file, &virqfd->pt);174 events = vfs_poll(fd_file(irqfd), &virqfd->pt);
175 175
176 /*176 /*
177 * Check if there was an event already pending on the eventfd177 * 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
125 INIT_WORK(&irqfd->shutdown, hsm_irqfd_shutdown_work);125 INIT_WORK(&irqfd->shutdown, hsm_irqfd_shutdown_work);
126 126
127 f = fdget(args->fd);127 f = fdget(args->fd);
128 if (!f.file) {128 if (!fd_file(f)) {
129 ret = -EBADF;129 ret = -EBADF;
130 goto out;130 goto out;
131 }131 }
132 132
133 eventfd = eventfd_ctx_fileget(f.file);133 eventfd = eventfd_ctx_fileget(fd_file(f));
134 if (IS_ERR(eventfd)) {134 if (IS_ERR(eventfd)) {
135 ret = PTR_ERR(eventfd);135 ret = PTR_ERR(eventfd);
136 goto fail;136 goto fail;
@@ -157,7 +157,7 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args) · 20 unmodified lines
157 mutex_unlock(&vm->irqfds_lock);157 mutex_unlock(&vm->irqfds_lock);
158 158
159 /* Check the pending event in this stage */159 /* Check the pending event in this stage */
160 events = vfs_poll(f.file, &irqfd->pt);160 events = vfs_poll(fd_file(f), &irqfd->pt);
161 161
162 if (events & EPOLLIN)162 if (events & EPOLLIN)
163 acrn_irqfd_inject(irqfd);163 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
959 INIT_WORK(&kirqfd->shutdown, irqfd_shutdown);959 INIT_WORK(&kirqfd->shutdown, irqfd_shutdown);
960 960
961 f = fdget(irqfd->fd);961 f = fdget(irqfd->fd);
962 if (!f.file) {962 if (!fd_file(f)) {
963 ret = -EBADF;963 ret = -EBADF;
964 goto error_kfree;964 goto error_kfree;
965 }965 }
966 966
967 kirqfd->eventfd = eventfd_ctx_fileget(f.file);967 kirqfd->eventfd = eventfd_ctx_fileget(fd_file(f));
968 if (IS_ERR(kirqfd->eventfd)) {968 if (IS_ERR(kirqfd->eventfd)) {
969 ret = PTR_ERR(kirqfd->eventfd);969 ret = PTR_ERR(kirqfd->eventfd);
970 goto error_fd_put;970 goto error_fd_put;
@@ -995,7 +995,7 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd) · 24 unmodified lines
995 * Check if there was an event already pending on the eventfd before we995 * Check if there was an event already pending on the eventfd before we
996 * registered, and trigger it as if we didn't miss it.996 * registered, and trigger it as if we didn't miss it.
997 */997 */
998 events = vfs_poll(f.file, &kirqfd->pt);998 events = vfs_poll(fd_file(f), &kirqfd->pt);
999 if (events & EPOLLIN)999 if (events & EPOLLIN)
1000 irqfd_inject(kirqfd);1000 irqfd_inject(kirqfd);
1001 1001
@@ -1345,12 +1345,12 @@ static int privcmd_ioeventfd_assign(struct privcmd_ioeventfd *ioeventfd) · 343 unmodified lines
1345 return -ENOMEM;1345 return -ENOMEM;
1346 1346
1347 f = fdget(ioeventfd->event_fd);1347 f = fdget(ioeventfd->event_fd);
1348 if (!f.file) {1348 if (!fd_file(f)) {
1349 ret = -EBADF;1349 ret = -EBADF;
1350 goto error_kfree;1350 goto error_kfree;
1351 }1351 }
1352 1352
1353 kioeventfd->eventfd = eventfd_ctx_fileget(f.file);1353 kioeventfd->eventfd = eventfd_ctx_fileget(fd_file(f));
1354 fdput(f);1354 fdput(f);
1355 1355
1356 if (IS_ERR(kioeventfd->eventfd)) {1356 if (IS_ERR(kioeventfd->eventfd)) {
fs/btrfs/ioctl.c+2−2
@@ -1312,12 +1312,12 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, · 1311 unmodified lines
1312 } else {1312 } else {
1313 struct fd src = fdget(fd);1313 struct fd src = fdget(fd);
1314 struct inode *src_inode;1314 struct inode *src_inode;
1315 if (!src.file) {1315 if (!fd_file(src)) {
1316 ret = -EINVAL;1316 ret = -EINVAL;
1317 goto out_drop_write;1317 goto out_drop_write;
1318 }1318 }
1319 1319
1320 src_inode = file_inode(src.file);1320 src_inode = file_inode(fd_file(src));
1321 if (src_inode->i_sb != file_inode(file)->i_sb) {1321 if (src_inode->i_sb != file_inode(file)->i_sb) {
1322 btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,1322 btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
1323 "Snapshot src from another FS");1323 "Snapshot src from another FS");
fs/coda/inode.c+2−2
@@ -127,9 +127,9 @@ static int coda_parse_fd(struct fs_context *fc, int fd) · 126 unmodified lines
127 int idx;127 int idx;
128 128
129 f = fdget(fd);129 f = fdget(fd);
130 if (!f.file)130 if (!fd_file(f))
131 return -EBADF;131 return -EBADF;
132 inode = file_inode(f.file);132 inode = file_inode(fd_file(f));
133 if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) {133 if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) {
134 fdput(f);134 fdput(f);
135 return invalf(fc, "code: Not coda psdev");135 return invalf(fc, "code: Not coda psdev");
fs/eventfd.c+2−2
@@ -349,9 +349,9 @@ struct eventfd_ctx *eventfd_ctx_fdget(int fd) · 348 unmodified lines
349{349{
350 struct eventfd_ctx *ctx;350 struct eventfd_ctx *ctx;
351 struct fd f = fdget(fd);351 struct fd f = fdget(fd);
352 if (!f.file)352 if (!fd_file(f))
353 return ERR_PTR(-EBADF);353 return ERR_PTR(-EBADF);
354 ctx = eventfd_ctx_fileget(f.file);354 ctx = eventfd_ctx_fileget(fd_file(f));
355 fdput(f);355 fdput(f);
356 return ctx;356 return ctx;
357}357}
fs/eventpoll.c+15−15
@@ -2266,17 +2266,17 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 2265 unmodified lines
2266 2266
2267 error = -EBADF;2267 error = -EBADF;
2268 f = fdget(epfd);2268 f = fdget(epfd);
2269 if (!f.file)2269 if (!fd_file(f))
2270 goto error_return;2270 goto error_return;
2271 2271
2272 /* Get the "struct file *" for the target file */2272 /* Get the "struct file *" for the target file */
2273 tf = fdget(fd);2273 tf = fdget(fd);
2274 if (!tf.file)2274 if (!fd_file(tf))
2275 goto error_fput;2275 goto error_fput;
2276 2276
2277 /* The target file descriptor must support poll */2277 /* The target file descriptor must support poll */
2278 error = -EPERM;2278 error = -EPERM;
2279 if (!file_can_poll(tf.file))2279 if (!file_can_poll(fd_file(tf)))
2280 goto error_tgt_fput;2280 goto error_tgt_fput;
2281 2281
2282 /* Check if EPOLLWAKEUP is allowed */2282 /* Check if EPOLLWAKEUP is allowed */
@@ -2289,7 +2289,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 6 unmodified lines
2289 * adding an epoll file descriptor inside itself.2289 * adding an epoll file descriptor inside itself.
2290 */2290 */
2291 error = -EINVAL;2291 error = -EINVAL;
2292 if (f.file == tf.file || !is_file_epoll(f.file))2292 if (fd_file(f) == fd_file(tf) || !is_file_epoll(fd_file(f)))
2293 goto error_tgt_fput;2293 goto error_tgt_fput;
2294 2294
2295 /*2295 /*
@@ -2300,7 +2300,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 4 unmodified lines
2300 if (ep_op_has_event(op) && (epds->events & EPOLLEXCLUSIVE)) {2300 if (ep_op_has_event(op) && (epds->events & EPOLLEXCLUSIVE)) {
2301 if (op == EPOLL_CTL_MOD)2301 if (op == EPOLL_CTL_MOD)
2302 goto error_tgt_fput;2302 goto error_tgt_fput;
2303 if (op == EPOLL_CTL_ADD && (is_file_epoll(tf.file) ||2303 if (op == EPOLL_CTL_ADD && (is_file_epoll(fd_file(tf)) ||
2304 (epds->events & ~EPOLLEXCLUSIVE_OK_BITS)))2304 (epds->events & ~EPOLLEXCLUSIVE_OK_BITS)))
2305 goto error_tgt_fput;2305 goto error_tgt_fput;
2306 }2306 }
@@ -2309,7 +2309,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 2 unmodified lines
2309 * At this point it is safe to assume that the "private_data" contains2309 * At this point it is safe to assume that the "private_data" contains
2310 * our own data structure.2310 * our own data structure.
2311 */2311 */
2312 ep = f.file->private_data;2312 ep = fd_file(f)->private_data;
2313 2313
2314 /*2314 /*
2315 * When we insert an epoll file descriptor inside another epoll file2315 * When we insert an epoll file descriptor inside another epoll file
@@ -2330,16 +2330,16 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 14 unmodified lines
2330 if (error)2330 if (error)
2331 goto error_tgt_fput;2331 goto error_tgt_fput;
2332 if (op == EPOLL_CTL_ADD) {2332 if (op == EPOLL_CTL_ADD) {
2333 if (READ_ONCE(f.file->f_ep) || ep->gen == loop_check_gen ||2333 if (READ_ONCE(fd_file(f)->f_ep) || ep->gen == loop_check_gen ||
2334 is_file_epoll(tf.file)) {2334 is_file_epoll(fd_file(tf))) {
2335 mutex_unlock(&ep->mtx);2335 mutex_unlock(&ep->mtx);
2336 error = epoll_mutex_lock(&epnested_mutex, 0, nonblock);2336 error = epoll_mutex_lock(&epnested_mutex, 0, nonblock);
2337 if (error)2337 if (error)
2338 goto error_tgt_fput;2338 goto error_tgt_fput;
2339 loop_check_gen++;2339 loop_check_gen++;
2340 full_check = 1;2340 full_check = 1;
2341 if (is_file_epoll(tf.file)) {2341 if (is_file_epoll(fd_file(tf))) {
2342 tep = tf.file->private_data;2342 tep = fd_file(tf)->private_data;
2343 error = -ELOOP;2343 error = -ELOOP;
2344 if (ep_loop_check(ep, tep) != 0)2344 if (ep_loop_check(ep, tep) != 0)
2345 goto error_tgt_fput;2345 goto error_tgt_fput;
@@ -2355,14 +2355,14 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds, · 9 unmodified lines
2355 * above, we can be sure to be able to use the item looked up by2355 * above, we can be sure to be able to use the item looked up by
2356 * ep_find() till we release the mutex.2356 * ep_find() till we release the mutex.
2357 */2357 */
2358 epi = ep_find(ep, tf.file, fd);2358 epi = ep_find(ep, fd_file(tf), fd);
2359 2359
2360 error = -EINVAL;2360 error = -EINVAL;
2361 switch (op) {2361 switch (op) {
2362 case EPOLL_CTL_ADD:2362 case EPOLL_CTL_ADD:
2363 if (!epi) {2363 if (!epi) {
2364 epds->events |= EPOLLERR | EPOLLHUP;2364 epds->events |= EPOLLERR | EPOLLHUP;
2365 error = ep_insert(ep, epds, tf.file, fd, full_check);2365 error = ep_insert(ep, epds, fd_file(tf), fd, full_check);
2366 } else2366 } else
2367 error = -EEXIST;2367 error = -EEXIST;
2368 break;2368 break;
@@ -2443,7 +2443,7 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events, · 74 unmodified lines
2443 2443
2444 /* Get the "struct file *" for the eventpoll file */2444 /* Get the "struct file *" for the eventpoll file */
2445 f = fdget(epfd);2445 f = fdget(epfd);
2446 if (!f.file)2446 if (!fd_file(f))
2447 return -EBADF;2447 return -EBADF;
2448 2448
2449 /*2449 /*
@@ -2451,14 +2451,14 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events, · 1 unmodified line
2451 * the user passed to us _is_ an eventpoll file.2451 * the user passed to us _is_ an eventpoll file.
2452 */2452 */
2453 error = -EINVAL;2453 error = -EINVAL;
2454 if (!is_file_epoll(f.file))2454 if (!is_file_epoll(fd_file(f)))
2455 goto error_fput;2455 goto error_fput;
2456 2456
2457 /*2457 /*
2458 * At this point it is safe to assume that the "private_data" contains2458 * At this point it is safe to assume that the "private_data" contains
2459 * our own data structure.2459 * our own data structure.
2460 */2460 */
2461 ep = f.file->private_data;2461 ep = fd_file(f)->private_data;
2462 2462
2463 /* Time to fish for events ... */2463 /* Time to fish for events ... */
2464 error = ep_poll(ep, events, maxevents, to);2464 error = ep_poll(ep, events, maxevents, to);
fs/ext4/ioctl.c+3−3
@@ -1343,10 +1343,10 @@ group_extend_out: · 1342 unmodified lines
1343 me.moved_len = 0;1343 me.moved_len = 0;
1344 1344
1345 donor = fdget(me.donor_fd);1345 donor = fdget(me.donor_fd);
1346 if (!donor.file)1346 if (!fd_file(donor))
1347 return -EBADF;1347 return -EBADF;
1348 1348
1349 if (!(donor.file->f_mode & FMODE_WRITE)) {1349 if (!(fd_file(donor)->f_mode & FMODE_WRITE)) {
1350 err = -EBADF;1350 err = -EBADF;
1351 goto mext_out;1351 goto mext_out;
1352 }1352 }
@@ -1367,7 +1367,7 @@ group_extend_out: · 14 unmodified lines
1367 if (err)1367 if (err)
1368 goto mext_out;1368 goto mext_out;
1369 1369
1370 err = ext4_move_extents(filp, donor.file, me.orig_start,1370 err = ext4_move_extents(filp, fd_file(donor), me.orig_start,
1371 me.donor_start, me.len, &me.moved_len);1371 me.donor_start, me.len, &me.moved_len);
1372 mnt_drop_write_file(filp);1372 mnt_drop_write_file(filp);
1373 1373
fs/f2fs/file.c+3−3
@@ -3014,10 +3014,10 @@ static int __f2fs_ioc_move_range(struct file *filp, · 3013 unmodified lines
3014 return -EBADF;3014 return -EBADF;
3015 3015
3016 dst = fdget(range->dst_fd);3016 dst = fdget(range->dst_fd);
3017 if (!dst.file)3017 if (!fd_file(dst))
3018 return -EBADF;3018 return -EBADF;
3019 3019
3020 if (!(dst.file->f_mode & FMODE_WRITE)) {3020 if (!(fd_file(dst)->f_mode & FMODE_WRITE)) {
3021 err = -EBADF;3021 err = -EBADF;
3022 goto err_out;3022 goto err_out;
3023 }3023 }
@@ -3026,7 +3026,7 @@ static int __f2fs_ioc_move_range(struct file *filp, · 2 unmodified lines
3026 if (err)3026 if (err)
3027 goto err_out;3027 goto err_out;
3028 3028
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),
3030 range->pos_out, range->len);3030 range->pos_out, range->len);
3031 3031
3032 mnt_drop_write_file(filp);3032 mnt_drop_write_file(filp);
fs/fcntl.c+19−19
@@ -340,7 +340,7 @@ static long f_dupfd_query(int fd, struct file *filp) · 339 unmodified lines
340 * overkill, but given our lockless file pointer lookup, the340 * overkill, but given our lockless file pointer lookup, the
341 * alternatives are complicated.341 * alternatives are complicated.
342 */342 */
343 return f.file == filp;343 return fd_file(f) == filp;
344}344}
345 345
346static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,346static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
@@ -479,17 +479,17 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) · 132 unmodified lines
479 struct fd f = fdget_raw(fd);479 struct fd f = fdget_raw(fd);
480 long err = -EBADF;480 long err = -EBADF;
481 481
482 if (!f.file)482 if (!fd_file(f))
483 goto out;483 goto out;
484 484
485 if (unlikely(f.file->f_mode & FMODE_PATH)) {485 if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
486 if (!check_fcntl_cmd(cmd))486 if (!check_fcntl_cmd(cmd))
487 goto out1;487 goto out1;
488 }488 }
489 489
490 err = security_file_fcntl(f.file, cmd, arg);490 err = security_file_fcntl(fd_file(f), cmd, arg);
491 if (!err)491 if (!err)
492 err = do_fcntl(fd, cmd, arg, f.file);492 err = do_fcntl(fd, cmd, arg, fd_file(f));
493 493
494out1:494out1:
495 fdput(f);495 fdput(f);
@@ -506,15 +506,15 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, · 10 unmodified lines
506 struct flock64 flock;506 struct flock64 flock;
507 long err = -EBADF;507 long err = -EBADF;
508 508
509 if (!f.file)509 if (!fd_file(f))
510 goto out;510 goto out;
511 511
512 if (unlikely(f.file->f_mode & FMODE_PATH)) {512 if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
513 if (!check_fcntl_cmd(cmd))513 if (!check_fcntl_cmd(cmd))
514 goto out1;514 goto out1;
515 }515 }
516 516
517 err = security_file_fcntl(f.file, cmd, arg);517 err = security_file_fcntl(fd_file(f), cmd, arg);
518 if (err)518 if (err)
519 goto out1;519 goto out1;
520 520
@@ -524,7 +524,7 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, · 3 unmodified lines
524 err = -EFAULT;524 err = -EFAULT;
525 if (copy_from_user(&flock, argp, sizeof(flock)))525 if (copy_from_user(&flock, argp, sizeof(flock)))
526 break;526 break;
527 err = fcntl_getlk64(f.file, cmd, &flock);527 err = fcntl_getlk64(fd_file(f), cmd, &flock);
528 if (!err && copy_to_user(argp, &flock, sizeof(flock)))528 if (!err && copy_to_user(argp, &flock, sizeof(flock)))
529 err = -EFAULT;529 err = -EFAULT;
530 break;530 break;
@@ -535,10 +535,10 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, · 4 unmodified lines
535 err = -EFAULT;535 err = -EFAULT;
536 if (copy_from_user(&flock, argp, sizeof(flock)))536 if (copy_from_user(&flock, argp, sizeof(flock)))
537 break;537 break;
538 err = fcntl_setlk64(fd, f.file, cmd, &flock);538 err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
539 break;539 break;
540 default:540 default:
541 err = do_fcntl(fd, cmd, arg, f.file);541 err = do_fcntl(fd, cmd, arg, fd_file(f));
542 break;542 break;
543 }543 }
544out1:544out1:
@@ -643,15 +643,15 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 98 unmodified lines
643 struct flock flock;643 struct flock flock;
644 long err = -EBADF;644 long err = -EBADF;
645 645
646 if (!f.file)646 if (!fd_file(f))
647 return err;647 return err;
648 648
649 if (unlikely(f.file->f_mode & FMODE_PATH)) {649 if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
650 if (!check_fcntl_cmd(cmd))650 if (!check_fcntl_cmd(cmd))
651 goto out_put;651 goto out_put;
652 }652 }
653 653
654 err = security_file_fcntl(f.file, cmd, arg);654 err = security_file_fcntl(fd_file(f), cmd, arg);
655 if (err)655 if (err)
656 goto out_put;656 goto out_put;
657 657
@@ -660,7 +660,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 2 unmodified lines
660 err = get_compat_flock(&flock, compat_ptr(arg));660 err = get_compat_flock(&flock, compat_ptr(arg));
661 if (err)661 if (err)
662 break;662 break;
663 err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock);663 err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock);
664 if (err)664 if (err)
665 break;665 break;
666 err = fixup_compat_flock(&flock);666 err = fixup_compat_flock(&flock);
@@ -672,7 +672,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 5 unmodified lines
672 err = get_compat_flock64(&flock, compat_ptr(arg));672 err = get_compat_flock64(&flock, compat_ptr(arg));
673 if (err)673 if (err)
674 break;674 break;
675 err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock);675 err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock);
676 if (!err)676 if (!err)
677 err = put_compat_flock64(&flock, compat_ptr(arg));677 err = put_compat_flock64(&flock, compat_ptr(arg));
678 break;678 break;
@@ -681,7 +681,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 2 unmodified lines
681 err = get_compat_flock(&flock, compat_ptr(arg));681 err = get_compat_flock(&flock, compat_ptr(arg));
682 if (err)682 if (err)
683 break;683 break;
684 err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock);684 err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock);
685 break;685 break;
686 case F_SETLK64:686 case F_SETLK64:
687 case F_SETLKW64:687 case F_SETLKW64:
@@ -690,10 +690,10 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd, · 2 unmodified lines
690 err = get_compat_flock64(&flock, compat_ptr(arg));690 err = get_compat_flock64(&flock, compat_ptr(arg));
691 if (err)691 if (err)
692 break;692 break;
693 err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock);693 err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock);
694 break;694 break;
695 default:695 default:
696 err = do_fcntl(fd, cmd, arg, f.file);696 err = do_fcntl(fd, cmd, arg, fd_file(f));
697 break;697 break;
698 }698 }
699out_put:699out_put:
fs/fhandle.c+2−2
@@ -125,9 +125,9 @@ static int get_path_from_fd(int fd, struct path *root) · 124 unmodified lines
125 spin_unlock(&fs->lock);125 spin_unlock(&fs->lock);
126 } else {126 } else {
127 struct fd f = fdget(fd);127 struct fd f = fdget(fd);
128 if (!f.file)128 if (!fd_file(f))
129 return -EBADF;129 return -EBADF;
130 *root = f.file->f_path;130 *root = fd_file(f)->f_path;
131 path_get(root);131 path_get(root);
132 fdput(f);132 fdput(f);
133 }133 }
fs/fsopen.c+3−3
@@ -394,13 +394,13 @@ SYSCALL_DEFINE5(fsconfig, · 393 unmodified lines
394 }394 }
395 395
396 f = fdget(fd);396 f = fdget(fd);
397 if (!f.file)397 if (!fd_file(f))
398 return -EBADF;398 return -EBADF;
399 ret = -EINVAL;399 ret = -EINVAL;
400 if (f.file->f_op != &fscontext_fops)400 if (fd_file(f)->f_op != &fscontext_fops)
401 goto out_f;401 goto out_f;
402 402
403 fc = f.file->private_data;403 fc = fd_file(f)->private_data;
404 if (fc->ops == &legacy_fs_context_ops) {404 if (fc->ops == &legacy_fs_context_ops) {
405 switch (cmd) {405 switch (cmd) {
406 case FSCONFIG_SET_BINARY:406 case FSCONFIG_SET_BINARY:
fs/fuse/dev.c+3−3
@@ -2321,15 +2321,15 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp) · 2320 unmodified lines
2321 return -EFAULT;2321 return -EFAULT;
2322 2322
2323 f = fdget(oldfd);2323 f = fdget(oldfd);
2324 if (!f.file)2324 if (!fd_file(f))
2325 return -EINVAL;2325 return -EINVAL;
2326 2326
2327 /*2327 /*
2328 * Check against file->f_op because CUSE2328 * Check against file->f_op because CUSE
2329 * uses the same ioctl handler.2329 * uses the same ioctl handler.
2330 */2330 */
2331 if (f.file->f_op == file->f_op)2331 if (fd_file(f)->f_op == file->f_op)
2332 fud = fuse_get_dev(f.file);2332 fud = fuse_get_dev(fd_file(f));
2333 2333
2334 res = -EINVAL;2334 res = -EINVAL;
2335 if (fud) {2335 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
235 loff_t cloned;235 loff_t cloned;
236 int ret;236 int ret;
237 237
238 if (!src_file.file)238 if (!fd_file(src_file))
239 return -EBADF;239 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,
241 olen, 0);241 olen, 0);
242 if (cloned < 0)242 if (cloned < 0)
243 ret = cloned;243 ret = cloned;
@@ -895,16 +895,16 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) · 651 unmodified lines
895 struct fd f = fdget(fd);895 struct fd f = fdget(fd);
896 int error;896 int error;
897 897
898 if (!f.file)898 if (!fd_file(f))
899 return -EBADF;899 return -EBADF;
900 900
901 error = security_file_ioctl(f.file, cmd, arg);901 error = security_file_ioctl(fd_file(f), cmd, arg);
902 if (error)902 if (error)
903 goto out;903 goto out;
904 904
905 error = do_vfs_ioctl(f.file, fd, cmd, arg);905 error = do_vfs_ioctl(fd_file(f), fd, cmd, arg);
906 if (error == -ENOIOCTLCMD)906 if (error == -ENOIOCTLCMD)
907 error = vfs_ioctl(f.file, cmd, arg);907 error = vfs_ioctl(fd_file(f), cmd, arg);
908 908
909out:909out:
910 fdput(f);910 fdput(f);
@@ -953,32 +953,32 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, · 42 unmodified lines
953 struct fd f = fdget(fd);953 struct fd f = fdget(fd);
954 int error;954 int error;
955 955
956 if (!f.file)956 if (!fd_file(f))
957 return -EBADF;957 return -EBADF;
958 958
959 error = security_file_ioctl_compat(f.file, cmd, arg);959 error = security_file_ioctl_compat(fd_file(f), cmd, arg);
960 if (error)960 if (error)
961 goto out;961 goto out;
962 962
963 switch (cmd) {963 switch (cmd) {
964 /* FICLONE takes an int argument, so don't use compat_ptr() */964 /* FICLONE takes an int argument, so don't use compat_ptr() */
965 case FICLONE:965 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);
967 break;967 break;
968 968
969#if defined(CONFIG_X86_64)969#if defined(CONFIG_X86_64)
970 /* these get messy on amd64 due to alignment differences */970 /* these get messy on amd64 due to alignment differences */
971 case FS_IOC_RESVSP_32:971 case FS_IOC_RESVSP_32:
972 case FS_IOC_RESVSP64_32:972 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));
974 break;974 break;
975 case FS_IOC_UNRESVSP_32:975 case FS_IOC_UNRESVSP_32:
976 case FS_IOC_UNRESVSP64_32:976 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,
978 compat_ptr(arg));978 compat_ptr(arg));
979 break;979 break;
980 case FS_IOC_ZERO_RANGE_32:980 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,
982 compat_ptr(arg));982 compat_ptr(arg));
983 break;983 break;
984#endif984#endif
@@ -998,13 +998,13 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, · 13 unmodified lines
998 * argument.998 * argument.
999 */999 */
1000 default:1000 default:
1001 error = do_vfs_ioctl(f.file, fd, cmd,1001 error = do_vfs_ioctl(fd_file(f), fd, cmd,
1002 (unsigned long)compat_ptr(arg));1002 (unsigned long)compat_ptr(arg));
1003 if (error != -ENOIOCTLCMD)1003 if (error != -ENOIOCTLCMD)
1004 break;1004 break;
1005 1005
1006 if (f.file->f_op->compat_ioctl)1006 if (fd_file(f)->f_op->compat_ioctl)
1007 error = f.file->f_op->compat_ioctl(f.file, cmd, arg);1007 error = fd_file(f)->f_op->compat_ioctl(fd_file(f), cmd, arg);
1008 if (error == -ENOIOCTLCMD)1008 if (error == -ENOIOCTLCMD)
1009 error = -ENOTTY;1009 error = -ENOTTY;
1010 break;1010 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
178 struct fd f = fdget(fd);178 struct fd f = fdget(fd);
179 ssize_t ret = -EBADF;179 ssize_t ret = -EBADF;
180 180
181 if (!f.file || !(f.file->f_mode & FMODE_READ))181 if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
182 goto out;182 goto out;
183 183
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);
185out:185out:
186 fdput(f);186 fdput(f);
187 return ret;187 return ret;
fs/locks.c+7−7
@@ -2153,15 +2153,15 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) · 2152 unmodified lines
2153 2153
2154 error = -EBADF;2154 error = -EBADF;
2155 f = fdget(fd);2155 f = fdget(fd);
2156 if (!f.file)2156 if (!fd_file(f))
2157 return error;2157 return error;
2158 2158
2159 if (type != F_UNLCK && !(f.file->f_mode & (FMODE_READ | FMODE_WRITE)))2159 if (type != F_UNLCK && !(fd_file(f)->f_mode & (FMODE_READ | FMODE_WRITE)))
2160 goto out_putf;2160 goto out_putf;
2161 2161
2162 flock_make_lock(f.file, &fl, type);2162 flock_make_lock(fd_file(f), &fl, type);
2163 2163
2164 error = security_file_lock(f.file, fl.c.flc_type);2164 error = security_file_lock(fd_file(f), fl.c.flc_type);
2165 if (error)2165 if (error)
2166 goto out_putf;2166 goto out_putf;
2167 2167
@@ -2169,12 +2169,12 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) · 1 unmodified line
2169 if (can_sleep)2169 if (can_sleep)
2170 fl.c.flc_flags |= FL_SLEEP;2170 fl.c.flc_flags |= FL_SLEEP;
2171 2171
2172 if (f.file->f_op->flock)2172 if (fd_file(f)->f_op->flock)
2173 error = f.file->f_op->flock(f.file,2173 error = fd_file(f)->f_op->flock(fd_file(f),
2174 (can_sleep) ? F_SETLKW : F_SETLK,2174 (can_sleep) ? F_SETLKW : F_SETLK,
2175 &fl);2175 &fl);
2176 else2176 else
2177 error = locks_lock_file_wait(f.file, &fl);2177 error = locks_lock_file_wait(fd_file(f), &fl);
2178 2178
2179 locks_release_private(&fl);2179 locks_release_private(&fl);
2180 out_putf:2180 out_putf:
fs/namei.c+5−5
@@ -2492,25 +2492,25 @@ static const char *path_init(struct nameidata *nd, unsigned flags) · 2491 unmodified lines
2492 struct fd f = fdget_raw(nd->dfd);2492 struct fd f = fdget_raw(nd->dfd);
2493 struct dentry *dentry;2493 struct dentry *dentry;
2494 2494
2495 if (!f.file)2495 if (!fd_file(f))
2496 return ERR_PTR(-EBADF);2496 return ERR_PTR(-EBADF);
2497 2497
2498 if (flags & LOOKUP_LINKAT_EMPTY) {2498 if (flags & LOOKUP_LINKAT_EMPTY) {
2499 if (f.file->f_cred != current_cred() &&2499 if (fd_file(f)->f_cred != current_cred() &&
2500 !ns_capable(f.file->f_cred->user_ns, CAP_DAC_READ_SEARCH)) {2500 !ns_capable(fd_file(f)->f_cred->user_ns, CAP_DAC_READ_SEARCH)) {
2501 fdput(f);2501 fdput(f);
2502 return ERR_PTR(-ENOENT);2502 return ERR_PTR(-ENOENT);
2503 }2503 }
2504 }2504 }
2505 2505
2506 dentry = f.file->f_path.dentry;2506 dentry = fd_file(f)->f_path.dentry;
2507 2507
2508 if (*s && unlikely(!d_can_lookup(dentry))) {2508 if (*s && unlikely(!d_can_lookup(dentry))) {
2509 fdput(f);2509 fdput(f);
2510 return ERR_PTR(-ENOTDIR);2510 return ERR_PTR(-ENOTDIR);
2511 }2511 }
2512 2512
2513 nd->path = f.file->f_path;2513 nd->path = fd_file(f)->f_path;
2514 if (flags & LOOKUP_RCU) {2514 if (flags & LOOKUP_RCU) {
2515 nd->inode = nd->path.dentry->d_inode;2515 nd->inode = nd->path.dentry->d_inode;
2516 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);2516 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
fs/namespace.c+6−6
@@ -4099,14 +4099,14 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags, · 4098 unmodified lines
4099 }4099 }
4100 4100
4101 f = fdget(fs_fd);4101 f = fdget(fs_fd);
4102 if (!f.file)4102 if (!fd_file(f))
4103 return -EBADF;4103 return -EBADF;
4104 4104
4105 ret = -EINVAL;4105 ret = -EINVAL;
4106 if (f.file->f_op != &fscontext_fops)4106 if (fd_file(f)->f_op != &fscontext_fops)
4107 goto err_fsfd;4107 goto err_fsfd;
4108 4108
4109 fc = f.file->private_data;4109 fc = fd_file(f)->private_data;
4110 4110
4111 ret = mutex_lock_interruptible(&fc->uapi_mutex);4111 ret = mutex_lock_interruptible(&fc->uapi_mutex);
4112 if (ret < 0)4112 if (ret < 0)
@@ -4649,15 +4649,15 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize, · 536 unmodified lines
4649 return -EINVAL;4649 return -EINVAL;
4650 4650
4651 f = fdget(attr->userns_fd);4651 f = fdget(attr->userns_fd);
4652 if (!f.file)4652 if (!fd_file(f))
4653 return -EBADF;4653 return -EBADF;
4654 4654
4655 if (!proc_ns_file(f.file)) {4655 if (!proc_ns_file(fd_file(f))) {
4656 err = -EINVAL;4656 err = -EINVAL;
4657 goto out_fput;4657 goto out_fput;
4658 }4658 }
4659 4659
4660 ns = get_proc_ns(file_inode(f.file));4660 ns = get_proc_ns(file_inode(fd_file(f)));
4661 if (ns->ops->type != CLONE_NEWUSER) {4661 if (ns->ops->type != CLONE_NEWUSER) {
4662 err = -EINVAL;4662 err = -EINVAL;
4663 goto out_fput;4663 goto out_fput;
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
1006 struct fd f = fdget(dfd);1006 struct fd f = fdget(dfd);
1007 1007
1008 ret = -EBADF;1008 ret = -EBADF;
1009 if (!f.file)1009 if (!fd_file(f))
1010 goto out;1010 goto out;
1011 1011
1012 ret = -ENOTDIR;1012 ret = -ENOTDIR;
1013 if ((flags & FAN_MARK_ONLYDIR) &&1013 if ((flags & FAN_MARK_ONLYDIR) &&
1014 !(S_ISDIR(file_inode(f.file)->i_mode))) {1014 !(S_ISDIR(file_inode(fd_file(f))->i_mode))) {
1015 fdput(f);1015 fdput(f);
1016 goto out;1016 goto out;
1017 }1017 }
1018 1018
1019 *path = f.file->f_path;1019 *path = fd_file(f)->f_path;
1020 path_get(path);1020 path_get(path);
1021 fdput(f);1021 fdput(f);
1022 } else {1022 } else {
@@ -1753,14 +1753,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, · 730 unmodified lines
1753 }1753 }
1754 1754
1755 f = fdget(fanotify_fd);1755 f = fdget(fanotify_fd);
1756 if (unlikely(!f.file))1756 if (unlikely(!fd_file(f)))
1757 return -EBADF;1757 return -EBADF;
1758 1758
1759 /* verify that this is indeed an fanotify instance */1759 /* verify that this is indeed an fanotify instance */
1760 ret = -EINVAL;1760 ret = -EINVAL;
1761 if (unlikely(f.file->f_op != &fanotify_fops))1761 if (unlikely(fd_file(f)->f_op != &fanotify_fops))
1762 goto fput_and_out;1762 goto fput_and_out;
1763 group = f.file->private_data;1763 group = fd_file(f)->private_data;
1764 1764
1765 /*1765 /*
1766 * An unprivileged user is not allowed to setup mount nor filesystem1766 * 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
753 return -EINVAL;753 return -EINVAL;
754 754
755 f = fdget(fd);755 f = fdget(fd);
756 if (unlikely(!f.file))756 if (unlikely(!fd_file(f)))
757 return -EBADF;757 return -EBADF;
758 758
759 /* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */759 /* 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
763 }763 }
764 764
765 /* verify that this is indeed an inotify instance */765 /* 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)) {
767 ret = -EINVAL;767 ret = -EINVAL;
768 goto fput_and_out;768 goto fput_and_out;
769 }769 }
@@ -780,7 +780,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname, · 10 unmodified lines
780 780
781 /* inode held in place by reference to path; group by fget on fd */781 /* inode held in place by reference to path; group by fget on fd */
782 inode = path.dentry->d_inode;782 inode = path.dentry->d_inode;
783 group = f.file->private_data;783 group = fd_file(f)->private_data;
784 784
785 /* create/update an inode mark */785 /* create/update an inode mark */
786 ret = inotify_update_watch(group, inode, mask);786 ret = inotify_update_watch(group, inode, mask);
@@ -798,14 +798,14 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd) · 11 unmodified lines
798 int ret = -EINVAL;798 int ret = -EINVAL;
799 799
800 f = fdget(fd);800 f = fdget(fd);
801 if (unlikely(!f.file))801 if (unlikely(!fd_file(f)))
802 return -EBADF;802 return -EBADF;
803 803
804 /* verify that this is indeed an inotify instance */804 /* 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))
806 goto out;806 goto out;
807 807
808 group = f.file->private_data;808 group = fd_file(f)->private_data;
809 809
810 i_mark = inotify_idr_find(group, wd);810 i_mark = inotify_idr_find(group, wd);
811 if (unlikely(!i_mark))811 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
1785 goto out;1785 goto out;
1786 1786
1787 f = fdget(fd);1787 f = fdget(fd);
1788 if (f.file == NULL)1788 if (fd_file(f) == NULL)
1789 goto out;1789 goto out;
1790 1790
1791 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||1791 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||
1792 reg->hr_block_bytes == 0)1792 reg->hr_block_bytes == 0)
1793 goto out2;1793 goto out2;
1794 1794
1795 if (!S_ISBLK(f.file->f_mapping->host->i_mode))1795 if (!S_ISBLK(fd_file(f)->f_mapping->host->i_mode))
1796 goto out2;1796 goto out2;
1797 1797
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,
1799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);1799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);
1800 if (IS_ERR(reg->hr_bdev_file)) {1800 if (IS_ERR(reg->hr_bdev_file)) {
1801 ret = PTR_ERR(reg->hr_bdev_file);1801 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
193 if (length < 0)193 if (length < 0)
194 return -EINVAL;194 return -EINVAL;
195 f = fdget(fd);195 f = fdget(fd);
196 if (!f.file)196 if (!fd_file(f))
197 return -EBADF;197 return -EBADF;
198 198
199 error = do_ftruncate(f.file, length, small);199 error = do_ftruncate(fd_file(f), length, small);
200 200
201 fdput(f);201 fdput(f);
202 return error;202 return error;
@@ -353,8 +353,8 @@ int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len) · 150 unmodified lines
353 struct fd f = fdget(fd);353 struct fd f = fdget(fd);
354 int error = -EBADF;354 int error = -EBADF;
355 355
356 if (f.file) {356 if (fd_file(f)) {
357 error = vfs_fallocate(f.file, mode, offset, len);357 error = vfs_fallocate(fd_file(f), mode, offset, len);
358 fdput(f);358 fdput(f);
359 }359 }
360 return error;360 return error;
@@ -585,16 +585,16 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd) · 224 unmodified lines
585 int error;585 int error;
586 586
587 error = -EBADF;587 error = -EBADF;
588 if (!f.file)588 if (!fd_file(f))
589 goto out;589 goto out;
590 590
591 error = -ENOTDIR;591 error = -ENOTDIR;
592 if (!d_can_lookup(f.file->f_path.dentry))592 if (!d_can_lookup(fd_file(f)->f_path.dentry))
593 goto out_putf;593 goto out_putf;
594 594
595 error = file_permission(f.file, MAY_EXEC | MAY_CHDIR);595 error = file_permission(fd_file(f), MAY_EXEC | MAY_CHDIR);
596 if (!error)596 if (!error)
597 set_fs_pwd(current->fs, &f.file->f_path);597 set_fs_pwd(current->fs, &fd_file(f)->f_path);
598out_putf:598out_putf:
599 fdput(f);599 fdput(f);
600out:600out:
@@ -675,8 +675,8 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode) · 74 unmodified lines
675 struct fd f = fdget(fd);675 struct fd f = fdget(fd);
676 int err = -EBADF;676 int err = -EBADF;
677 677
678 if (f.file) {678 if (fd_file(f)) {
679 err = vfs_fchmod(f.file, mode);679 err = vfs_fchmod(fd_file(f), mode);
680 fdput(f);680 fdput(f);
681 }681 }
682 return err;682 return err;
@@ -869,8 +869,8 @@ int ksys_fchown(unsigned int fd, uid_t user, gid_t group) · 186 unmodified lines
869 struct fd f = fdget(fd);869 struct fd f = fdget(fd);
870 int error = -EBADF;870 int error = -EBADF;
871 871
872 if (f.file) {872 if (fd_file(f)) {
873 error = vfs_fchown(f.file, user, group);873 error = vfs_fchown(fd_file(f), user, group);
874 fdput(f);874 fdput(f);
875 }875 }
876 return error;876 return error;
fs/overlayfs/file.c+20−20
@@ -209,13 +209,13 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence) · 208 unmodified lines
209 * files, so we use the real file to perform seeks.209 * files, so we use the real file to perform seeks.
210 */210 */
211 ovl_inode_lock(inode);211 ovl_inode_lock(inode);
212 real.file->f_pos = file->f_pos;212 fd_file(real)->f_pos = file->f_pos;
213 213
214 old_cred = ovl_override_creds(inode->i_sb);214 old_cred = ovl_override_creds(inode->i_sb);
215 ret = vfs_llseek(real.file, offset, whence);215 ret = vfs_llseek(fd_file(real), offset, whence);
216 revert_creds(old_cred);216 revert_creds(old_cred);
217 217
218 file->f_pos = real.file->f_pos;218 file->f_pos = fd_file(real)->f_pos;
219 ovl_inode_unlock(inode);219 ovl_inode_unlock(inode);
220 220
221 fdput(real);221 fdput(real);
@@ -275,7 +275,7 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) · 53 unmodified lines
275 if (ret)275 if (ret)
276 return ret;276 return ret;
277 277
278 ret = backing_file_read_iter(real.file, iter, iocb, iocb->ki_flags,278 ret = backing_file_read_iter(fd_file(real), iter, iocb, iocb->ki_flags,
279 &ctx);279 &ctx);
280 fdput(real);280 fdput(real);
281 281
@@ -314,7 +314,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) · 32 unmodified lines
314 * this property in case it is set by the issuer.314 * this property in case it is set by the issuer.
315 */315 */
316 ifl &= ~IOCB_DIO_CALLER_COMP;316 ifl &= ~IOCB_DIO_CALLER_COMP;
317 ret = backing_file_write_iter(real.file, iter, iocb, ifl, &ctx);317 ret = backing_file_write_iter(fd_file(real), iter, iocb, ifl, &ctx);
318 fdput(real);318 fdput(real);
319 319
320out_unlock:320out_unlock:
@@ -339,7 +339,7 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, · 18 unmodified lines
339 if (ret)339 if (ret)
340 return ret;340 return ret;
341 341
342 ret = backing_file_splice_read(real.file, ppos, pipe, len, flags, &ctx);342 ret = backing_file_splice_read(fd_file(real), ppos, pipe, len, flags, &ctx);
343 fdput(real);343 fdput(real);
344 344
345 return ret;345 return ret;
@@ -348,7 +348,7 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos, · 2 unmodified lines
348/*348/*
349 * Calling iter_file_splice_write() directly from overlay's f_op may deadlock349 * Calling iter_file_splice_write() directly from overlay's f_op may deadlock
350 * due to lock order inversion between pipe->mutex in iter_file_splice_write()350 * due to lock order inversion between pipe->mutex in iter_file_splice_write()
351 * and file_start_write(real.file) in ovl_write_iter().351 * and file_start_write(fd_file(real)) in ovl_write_iter().
352 *352 *
353 * So do everything ovl_write_iter() does and call iter_file_splice_write() on353 * So do everything ovl_write_iter() does and call iter_file_splice_write() on
354 * the real file.354 * the real file.
@@ -373,7 +373,7 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out, · 18 unmodified lines
373 if (ret)373 if (ret)
374 goto out_unlock;374 goto out_unlock;
375 375
376 ret = backing_file_splice_write(pipe, real.file, ppos, len, flags, &ctx);376 ret = backing_file_splice_write(pipe, fd_file(real), ppos, len, flags, &ctx);
377 fdput(real);377 fdput(real);
378 378
379out_unlock:379out_unlock:
@@ -397,9 +397,9 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) · 17 unmodified lines
397 return ret;397 return ret;
398 398
399 /* Don't sync lower file for fear of receiving EROFS error */399 /* Don't sync lower file for fear of receiving EROFS error */
400 if (file_inode(real.file) == ovl_inode_upper(file_inode(file))) {400 if (file_inode(fd_file(real)) == ovl_inode_upper(file_inode(file))) {
401 old_cred = ovl_override_creds(file_inode(file)->i_sb);401 old_cred = ovl_override_creds(file_inode(file)->i_sb);
402 ret = vfs_fsync_range(real.file, start, end, datasync);402 ret = vfs_fsync_range(fd_file(real), start, end, datasync);
403 revert_creds(old_cred);403 revert_creds(old_cred);
404 }404 }
405 405
@@ -439,7 +439,7 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len · 33 unmodified lines
439 goto out_unlock;439 goto out_unlock;
440 440
441 old_cred = ovl_override_creds(file_inode(file)->i_sb);441 old_cred = ovl_override_creds(file_inode(file)->i_sb);
442 ret = vfs_fallocate(real.file, mode, offset, len);442 ret = vfs_fallocate(fd_file(real), mode, offset, len);
443 revert_creds(old_cred);443 revert_creds(old_cred);
444 444
445 /* Update size */445 /* Update size */
@@ -464,7 +464,7 @@ static int ovl_fadvise(struct file *file, loff_t offset, loff_t len, int advice) · 18 unmodified lines
464 return ret;464 return ret;
465 465
466 old_cred = ovl_override_creds(file_inode(file)->i_sb);466 old_cred = ovl_override_creds(file_inode(file)->i_sb);
467 ret = vfs_fadvise(real.file, offset, len, advice);467 ret = vfs_fadvise(fd_file(real), offset, len, advice);
468 revert_creds(old_cred);468 revert_creds(old_cred);
469 469
470 fdput(real);470 fdput(real);
@@ -509,18 +509,18 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in, · 38 unmodified lines
509 old_cred = ovl_override_creds(file_inode(file_out)->i_sb);509 old_cred = ovl_override_creds(file_inode(file_out)->i_sb);
510 switch (op) {510 switch (op) {
511 case OVL_COPY:511 case OVL_COPY:
512 ret = vfs_copy_file_range(real_in.file, pos_in,512 ret = vfs_copy_file_range(fd_file(real_in), pos_in,
513 real_out.file, pos_out, len, flags);513 fd_file(real_out), pos_out, len, flags);
514 break;514 break;
515 515
516 case OVL_CLONE:516 case OVL_CLONE:
517 ret = vfs_clone_file_range(real_in.file, pos_in,517 ret = vfs_clone_file_range(fd_file(real_in), pos_in,
518 real_out.file, pos_out, len, flags);518 fd_file(real_out), pos_out, len, flags);
519 break;519 break;
520 520
521 case OVL_DEDUPE:521 case OVL_DEDUPE:
522 ret = vfs_dedupe_file_range_one(real_in.file, pos_in,522 ret = vfs_dedupe_file_range_one(fd_file(real_in), pos_in,
523 real_out.file, pos_out, len,523 fd_file(real_out), pos_out, len,
524 flags);524 flags);
525 break;525 break;
526 }526 }
@@ -583,9 +583,9 @@ static int ovl_flush(struct file *file, fl_owner_t id) · 56 unmodified lines
583 if (err)583 if (err)
584 return err;584 return err;
585 585
586 if (real.file->f_op->flush) {586 if (fd_file(real)->f_op->flush) {
587 old_cred = ovl_override_creds(file_inode(file)->i_sb);587 old_cred = ovl_override_creds(file_inode(file)->i_sb);
588 err = real.file->f_op->flush(real.file, id);588 err = fd_file(real)->f_op->flush(fd_file(real), id);
589 revert_creds(old_cred);589 revert_creds(old_cred);
590 }590 }
591 fdput(real);591 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
980 int ret;980 int ret;
981 981
982 f = fdget_raw(fd);982 f = fdget_raw(fd);
983 if (!f.file)983 if (!fd_file(f))
984 return -EBADF;984 return -EBADF;
985 985
986 ret = -EINVAL;986 ret = -EINVAL;
@@ -988,12 +988,12 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd, · 1 unmodified line
988 goto out;988 goto out;
989 989
990 if (quotactl_cmd_write(cmds)) {990 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);
992 if (ret)992 if (ret)
993 goto out;993 goto out;
994 }994 }
995 995
996 sb = f.file->f_path.mnt->mnt_sb;996 sb = fd_file(f)->f_path.mnt->mnt_sb;
997 if (quotactl_cmd_onoff(cmds))997 if (quotactl_cmd_onoff(cmds))
998 down_write(&sb->s_umount);998 down_write(&sb->s_umount);
999 else999 else
@@ -1007,7 +1007,7 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd, · 7 unmodified lines
1007 up_read(&sb->s_umount);1007 up_read(&sb->s_umount);
1008 1008
1009 if (quotactl_cmd_write(cmds))1009 if (quotactl_cmd_write(cmds))
1010 mnt_drop_write(f.file->f_path.mnt);1010 mnt_drop_write(fd_file(f)->f_path.mnt);
1011out:1011out:
1012 fdput(f);1012 fdput(f);
1013 return ret;1013 return ret;
fs/read_write.c+59−59
@@ -294,12 +294,12 @@ static off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence) · 293 unmodified lines
294{294{
295 off_t retval;295 off_t retval;
296 struct fd f = fdget_pos(fd);296 struct fd f = fdget_pos(fd);
297 if (!f.file)297 if (!fd_file(f))
298 return -EBADF;298 return -EBADF;
299 299
300 retval = -EINVAL;300 retval = -EINVAL;
301 if (whence <= SEEK_MAX) {301 if (whence <= SEEK_MAX) {
302 loff_t res = vfs_llseek(f.file, offset, whence);302 loff_t res = vfs_llseek(fd_file(f), offset, whence);
303 retval = res;303 retval = res;
304 if (res != (loff_t)retval)304 if (res != (loff_t)retval)
305 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */305 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
@@ -330,14 +330,14 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high, · 24 unmodified lines
330 struct fd f = fdget_pos(fd);330 struct fd f = fdget_pos(fd);
331 loff_t offset;331 loff_t offset;
332 332
333 if (!f.file)333 if (!fd_file(f))
334 return -EBADF;334 return -EBADF;
335 335
336 retval = -EINVAL;336 retval = -EINVAL;
337 if (whence > SEEK_MAX)337 if (whence > SEEK_MAX)
338 goto out_putf;338 goto out_putf;
339 339
340 offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,340 offset = vfs_llseek(fd_file(f), ((loff_t) offset_high << 32) | offset_low,
341 whence);341 whence);
342 342
343 retval = (int)offset;343 retval = (int)offset;
@@ -610,15 +610,15 @@ ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count) · 266 unmodified lines
610 struct fd f = fdget_pos(fd);610 struct fd f = fdget_pos(fd);
611 ssize_t ret = -EBADF;611 ssize_t ret = -EBADF;
612 612
613 if (f.file) {613 if (fd_file(f)) {
614 loff_t pos, *ppos = file_ppos(f.file);614 loff_t pos, *ppos = file_ppos(fd_file(f));
615 if (ppos) {615 if (ppos) {
616 pos = *ppos;616 pos = *ppos;
617 ppos = &pos;617 ppos = &pos;
618 }618 }
619 ret = vfs_read(f.file, buf, count, ppos);619 ret = vfs_read(fd_file(f), buf, count, ppos);
620 if (ret >= 0 && ppos)620 if (ret >= 0 && ppos)
621 f.file->f_pos = pos;621 fd_file(f)->f_pos = pos;
622 fdput_pos(f);622 fdput_pos(f);
623 }623 }
624 return ret;624 return ret;
@@ -634,15 +634,15 @@ ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count) · 9 unmodified lines
634 struct fd f = fdget_pos(fd);634 struct fd f = fdget_pos(fd);
635 ssize_t ret = -EBADF;635 ssize_t ret = -EBADF;
636 636
637 if (f.file) {637 if (fd_file(f)) {
638 loff_t pos, *ppos = file_ppos(f.file);638 loff_t pos, *ppos = file_ppos(fd_file(f));
639 if (ppos) {639 if (ppos) {
640 pos = *ppos;640 pos = *ppos;
641 ppos = &pos;641 ppos = &pos;
642 }642 }
643 ret = vfs_write(f.file, buf, count, ppos);643 ret = vfs_write(fd_file(f), buf, count, ppos);
644 if (ret >= 0 && ppos)644 if (ret >= 0 && ppos)
645 f.file->f_pos = pos;645 fd_file(f)->f_pos = pos;
646 fdput_pos(f);646 fdput_pos(f);
647 }647 }
648 648
@@ -665,10 +665,10 @@ ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count, · 16 unmodified lines
665 return -EINVAL;665 return -EINVAL;
666 666
667 f = fdget(fd);667 f = fdget(fd);
668 if (f.file) {668 if (fd_file(f)) {
669 ret = -ESPIPE;669 ret = -ESPIPE;
670 if (f.file->f_mode & FMODE_PREAD)670 if (fd_file(f)->f_mode & FMODE_PREAD)
671 ret = vfs_read(f.file, buf, count, &pos);671 ret = vfs_read(fd_file(f), buf, count, &pos);
672 fdput(f);672 fdput(f);
673 }673 }
674 674
@@ -699,10 +699,10 @@ ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf, · 24 unmodified lines
699 return -EINVAL;699 return -EINVAL;
700 700
701 f = fdget(fd);701 f = fdget(fd);
702 if (f.file) {702 if (fd_file(f)) {
703 ret = -ESPIPE;703 ret = -ESPIPE;
704 if (f.file->f_mode & FMODE_PWRITE) 704 if (fd_file(f)->f_mode & FMODE_PWRITE)
705 ret = vfs_write(f.file, buf, count, &pos);705 ret = vfs_write(fd_file(f), buf, count, &pos);
706 fdput(f);706 fdput(f);
707 }707 }
708 708
@@ -985,15 +985,15 @@ static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec, · 276 unmodified lines
985 struct fd f = fdget_pos(fd);985 struct fd f = fdget_pos(fd);
986 ssize_t ret = -EBADF;986 ssize_t ret = -EBADF;
987 987
988 if (f.file) {988 if (fd_file(f)) {
989 loff_t pos, *ppos = file_ppos(f.file);989 loff_t pos, *ppos = file_ppos(fd_file(f));
990 if (ppos) {990 if (ppos) {
991 pos = *ppos;991 pos = *ppos;
992 ppos = &pos;992 ppos = &pos;
993 }993 }
994 ret = vfs_readv(f.file, vec, vlen, ppos, flags);994 ret = vfs_readv(fd_file(f), vec, vlen, ppos, flags);
995 if (ret >= 0 && ppos)995 if (ret >= 0 && ppos)
996 f.file->f_pos = pos;996 fd_file(f)->f_pos = pos;
997 fdput_pos(f);997 fdput_pos(f);
998 }998 }
999 999
@@ -1009,15 +1009,15 @@ static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec, · 9 unmodified lines
1009 struct fd f = fdget_pos(fd);1009 struct fd f = fdget_pos(fd);
1010 ssize_t ret = -EBADF;1010 ssize_t ret = -EBADF;
1011 1011
1012 if (f.file) {1012 if (fd_file(f)) {
1013 loff_t pos, *ppos = file_ppos(f.file);1013 loff_t pos, *ppos = file_ppos(fd_file(f));
1014 if (ppos) {1014 if (ppos) {
1015 pos = *ppos;1015 pos = *ppos;
1016 ppos = &pos;1016 ppos = &pos;
1017 }1017 }
1018 ret = vfs_writev(f.file, vec, vlen, ppos, flags);1018 ret = vfs_writev(fd_file(f), vec, vlen, ppos, flags);
1019 if (ret >= 0 && ppos)1019 if (ret >= 0 && ppos)
1020 f.file->f_pos = pos;1020 fd_file(f)->f_pos = pos;
1021 fdput_pos(f);1021 fdput_pos(f);
1022 }1022 }
1023 1023
@@ -1043,10 +1043,10 @@ static ssize_t do_preadv(unsigned long fd, const struct iovec __user *vec, · 19 unmodified lines
1043 return -EINVAL;1043 return -EINVAL;
1044 1044
1045 f = fdget(fd);1045 f = fdget(fd);
1046 if (f.file) {1046 if (fd_file(f)) {
1047 ret = -ESPIPE;1047 ret = -ESPIPE;
1048 if (f.file->f_mode & FMODE_PREAD)1048 if (fd_file(f)->f_mode & FMODE_PREAD)
1049 ret = vfs_readv(f.file, vec, vlen, &pos, flags);1049 ret = vfs_readv(fd_file(f), vec, vlen, &pos, flags);
1050 fdput(f);1050 fdput(f);
1051 }1051 }
1052 1052
@@ -1066,10 +1066,10 @@ static ssize_t do_pwritev(unsigned long fd, const struct iovec __user *vec, · 13 unmodified lines
1066 return -EINVAL;1066 return -EINVAL;
1067 1067
1068 f = fdget(fd);1068 f = fdget(fd);
1069 if (f.file) {1069 if (fd_file(f)) {
1070 ret = -ESPIPE;1070 ret = -ESPIPE;
1071 if (f.file->f_mode & FMODE_PWRITE)1071 if (fd_file(f)->f_mode & FMODE_PWRITE)
1072 ret = vfs_writev(f.file, vec, vlen, &pos, flags);1072 ret = vfs_writev(fd_file(f), vec, vlen, &pos, flags);
1073 fdput(f);1073 fdput(f);
1074 }1074 }
1075 1075
@@ -1235,19 +1235,19 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, · 159 unmodified lines
1235 */1235 */
1236 retval = -EBADF;1236 retval = -EBADF;
1237 in = fdget(in_fd);1237 in = fdget(in_fd);
1238 if (!in.file)1238 if (!fd_file(in))
1239 goto out;1239 goto out;
1240 if (!(in.file->f_mode & FMODE_READ))1240 if (!(fd_file(in)->f_mode & FMODE_READ))
1241 goto fput_in;1241 goto fput_in;
1242 retval = -ESPIPE;1242 retval = -ESPIPE;
1243 if (!ppos) {1243 if (!ppos) {
1244 pos = in.file->f_pos;1244 pos = fd_file(in)->f_pos;
1245 } else {1245 } else {
1246 pos = *ppos;1246 pos = *ppos;
1247 if (!(in.file->f_mode & FMODE_PREAD))1247 if (!(fd_file(in)->f_mode & FMODE_PREAD))
1248 goto fput_in;1248 goto fput_in;
1249 }1249 }
1250 retval = rw_verify_area(READ, in.file, &pos, count);1250 retval = rw_verify_area(READ, fd_file(in), &pos, count);
1251 if (retval < 0)1251 if (retval < 0)
1252 goto fput_in;1252 goto fput_in;
1253 if (count > MAX_RW_COUNT)1253 if (count > MAX_RW_COUNT)
@@ -1258,13 +1258,13 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, · 4 unmodified lines
1258 */1258 */
1259 retval = -EBADF;1259 retval = -EBADF;
1260 out = fdget(out_fd);1260 out = fdget(out_fd);
1261 if (!out.file)1261 if (!fd_file(out))
1262 goto fput_in;1262 goto fput_in;
1263 if (!(out.file->f_mode & FMODE_WRITE))1263 if (!(fd_file(out)->f_mode & FMODE_WRITE))
1264 goto fput_out;1264 goto fput_out;
1265 in_inode = file_inode(in.file);1265 in_inode = file_inode(fd_file(in));
1266 out_inode = file_inode(out.file);1266 out_inode = file_inode(fd_file(out));
1267 out_pos = out.file->f_pos;1267 out_pos = fd_file(out)->f_pos;
1268 1268
1269 if (!max)1269 if (!max)
1270 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);1270 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
@@ -1284,33 +1284,33 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, · 13 unmodified lines
1284 * and the application is arguably buggy if it doesn't expect1284 * and the application is arguably buggy if it doesn't expect
1285 * EAGAIN on a non-blocking file descriptor.1285 * EAGAIN on a non-blocking file descriptor.
1286 */1286 */
1287 if (in.file->f_flags & O_NONBLOCK)1287 if (fd_file(in)->f_flags & O_NONBLOCK)
1288 fl = SPLICE_F_NONBLOCK;1288 fl = SPLICE_F_NONBLOCK;
1289#endif1289#endif
1290 opipe = get_pipe_info(out.file, true);1290 opipe = get_pipe_info(fd_file(out), true);
1291 if (!opipe) {1291 if (!opipe) {
1292 retval = rw_verify_area(WRITE, out.file, &out_pos, count);1292 retval = rw_verify_area(WRITE, fd_file(out), &out_pos, count);
1293 if (retval < 0)1293 if (retval < 0)
1294 goto fput_out;1294 goto fput_out;
1295 retval = do_splice_direct(in.file, &pos, out.file, &out_pos,1295 retval = do_splice_direct(fd_file(in), &pos, fd_file(out), &out_pos,
1296 count, fl);1296 count, fl);
1297 } else {1297 } else {
1298 if (out.file->f_flags & O_NONBLOCK)1298 if (fd_file(out)->f_flags & O_NONBLOCK)
1299 fl |= SPLICE_F_NONBLOCK;1299 fl |= SPLICE_F_NONBLOCK;
1300 1300
1301 retval = splice_file_to_pipe(in.file, opipe, &pos, count, fl);1301 retval = splice_file_to_pipe(fd_file(in), opipe, &pos, count, fl);
1302 }1302 }
1303 1303
1304 if (retval > 0) {1304 if (retval > 0) {
1305 add_rchar(current, retval);1305 add_rchar(current, retval);
1306 add_wchar(current, retval);1306 add_wchar(current, retval);
1307 fsnotify_access(in.file);1307 fsnotify_access(fd_file(in));
1308 fsnotify_modify(out.file);1308 fsnotify_modify(fd_file(out));
1309 out.file->f_pos = out_pos;1309 fd_file(out)->f_pos = out_pos;
1310 if (ppos)1310 if (ppos)
1311 *ppos = pos;1311 *ppos = pos;
1312 else1312 else
1313 in.file->f_pos = pos;1313 fd_file(in)->f_pos = pos;
1314 }1314 }
1315 1315
1316 inc_syscr(current);1316 inc_syscr(current);
@@ -1583,11 +1583,11 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, · 266 unmodified lines
1583 ssize_t ret = -EBADF;1583 ssize_t ret = -EBADF;
1584 1584
1585 f_in = fdget(fd_in);1585 f_in = fdget(fd_in);
1586 if (!f_in.file)1586 if (!fd_file(f_in))
1587 goto out2;1587 goto out2;
1588 1588
1589 f_out = fdget(fd_out);1589 f_out = fdget(fd_out);
1590 if (!f_out.file)1590 if (!fd_file(f_out))
1591 goto out1;1591 goto out1;
1592 1592
1593 ret = -EFAULT;1593 ret = -EFAULT;
@@ -1595,21 +1595,21 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, · 1 unmodified line
1595 if (copy_from_user(&pos_in, off_in, sizeof(loff_t)))1595 if (copy_from_user(&pos_in, off_in, sizeof(loff_t)))
1596 goto out;1596 goto out;
1597 } else {1597 } else {
1598 pos_in = f_in.file->f_pos;1598 pos_in = fd_file(f_in)->f_pos;
1599 }1599 }
1600 1600
1601 if (off_out) {1601 if (off_out) {
1602 if (copy_from_user(&pos_out, off_out, sizeof(loff_t)))1602 if (copy_from_user(&pos_out, off_out, sizeof(loff_t)))
1603 goto out;1603 goto out;
1604 } else {1604 } else {
1605 pos_out = f_out.file->f_pos;1605 pos_out = fd_file(f_out)->f_pos;
1606 }1606 }
1607 1607
1608 ret = -EINVAL;1608 ret = -EINVAL;
1609 if (flags != 0)1609 if (flags != 0)
1610 goto out;1610 goto out;
1611 1611
1612 ret = vfs_copy_file_range(f_in.file, pos_in, f_out.file, pos_out, len,1612 ret = vfs_copy_file_range(fd_file(f_in), pos_in, fd_file(f_out), pos_out, len,
1613 flags);1613 flags);
1614 if (ret > 0) {1614 if (ret > 0) {
1615 pos_in += ret;1615 pos_in += ret;
@@ -1619,14 +1619,14 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in, · 3 unmodified lines
1619 if (copy_to_user(off_in, &pos_in, sizeof(loff_t)))1619 if (copy_to_user(off_in, &pos_in, sizeof(loff_t)))
1620 ret = -EFAULT;1620 ret = -EFAULT;
1621 } else {1621 } else {
1622 f_in.file->f_pos = pos_in;1622 fd_file(f_in)->f_pos = pos_in;
1623 }1623 }
1624 1624
1625 if (off_out) {1625 if (off_out) {
1626 if (copy_to_user(off_out, &pos_out, sizeof(loff_t)))1626 if (copy_to_user(off_out, &pos_out, sizeof(loff_t)))
1627 ret = -EFAULT;1627 ret = -EFAULT;
1628 } else {1628 } else {
1629 f_out.file->f_pos = pos_out;1629 fd_file(f_out)->f_pos = pos_out;
1630 }1630 }
1631 }1631 }
1632 1632
fs/readdir.c+10−10
@@ -225,10 +225,10 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd, · 224 unmodified lines
225 .dirent = dirent225 .dirent = dirent
226 };226 };
227 227
228 if (!f.file)228 if (!fd_file(f))
229 return -EBADF;229 return -EBADF;
230 230
231 error = iterate_dir(f.file, &buf.ctx);231 error = iterate_dir(fd_file(f), &buf.ctx);
232 if (buf.result)232 if (buf.result)
233 error = buf.result;233 error = buf.result;
234 234
@@ -318,10 +318,10 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd, · 83 unmodified lines
318 int error;318 int error;
319 319
320 f = fdget_pos(fd);320 f = fdget_pos(fd);
321 if (!f.file)321 if (!fd_file(f))
322 return -EBADF;322 return -EBADF;
323 323
324 error = iterate_dir(f.file, &buf.ctx);324 error = iterate_dir(fd_file(f), &buf.ctx);
325 if (error >= 0)325 if (error >= 0)
326 error = buf.error;326 error = buf.error;
327 if (buf.prev_reclen) {327 if (buf.prev_reclen) {
@@ -401,10 +401,10 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, · 73 unmodified lines
401 int error;401 int error;
402 402
403 f = fdget_pos(fd);403 f = fdget_pos(fd);
404 if (!f.file)404 if (!fd_file(f))
405 return -EBADF;405 return -EBADF;
406 406
407 error = iterate_dir(f.file, &buf.ctx);407 error = iterate_dir(fd_file(f), &buf.ctx);
408 if (error >= 0)408 if (error >= 0)
409 error = buf.error;409 error = buf.error;
410 if (buf.prev_reclen) {410 if (buf.prev_reclen) {
@@ -483,10 +483,10 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd, · 72 unmodified lines
483 .dirent = dirent483 .dirent = dirent
484 };484 };
485 485
486 if (!f.file)486 if (!fd_file(f))
487 return -EBADF;487 return -EBADF;
488 488
489 error = iterate_dir(f.file, &buf.ctx);489 error = iterate_dir(fd_file(f), &buf.ctx);
490 if (buf.result)490 if (buf.result)
491 error = buf.result;491 error = buf.result;
492 492
@@ -569,10 +569,10 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd, · 76 unmodified lines
569 int error;569 int error;
570 570
571 f = fdget_pos(fd);571 f = fdget_pos(fd);
572 if (!f.file)572 if (!fd_file(f))
573 return -EBADF;573 return -EBADF;
574 574
575 error = iterate_dir(f.file, &buf.ctx);575 error = iterate_dir(fd_file(f), &buf.ctx);
576 if (error >= 0)576 if (error >= 0)
577 error = buf.error;577 error = buf.error;
578 if (buf.prev_reclen) {578 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
537 537
538 for (i = 0, info = same->info; i < count; i++, info++) {538 for (i = 0, info = same->info; i < count; i++, info++) {
539 struct fd dst_fd = fdget(info->dest_fd);539 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);
541 541
542 if (!dst_file) {542 if (!dst_file) {
543 info->status = -EBADF;543 info->status = -EBADF;
fs/select.c+4−4
@@ -532,10 +532,10 @@ static noinline_for_stack int do_select(int n, fd_set_bits *fds, struct timespec · 531 unmodified lines
532 continue;532 continue;
533 mask = EPOLLNVAL;533 mask = EPOLLNVAL;
534 f = fdget(i);534 f = fdget(i);
535 if (f.file) {535 if (fd_file(f)) {
536 wait_key_set(wait, in, out, bit,536 wait_key_set(wait, in, out, bit,
537 busy_flag);537 busy_flag);
538 mask = vfs_poll(f.file, wait);538 mask = vfs_poll(fd_file(f), wait);
539 539
540 fdput(f);540 fdput(f);
541 }541 }
@@ -864,13 +864,13 @@ static inline __poll_t do_pollfd(struct pollfd *pollfd, poll_table *pwait, · 322 unmodified lines
864 goto out;864 goto out;
865 mask = EPOLLNVAL;865 mask = EPOLLNVAL;
866 f = fdget(fd);866 f = fdget(fd);
867 if (!f.file)867 if (!fd_file(f))
868 goto out;868 goto out;
869 869
870 /* userland u16 ->events contains POLL... bitmap */870 /* userland u16 ->events contains POLL... bitmap */
871 filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP;871 filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP;
872 pwait->_key = filter | busy_flag;872 pwait->_key = filter | busy_flag;
873 mask = vfs_poll(f.file, pwait);873 mask = vfs_poll(fd_file(f), pwait);
874 if (mask & busy_flag)874 if (mask & busy_flag)
875 *can_busy_poll = true;875 *can_busy_poll = true;
876 mask &= filter; /* Mask out unneeded events. */876 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
289 fd_install(ufd, file);289 fd_install(ufd, file);
290 } else {290 } else {
291 struct fd f = fdget(ufd);291 struct fd f = fdget(ufd);
292 if (!f.file)292 if (!fd_file(f))
293 return -EBADF;293 return -EBADF;
294 ctx = f.file->private_data;294 ctx = fd_file(f)->private_data;
295 if (f.file->f_op != &signalfd_fops) {295 if (fd_file(f)->f_op != &signalfd_fops) {
296 fdput(f);296 fdput(f);
297 return -EINVAL;297 return -EINVAL;
298 }298 }
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
90 }90 }
91 91
92 src_file = fdget(srcfd);92 src_file = fdget(srcfd);
93 if (!src_file.file) {93 if (!fd_file(src_file)) {
94 rc = -EBADF;94 rc = -EBADF;
95 goto out_drop_write;95 goto out_drop_write;
96 }96 }
97 97
98 if (src_file.file->f_op->unlocked_ioctl != cifs_ioctl) {98 if (fd_file(src_file)->f_op->unlocked_ioctl != cifs_ioctl) {
99 rc = -EBADF;99 rc = -EBADF;
100 cifs_dbg(VFS, "src file seems to be from a different filesystem type\n");100 cifs_dbg(VFS, "src file seems to be from a different filesystem type\n");
101 goto out_fput;101 goto out_fput;
102 }102 }
103 103
104 src_inode = file_inode(src_file.file);104 src_inode = file_inode(fd_file(src_file));
105 rc = -EINVAL;105 rc = -EINVAL;
106 if (S_ISDIR(src_inode->i_mode))106 if (S_ISDIR(src_inode->i_mode))
107 goto out_fput;107 goto out_fput;
108 108
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,
110 src_inode->i_size, 0);110 src_inode->i_size, 0);
111 if (rc > 0)111 if (rc > 0)
112 rc = 0;112 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
1566 1566
1567static int vmsplice_type(struct fd f, int *type)1567static int vmsplice_type(struct fd f, int *type)
1568{1568{
1569 if (!f.file)1569 if (!fd_file(f))
1570 return -EBADF;1570 return -EBADF;
1571 if (f.file->f_mode & FMODE_WRITE) {1571 if (fd_file(f)->f_mode & FMODE_WRITE) {
1572 *type = ITER_SOURCE;1572 *type = ITER_SOURCE;
1573 } else if (f.file->f_mode & FMODE_READ) {1573 } else if (fd_file(f)->f_mode & FMODE_READ) {
1574 *type = ITER_DEST;1574 *type = ITER_DEST;
1575 } else {1575 } else {
1576 fdput(f);1576 fdput(f);
@@ -1621,9 +1621,9 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov, · 44 unmodified lines
1621 if (!iov_iter_count(&iter))1621 if (!iov_iter_count(&iter))
1622 error = 0;1622 error = 0;
1623 else if (type == ITER_SOURCE)1623 else if (type == ITER_SOURCE)
1624 error = vmsplice_to_pipe(f.file, &iter, flags);1624 error = vmsplice_to_pipe(fd_file(f), &iter, flags);
1625 else1625 else
1626 error = vmsplice_to_user(f.file, &iter, flags);1626 error = vmsplice_to_user(fd_file(f), &iter, flags);
1627 1627
1628 kfree(iov);1628 kfree(iov);
1629out_fdput:1629out_fdput:
@@ -1646,10 +1646,10 @@ SYSCALL_DEFINE6(splice, int, fd_in, loff_t __user *, off_in, · 16 unmodified lines
1646 1646
1647 error = -EBADF;1647 error = -EBADF;
1648 in = fdget(fd_in);1648 in = fdget(fd_in);
1649 if (in.file) {1649 if (fd_file(in)) {
1650 out = fdget(fd_out);1650 out = fdget(fd_out);
1651 if (out.file) {1651 if (fd_file(out)) {
1652 error = __do_splice(in.file, off_in, out.file, off_out,1652 error = __do_splice(fd_file(in), off_in, fd_file(out), off_out,
1653 len, flags);1653 len, flags);
1654 fdput(out);1654 fdput(out);
1655 }1655 }
@@ -2016,10 +2016,10 @@ SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags) · 360 unmodified lines
2016 2016
2017 error = -EBADF;2017 error = -EBADF;
2018 in = fdget(fdin);2018 in = fdget(fdin);
2019 if (in.file) {2019 if (fd_file(in)) {
2020 out = fdget(fdout);2020 out = fdget(fdout);
2021 if (out.file) {2021 if (fd_file(out)) {
2022 error = do_tee(in.file, out.file, len, flags);2022 error = do_tee(fd_file(in), fd_file(out), len, flags);
2023 fdput(out);2023 fdput(out);
2024 }2024 }
2025 fdput(in);2025 fdput(in);
fs/stat.c+4−4
@@ -224,9 +224,9 @@ int vfs_fstat(int fd, struct kstat *stat) · 223 unmodified lines
224 int error;224 int error;
225 225
226 f = fdget_raw(fd);226 f = fdget_raw(fd);
227 if (!f.file)227 if (!fd_file(f))
228 return -EBADF;228 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);
230 fdput(f);230 fdput(f);
231 return error;231 return error;
232}232}
@@ -277,9 +277,9 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat, · 44 unmodified lines
277 u32 request_mask)277 u32 request_mask)
278{278{
279 CLASS(fd_raw, f)(fd);279 CLASS(fd_raw, f)(fd);
280 if (!f.file)280 if (!fd_file(f))
281 return -EBADF;281 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);
283}283}
284 284
285/**285/**
fs/statfs.c+2−2
@@ -116,8 +116,8 @@ int fd_statfs(int fd, struct kstatfs *st) · 115 unmodified lines
116{116{
117 struct fd f = fdget_raw(fd);117 struct fd f = fdget_raw(fd);
118 int error = -EBADF;118 int error = -EBADF;
119 if (f.file) {119 if (fd_file(f)) {
120 error = vfs_statfs(&f.file->f_path, st);120 error = vfs_statfs(&fd_file(f)->f_path, st);
121 fdput(f);121 fdput(f);
122 }122 }
123 return error;123 return error;
fs/sync.c+7−7
@@ -152,15 +152,15 @@ SYSCALL_DEFINE1(syncfs, int, fd) · 151 unmodified lines
152 struct super_block *sb;152 struct super_block *sb;
153 int ret, ret2;153 int ret, ret2;
154 154
155 if (!f.file)155 if (!fd_file(f))
156 return -EBADF;156 return -EBADF;
157 sb = f.file->f_path.dentry->d_sb;157 sb = fd_file(f)->f_path.dentry->d_sb;
158 158
159 down_read(&sb->s_umount);159 down_read(&sb->s_umount);
160 ret = sync_filesystem(sb);160 ret = sync_filesystem(sb);
161 up_read(&sb->s_umount);161 up_read(&sb->s_umount);
162 162
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);
164 164
165 fdput(f);165 fdput(f);
166 return ret ? ret : ret2;166 return ret ? ret : ret2;
@@ -208,8 +208,8 @@ static int do_fsync(unsigned int fd, int datasync) · 41 unmodified lines
208 struct fd f = fdget(fd);208 struct fd f = fdget(fd);
209 int ret = -EBADF;209 int ret = -EBADF;
210 210
211 if (f.file) {211 if (fd_file(f)) {
212 ret = vfs_fsync(f.file, datasync);212 ret = vfs_fsync(fd_file(f), datasync);
213 fdput(f);213 fdput(f);
214 }214 }
215 return ret;215 return ret;
@@ -360,8 +360,8 @@ int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes, · 144 unmodified lines
360 360
361 ret = -EBADF;361 ret = -EBADF;
362 f = fdget(fd);362 f = fdget(fd);
363 if (f.file)363 if (fd_file(f))
364 ret = sync_file_range(f.file, offset, nbytes, flags);364 ret = sync_file_range(fd_file(f), offset, nbytes, flags);
365 365
366 fdput(f);366 fdput(f);
367 return ret;367 return ret;
fs/timerfd.c+4−4
@@ -397,9 +397,9 @@ static const struct file_operations timerfd_fops = { · 396 unmodified lines
397static int timerfd_fget(int fd, struct fd *p)397static int timerfd_fget(int fd, struct fd *p)
398{398{
399 struct fd f = fdget(fd);399 struct fd f = fdget(fd);
400 if (!f.file)400 if (!fd_file(f))
401 return -EBADF;401 return -EBADF;
402 if (f.file->f_op != &timerfd_fops) {402 if (fd_file(f)->f_op != &timerfd_fops) {
403 fdput(f);403 fdput(f);
404 return -EINVAL;404 return -EINVAL;
405 }405 }
@@ -482,7 +482,7 @@ static int do_timerfd_settime(int ufd, int flags, · 76 unmodified lines
482 ret = timerfd_fget(ufd, &f);482 ret = timerfd_fget(ufd, &f);
483 if (ret)483 if (ret)
484 return ret;484 return ret;
485 ctx = f.file->private_data;485 ctx = fd_file(f)->private_data;
486 486
487 if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) {487 if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) {
488 fdput(f);488 fdput(f);
@@ -546,7 +546,7 @@ static int do_timerfd_gettime(int ufd, struct itimerspec64 *t) · 57 unmodified lines
546 int ret = timerfd_fget(ufd, &f);546 int ret = timerfd_fget(ufd, &f);
547 if (ret)547 if (ret)
548 return ret;548 return ret;
549 ctx = f.file->private_data;549 ctx = fd_file(f)->private_data;
550 550
551 spin_lock_irq(&ctx->wqh.lock);551 spin_lock_irq(&ctx->wqh.lock);
552 if (ctx->expired && ctx->tintv) {552 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
115 return -EINVAL;115 return -EINVAL;
116 116
117 f = fdget(fd);117 f = fdget(fd);
118 if (!f.file)118 if (!fd_file(f))
119 return -EBADF;119 return -EBADF;
120 error = vfs_utimes(&f.file->f_path, times);120 error = vfs_utimes(&fd_file(f)->f_path, times);
121 fdput(f);121 fdput(f);
122 return error;122 return error;
123}123}
fs/xattr.c+18−18
@@ -697,19 +697,19 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name, · 696 unmodified lines
697 int error;697 int error;
698 698
699 CLASS(fd, f)(fd);699 CLASS(fd, f)(fd);
700 if (!f.file)700 if (!fd_file(f))
701 return -EBADF;701 return -EBADF;
702 702
703 audit_file(f.file);703 audit_file(fd_file(f));
704 error = setxattr_copy(name, &ctx);704 error = setxattr_copy(name, &ctx);
705 if (error)705 if (error)
706 return error;706 return error;
707 707
708 error = mnt_want_write_file(f.file);708 error = mnt_want_write_file(fd_file(f));
709 if (!error) {709 if (!error) {
710 error = do_setxattr(file_mnt_idmap(f.file),710 error = do_setxattr(file_mnt_idmap(fd_file(f)),
711 f.file->f_path.dentry, &ctx);711 fd_file(f)->f_path.dentry, &ctx);
712 mnt_drop_write_file(f.file);712 mnt_drop_write_file(fd_file(f));
713 }713 }
714 kvfree(ctx.kvalue);714 kvfree(ctx.kvalue);
715 return error;715 return error;
@@ -812,10 +812,10 @@ SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, · 96 unmodified lines
812 struct fd f = fdget(fd);812 struct fd f = fdget(fd);
813 ssize_t error = -EBADF;813 ssize_t error = -EBADF;
814 814
815 if (!f.file)815 if (!fd_file(f))
816 return error;816 return error;
817 audit_file(f.file);817 audit_file(fd_file(f));
818 error = getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry,818 error = getxattr(file_mnt_idmap(fd_file(f)), fd_file(f)->f_path.dentry,
819 name, value, size);819 name, value, size);
820 fdput(f);820 fdput(f);
821 return error;821 return error;
@@ -888,10 +888,10 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size) · 66 unmodified lines
888 struct fd f = fdget(fd);888 struct fd f = fdget(fd);
889 ssize_t error = -EBADF;889 ssize_t error = -EBADF;
890 890
891 if (!f.file)891 if (!fd_file(f))
892 return error;892 return error;
893 audit_file(f.file);893 audit_file(fd_file(f));
894 error = listxattr(f.file->f_path.dentry, list, size);894 error = listxattr(fd_file(f)->f_path.dentry, list, size);
895 fdput(f);895 fdput(f);
896 return error;896 return error;
897}897}
@@ -954,9 +954,9 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) · 56 unmodified lines
954 char kname[XATTR_NAME_MAX + 1];954 char kname[XATTR_NAME_MAX + 1];
955 int error = -EBADF;955 int error = -EBADF;
956 956
957 if (!f.file)957 if (!fd_file(f))
958 return error;958 return error;
959 audit_file(f.file);959 audit_file(fd_file(f));
960 960
961 error = strncpy_from_user(kname, name, sizeof(kname));961 error = strncpy_from_user(kname, name, sizeof(kname));
962 if (error == 0 || error == sizeof(kname))962 if (error == 0 || error == sizeof(kname))
@@ -964,11 +964,11 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) · 1 unmodified line
964 if (error < 0)964 if (error < 0)
965 return error;965 return error;
966 966
967 error = mnt_want_write_file(f.file);967 error = mnt_want_write_file(fd_file(f));
968 if (!error) {968 if (!error) {
969 error = removexattr(file_mnt_idmap(f.file),969 error = removexattr(file_mnt_idmap(fd_file(f)),
970 f.file->f_path.dentry, kname);970 fd_file(f)->f_path.dentry, kname);
971 mnt_drop_write_file(f.file);971 mnt_drop_write_file(fd_file(f));
972 }972 }
973 fdput(f);973 fdput(f);
974 return error;974 return error;
fs/xfs/xfs_exchrange.c+2−2
@@ -794,9 +794,9 @@ xfs_ioc_exchange_range( · 793 unmodified lines
794 fxr.flags = args.flags;794 fxr.flags = args.flags;
795 795
796 file1 = fdget(args.file1_fd);796 file1 = fdget(args.file1_fd);
797 if (!file1.file)797 if (!fd_file(file1))
798 return -EBADF;798 return -EBADF;
799 fxr.file1 = file1.file;799 fxr.file1 = fd_file(file1);
800 800
801 error = xfs_exchange_range(&fxr);801 error = xfs_exchange_range(&fxr);
802 fdput(file1);802 fdput(file1);
fs/xfs/xfs_handle.c+2−2
@@ -92,9 +92,9 @@ xfs_find_handle( · 91 unmodified lines
92 92
93 if (cmd == XFS_IOC_FD_TO_HANDLE) {93 if (cmd == XFS_IOC_FD_TO_HANDLE) {
94 f = fdget(hreq->fd);94 f = fdget(hreq->fd);
95 if (!f.file)95 if (!fd_file(f))
96 return -EBADF;96 return -EBADF;
97 inode = file_inode(f.file);97 inode = file_inode(fd_file(f));
98 } else {98 } else {
99 error = user_path_at(AT_FDCWD, hreq->path, 0, &path);99 error = user_path_at(AT_FDCWD, hreq->path, 0, &path);
100 if (error)100 if (error)
fs/xfs/xfs_ioctl.c+14−14
@@ -1005,33 +1005,33 @@ xfs_ioc_swapext( · 1004 unmodified lines
1005 1005
1006 /* Pull information for the target fd */1006 /* Pull information for the target fd */
1007 f = fdget((int)sxp->sx_fdtarget);1007 f = fdget((int)sxp->sx_fdtarget);
1008 if (!f.file) {1008 if (!fd_file(f)) {
1009 error = -EINVAL;1009 error = -EINVAL;
1010 goto out;1010 goto out;
1011 }1011 }
1012 1012
1013 if (!(f.file->f_mode & FMODE_WRITE) ||1013 if (!(fd_file(f)->f_mode & FMODE_WRITE) ||
1014 !(f.file->f_mode & FMODE_READ) ||1014 !(fd_file(f)->f_mode & FMODE_READ) ||
1015 (f.file->f_flags & O_APPEND)) {1015 (fd_file(f)->f_flags & O_APPEND)) {
1016 error = -EBADF;1016 error = -EBADF;
1017 goto out_put_file;1017 goto out_put_file;
1018 }1018 }
1019 1019
1020 tmp = fdget((int)sxp->sx_fdtmp);1020 tmp = fdget((int)sxp->sx_fdtmp);
1021 if (!tmp.file) {1021 if (!fd_file(tmp)) {
1022 error = -EINVAL;1022 error = -EINVAL;
1023 goto out_put_file;1023 goto out_put_file;
1024 }1024 }
1025 1025
1026 if (!(tmp.file->f_mode & FMODE_WRITE) ||1026 if (!(fd_file(tmp)->f_mode & FMODE_WRITE) ||
1027 !(tmp.file->f_mode & FMODE_READ) ||1027 !(fd_file(tmp)->f_mode & FMODE_READ) ||
1028 (tmp.file->f_flags & O_APPEND)) {1028 (fd_file(tmp)->f_flags & O_APPEND)) {
1029 error = -EBADF;1029 error = -EBADF;
1030 goto out_put_tmp_file;1030 goto out_put_tmp_file;
1031 }1031 }
1032 1032
1033 if (IS_SWAPFILE(file_inode(f.file)) ||1033 if (IS_SWAPFILE(file_inode(fd_file(f))) ||
1034 IS_SWAPFILE(file_inode(tmp.file))) {1034 IS_SWAPFILE(file_inode(fd_file(tmp)))) {
1035 error = -EINVAL;1035 error = -EINVAL;
1036 goto out_put_tmp_file;1036 goto out_put_tmp_file;
1037 }1037 }
@@ -1041,14 +1041,14 @@ xfs_ioc_swapext( · 3 unmodified lines
1041 * before we cast and access them as XFS structures as we have no1041 * before we cast and access them as XFS structures as we have no
1042 * control over what the user passes us here.1042 * control over what the user passes us here.
1043 */1043 */
1044 if (f.file->f_op != &xfs_file_operations ||1044 if (fd_file(f)->f_op != &xfs_file_operations ||
1045 tmp.file->f_op != &xfs_file_operations) {1045 fd_file(tmp)->f_op != &xfs_file_operations) {
1046 error = -EINVAL;1046 error = -EINVAL;
1047 goto out_put_tmp_file;1047 goto out_put_tmp_file;
1048 }1048 }
1049 1049
1050 ip = XFS_I(file_inode(f.file));1050 ip = XFS_I(file_inode(fd_file(f)));
1051 tip = XFS_I(file_inode(tmp.file));1051 tip = XFS_I(file_inode(fd_file(tmp)));
1052 1052
1053 if (ip->i_mount != tip->i_mount) {1053 if (ip->i_mount != tip->i_mount) {
1054 error = -EINVAL;1054 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
98 * DEFINE_CLASS(fdget, struct fd, fdput(_T), fdget(fd), int fd)98 * DEFINE_CLASS(fdget, struct fd, fdput(_T), fdget(fd), int fd)
99 *99 *
100 * CLASS(fdget, f)(fd);100 * CLASS(fdget, f)(fd);
101 * if (!f.file)101 * if (!fd_file(f))
102 * return -EBADF;102 * return -EBADF;
103 *103 *
104 * // use 'f' without concern104 * // use 'f' without concern
include/linux/file.h+4−2
@@ -42,10 +42,12 @@ struct fd { · 41 unmodified lines
42#define FDPUT_FPUT 142#define FDPUT_FPUT 1
43#define FDPUT_POS_UNLOCK 243#define FDPUT_POS_UNLOCK 2
44 44
45#define fd_file(f) ((f).file)
46
45static inline void fdput(struct fd fd)47static inline void fdput(struct fd fd)
46{48{
47 if (fd.flags & FDPUT_FPUT)49 if (fd.flags & FDPUT_FPUT)
48 fput(fd.file);50 fput(fd_file(fd));
49}51}
50 52
51extern struct file *fget(unsigned int fd);53extern struct file *fget(unsigned int fd);
@@ -79,7 +81,7 @@ static inline struct fd fdget_pos(int fd) · 27 unmodified lines
79static inline void fdput_pos(struct fd f)81static inline void fdput_pos(struct fd f)
80{82{
81 if (f.flags & FDPUT_POS_UNLOCK)83 if (f.flags & FDPUT_POS_UNLOCK)
82 __f_unlock_pos(f.file);84 __f_unlock_pos(fd_file(f));
83 fdput(f);85 fdput(f);
84}86}
85 87
io_uring/sqpoll.c+5−5
@@ -108,14 +108,14 @@ static struct io_sq_data *io_attach_sq_data(struct io_uring_params *p) · 107 unmodified lines
108 struct fd f;108 struct fd f;
109 109
110 f = fdget(p->wq_fd);110 f = fdget(p->wq_fd);
111 if (!f.file)111 if (!fd_file(f))
112 return ERR_PTR(-ENXIO);112 return ERR_PTR(-ENXIO);
113 if (!io_is_uring_fops(f.file)) {113 if (!io_is_uring_fops(fd_file(f))) {
114 fdput(f);114 fdput(f);
115 return ERR_PTR(-EINVAL);115 return ERR_PTR(-EINVAL);
116 }116 }
117 117
118 ctx_attach = f.file->private_data;118 ctx_attach = fd_file(f)->private_data;
119 sqd = ctx_attach->sq_data;119 sqd = ctx_attach->sq_data;
120 if (!sqd) {120 if (!sqd) {
121 fdput(f);121 fdput(f);
@@ -418,9 +418,9 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx, · 296 unmodified lines
418 struct fd f;418 struct fd f;
419 419
420 f = fdget(p->wq_fd);420 f = fdget(p->wq_fd);
421 if (!f.file)421 if (!fd_file(f))
422 return -ENXIO;422 return -ENXIO;
423 if (!io_is_uring_fops(f.file)) {423 if (!io_is_uring_fops(fd_file(f))) {
424 fdput(f);424 fdput(f);
425 return -EINVAL;425 return -EINVAL;
426 }426 }
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
1085 audit_mq_sendrecv(mqdes, msg_len, msg_prio, ts);1085 audit_mq_sendrecv(mqdes, msg_len, msg_prio, ts);
1086 1086
1087 f = fdget(mqdes);1087 f = fdget(mqdes);
1088 if (unlikely(!f.file)) {1088 if (unlikely(!fd_file(f))) {
1089 ret = -EBADF;1089 ret = -EBADF;
1090 goto out;1090 goto out;
1091 }1091 }
1092 1092
1093 inode = file_inode(f.file);1093 inode = file_inode(fd_file(f));
1094 if (unlikely(f.file->f_op != &mqueue_file_operations)) {1094 if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
1095 ret = -EBADF;1095 ret = -EBADF;
1096 goto out_fput;1096 goto out_fput;
1097 }1097 }
1098 info = MQUEUE_I(inode);1098 info = MQUEUE_I(inode);
1099 audit_file(f.file);1099 audit_file(fd_file(f));
1100 1100
1101 if (unlikely(!(f.file->f_mode & FMODE_WRITE))) {1101 if (unlikely(!(fd_file(f)->f_mode & FMODE_WRITE))) {
1102 ret = -EBADF;1102 ret = -EBADF;
1103 goto out_fput;1103 goto out_fput;
1104 }1104 }
@@ -1138,7 +1138,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr, · 33 unmodified lines
1138 }1138 }
1139 1139
1140 if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {1140 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) {
1142 ret = -EAGAIN;1142 ret = -EAGAIN;
1143 } else {1143 } else {
1144 wait.task = current;1144 wait.task = current;
@@ -1199,20 +1199,20 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr, · 54 unmodified lines
1199 audit_mq_sendrecv(mqdes, msg_len, 0, ts);1199 audit_mq_sendrecv(mqdes, msg_len, 0, ts);
1200 1200
1201 f = fdget(mqdes);1201 f = fdget(mqdes);
1202 if (unlikely(!f.file)) {1202 if (unlikely(!fd_file(f))) {
1203 ret = -EBADF;1203 ret = -EBADF;
1204 goto out;1204 goto out;
1205 }1205 }
1206 1206
1207 inode = file_inode(f.file);1207 inode = file_inode(fd_file(f));
1208 if (unlikely(f.file->f_op != &mqueue_file_operations)) {1208 if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
1209 ret = -EBADF;1209 ret = -EBADF;
1210 goto out_fput;1210 goto out_fput;
1211 }1211 }
1212 info = MQUEUE_I(inode);1212 info = MQUEUE_I(inode);
1213 audit_file(f.file);1213 audit_file(fd_file(f));
1214 1214
1215 if (unlikely(!(f.file->f_mode & FMODE_READ))) {1215 if (unlikely(!(fd_file(f)->f_mode & FMODE_READ))) {
1216 ret = -EBADF;1216 ret = -EBADF;
1217 goto out_fput;1217 goto out_fput;
1218 }1218 }
@@ -1242,7 +1242,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr, · 23 unmodified lines
1242 }1242 }
1243 1243
1244 if (info->attr.mq_curmsgs == 0) {1244 if (info->attr.mq_curmsgs == 0) {
1245 if (f.file->f_flags & O_NONBLOCK) {1245 if (fd_file(f)->f_flags & O_NONBLOCK) {
1246 spin_unlock(&info->lock);1246 spin_unlock(&info->lock);
1247 ret = -EAGAIN;1247 ret = -EAGAIN;
1248 } else {1248 } else {
@@ -1356,11 +1356,11 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification) · 107 unmodified lines
1356 /* and attach it to the socket */1356 /* and attach it to the socket */
1357retry:1357retry:
1358 f = fdget(notification->sigev_signo);1358 f = fdget(notification->sigev_signo);
1359 if (!f.file) {1359 if (!fd_file(f)) {
1360 ret = -EBADF;1360 ret = -EBADF;
1361 goto out;1361 goto out;
1362 }1362 }
1363 sock = netlink_getsockbyfilp(f.file);1363 sock = netlink_getsockbyfilp(fd_file(f));
1364 fdput(f);1364 fdput(f);
1365 if (IS_ERR(sock)) {1365 if (IS_ERR(sock)) {
1366 ret = PTR_ERR(sock);1366 ret = PTR_ERR(sock);
@@ -1379,13 +1379,13 @@ retry: · 12 unmodified lines
1379 }1379 }
1380 1380
1381 f = fdget(mqdes);1381 f = fdget(mqdes);
1382 if (!f.file) {1382 if (!fd_file(f)) {
1383 ret = -EBADF;1383 ret = -EBADF;
1384 goto out;1384 goto out;
1385 }1385 }
1386 1386
1387 inode = file_inode(f.file);1387 inode = file_inode(fd_file(f));
1388 if (unlikely(f.file->f_op != &mqueue_file_operations)) {1388 if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
1389 ret = -EBADF;1389 ret = -EBADF;
1390 goto out_fput;1390 goto out_fput;
1391 }1391 }
@@ -1460,31 +1460,31 @@ static int do_mq_getsetattr(int mqdes, struct mq_attr *new, struct mq_attr *old) · 68 unmodified lines
1460 return -EINVAL;1460 return -EINVAL;
1461 1461
1462 f = fdget(mqdes);1462 f = fdget(mqdes);
1463 if (!f.file)1463 if (!fd_file(f))
1464 return -EBADF;1464 return -EBADF;
1465 1465
1466 if (unlikely(f.file->f_op != &mqueue_file_operations)) {1466 if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
1467 fdput(f);1467 fdput(f);
1468 return -EBADF;1468 return -EBADF;
1469 }1469 }
1470 1470
1471 inode = file_inode(f.file);1471 inode = file_inode(fd_file(f));
1472 info = MQUEUE_I(inode);1472 info = MQUEUE_I(inode);
1473 1473
1474 spin_lock(&info->lock);1474 spin_lock(&info->lock);
1475 1475
1476 if (old) {1476 if (old) {
1477 *old = info->attr;1477 *old = info->attr;
1478 old->mq_flags = f.file->f_flags & O_NONBLOCK;1478 old->mq_flags = fd_file(f)->f_flags & O_NONBLOCK;
1479 }1479 }
1480 if (new) {1480 if (new) {
1481 audit_mq_getsetattr(mqdes, new);1481 audit_mq_getsetattr(mqdes, new);
1482 spin_lock(&f.file->f_lock);1482 spin_lock(&fd_file(f)->f_lock);
1483 if (new->mq_flags & O_NONBLOCK)1483 if (new->mq_flags & O_NONBLOCK)
1484 f.file->f_flags |= O_NONBLOCK;1484 fd_file(f)->f_flags |= O_NONBLOCK;
1485 else1485 else
1486 f.file->f_flags &= ~O_NONBLOCK;1486 fd_file(f)->f_flags &= ~O_NONBLOCK;
1487 spin_unlock(&f.file->f_lock);1487 spin_unlock(&fd_file(f)->f_lock);
1488 1488
1489 inode_set_atime_to_ts(inode, inode_set_ctime_current(inode));1489 inode_set_atime_to_ts(inode, inode_set_ctime_current(inode));
1490 }1490 }
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
80 struct bpf_local_storage_data *sdata;80 struct bpf_local_storage_data *sdata;
81 struct fd f = fdget_raw(*(int *)key);81 struct fd f = fdget_raw(*(int *)key);
82 82
83 if (!f.file)83 if (!fd_file(f))
84 return ERR_PTR(-EBADF);84 return ERR_PTR(-EBADF);
85 85
86 sdata = inode_storage_lookup(file_inode(f.file), map, true);86 sdata = inode_storage_lookup(file_inode(fd_file(f)), map, true);
87 fdput(f);87 fdput(f);
88 return sdata ? sdata->data : NULL;88 return sdata ? sdata->data : NULL;
89}89}
@@ -94,14 +94,14 @@ static long bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key, · 4 unmodified lines
94 struct bpf_local_storage_data *sdata;94 struct bpf_local_storage_data *sdata;
95 struct fd f = fdget_raw(*(int *)key);95 struct fd f = fdget_raw(*(int *)key);
96 96
97 if (!f.file)97 if (!fd_file(f))
98 return -EBADF;98 return -EBADF;
99 if (!inode_storage_ptr(file_inode(f.file))) {99 if (!inode_storage_ptr(file_inode(fd_file(f)))) {
100 fdput(f);100 fdput(f);
101 return -EBADF;101 return -EBADF;
102 }102 }
103 103
104 sdata = bpf_local_storage_update(file_inode(f.file),104 sdata = bpf_local_storage_update(file_inode(fd_file(f)),
105 (struct bpf_local_storage_map *)map,105 (struct bpf_local_storage_map *)map,
106 value, map_flags, GFP_ATOMIC);106 value, map_flags, GFP_ATOMIC);
107 fdput(f);107 fdput(f);
@@ -126,10 +126,10 @@ static long bpf_fd_inode_storage_delete_elem(struct bpf_map *map, void *key) · 18 unmodified lines
126 struct fd f = fdget_raw(*(int *)key);126 struct fd f = fdget_raw(*(int *)key);
127 int err;127 int err;
128 128
129 if (!f.file)129 if (!fd_file(f))
130 return -EBADF;130 return -EBADF;
131 131
132 err = inode_storage_delete(file_inode(f.file), map);132 err = inode_storage_delete(file_inode(fd_file(f)), map);
133 fdput(f);133 fdput(f);
134 return err;134 return err;
135}135}
kernel/bpf/btf.c+3−3
@@ -7677,15 +7677,15 @@ struct btf *btf_get_by_fd(int fd) · 7676 unmodified lines
7677 7677
7678 f = fdget(fd);7678 f = fdget(fd);
7679 7679
7680 if (!f.file)7680 if (!fd_file(f))
7681 return ERR_PTR(-EBADF);7681 return ERR_PTR(-EBADF);
7682 7682
7683 if (f.file->f_op != &btf_fops) {7683 if (fd_file(f)->f_op != &btf_fops) {
7684 fdput(f);7684 fdput(f);
7685 return ERR_PTR(-EINVAL);7685 return ERR_PTR(-EINVAL);
7686 }7686 }
7687 7687
7688 btf = f.file->private_data;7688 btf = fd_file(f)->private_data;
7689 refcount_inc(&btf->refcnt);7689 refcount_inc(&btf->refcnt);
7690 fdput(f);7690 fdput(f);
7691 7691
kernel/bpf/syscall.c+21−21
@@ -829,7 +829,7 @@ static int bpf_map_release(struct inode *inode, struct file *filp) · 828 unmodified lines
829 829
830static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f)830static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f)
831{831{
832 fmode_t mode = f.file->f_mode;832 fmode_t mode = fd_file(f)->f_mode;
833 833
834 /* Our file permissions may have been overridden by global834 /* Our file permissions may have been overridden by global
835 * map permissions facing syscall side.835 * map permissions facing syscall side.
@@ -1423,14 +1423,14 @@ put_token: · 587 unmodified lines
1423 */1423 */
1424struct bpf_map *__bpf_map_get(struct fd f)1424struct bpf_map *__bpf_map_get(struct fd f)
1425{1425{
1426 if (!f.file)1426 if (!fd_file(f))
1427 return ERR_PTR(-EBADF);1427 return ERR_PTR(-EBADF);
1428 if (f.file->f_op != &bpf_map_fops) {1428 if (fd_file(f)->f_op != &bpf_map_fops) {
1429 fdput(f);1429 fdput(f);
1430 return ERR_PTR(-EINVAL);1430 return ERR_PTR(-EINVAL);
1431 }1431 }
1432 1432
1433 return f.file->private_data;1433 return fd_file(f)->private_data;
1434}1434}
1435 1435
1436void bpf_map_inc(struct bpf_map *map)1436void bpf_map_inc(struct bpf_map *map)
@@ -1651,7 +1651,7 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr) · 214 unmodified lines
1651 goto free_key;1651 goto free_key;
1652 }1652 }
1653 1653
1654 err = bpf_map_update_value(map, f.file, key, value, attr->flags);1654 err = bpf_map_update_value(map, fd_file(f), key, value, attr->flags);
1655 if (!err)1655 if (!err)
1656 maybe_wait_bpf_programs(map);1656 maybe_wait_bpf_programs(map);
1657 1657
@@ -2409,14 +2409,14 @@ int bpf_prog_new_fd(struct bpf_prog *prog) · 751 unmodified lines
2409 2409
2410static struct bpf_prog *____bpf_prog_get(struct fd f)2410static struct bpf_prog *____bpf_prog_get(struct fd f)
2411{2411{
2412 if (!f.file)2412 if (!fd_file(f))
2413 return ERR_PTR(-EBADF);2413 return ERR_PTR(-EBADF);
2414 if (f.file->f_op != &bpf_prog_fops) {2414 if (fd_file(f)->f_op != &bpf_prog_fops) {
2415 fdput(f);2415 fdput(f);
2416 return ERR_PTR(-EINVAL);2416 return ERR_PTR(-EINVAL);
2417 }2417 }
2418 2418
2419 return f.file->private_data;2419 return fd_file(f)->private_data;
2420}2420}
2421 2421
2422void bpf_prog_add(struct bpf_prog *prog, int i)2422void bpf_prog_add(struct bpf_prog *prog, int i)
@@ -3259,14 +3259,14 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd) · 836 unmodified lines
3259 struct fd f = fdget(ufd);3259 struct fd f = fdget(ufd);
3260 struct bpf_link *link;3260 struct bpf_link *link;
3261 3261
3262 if (!f.file)3262 if (!fd_file(f))
3263 return ERR_PTR(-EBADF);3263 return ERR_PTR(-EBADF);
3264 if (f.file->f_op != &bpf_link_fops && f.file->f_op != &bpf_link_fops_poll) {3264 if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll) {
3265 fdput(f);3265 fdput(f);
3266 return ERR_PTR(-EINVAL);3266 return ERR_PTR(-EINVAL);
3267 }3267 }
3268 3268
3269 link = f.file->private_data;3269 link = fd_file(f)->private_data;
3270 bpf_link_inc(link);3270 bpf_link_inc(link);
3271 fdput(f);3271 fdput(f);
3272 3272
@@ -4982,19 +4982,19 @@ static int bpf_obj_get_info_by_fd(const union bpf_attr *attr, · 1709 unmodified lines
4982 return -EINVAL;4982 return -EINVAL;
4983 4983
4984 f = fdget(ufd);4984 f = fdget(ufd);
4985 if (!f.file)4985 if (!fd_file(f))
4986 return -EBADFD;4986 return -EBADFD;
4987 4987
4988 if (f.file->f_op == &bpf_prog_fops)4988 if (fd_file(f)->f_op == &bpf_prog_fops)
4989 err = bpf_prog_get_info_by_fd(f.file, f.file->private_data, attr,4989 err = bpf_prog_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
4990 uattr);4990 uattr);
4991 else if (f.file->f_op == &bpf_map_fops)4991 else if (fd_file(f)->f_op == &bpf_map_fops)
4992 err = bpf_map_get_info_by_fd(f.file, f.file->private_data, attr,4992 err = bpf_map_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
4993 uattr);4993 uattr);
4994 else if (f.file->f_op == &btf_fops)4994 else if (fd_file(f)->f_op == &btf_fops)
4995 err = bpf_btf_get_info_by_fd(f.file, f.file->private_data, attr, uattr);4995 err = bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, uattr);
4996 else if (f.file->f_op == &bpf_link_fops || f.file->f_op == &bpf_link_fops_poll)4996 else if (fd_file(f)->f_op == &bpf_link_fops || fd_file(f)->f_op == &bpf_link_fops_poll)
4997 err = bpf_link_get_info_by_fd(f.file, f.file->private_data,4997 err = bpf_link_get_info_by_fd(fd_file(f), fd_file(f)->private_data,
4998 attr, uattr);4998 attr, uattr);
4999 else4999 else
5000 err = -EINVAL;5000 err = -EINVAL;
@@ -5215,7 +5215,7 @@ static int bpf_map_do_batch(const union bpf_attr *attr, · 214 unmodified lines
5215 else if (cmd == BPF_MAP_LOOKUP_AND_DELETE_BATCH)5215 else if (cmd == BPF_MAP_LOOKUP_AND_DELETE_BATCH)
5216 BPF_DO_BATCH(map->ops->map_lookup_and_delete_batch, map, attr, uattr);5216 BPF_DO_BATCH(map->ops->map_lookup_and_delete_batch, map, attr, uattr);
5217 else if (cmd == BPF_MAP_UPDATE_BATCH)5217 else if (cmd == BPF_MAP_UPDATE_BATCH)
5218 BPF_DO_BATCH(map->ops->map_update_batch, map, f.file, attr, uattr);5218 BPF_DO_BATCH(map->ops->map_update_batch, map, fd_file(f), attr, uattr);
5219 else5219 else
5220 BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);5220 BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);
5221err_put:5221err_put:
kernel/bpf/token.c+5−5
@@ -122,10 +122,10 @@ int bpf_token_create(union bpf_attr *attr) · 121 unmodified lines
122 int err, fd;122 int err, fd;
123 123
124 f = fdget(attr->token_create.bpffs_fd);124 f = fdget(attr->token_create.bpffs_fd);
125 if (!f.file)125 if (!fd_file(f))
126 return -EBADF;126 return -EBADF;
127 127
128 path = f.file->f_path;128 path = fd_file(f)->f_path;
129 path_get(&path);129 path_get(&path);
130 fdput(f);130 fdput(f);
131 131
@@ -235,14 +235,14 @@ struct bpf_token *bpf_token_get_from_fd(u32 ufd) · 103 unmodified lines
235 struct fd f = fdget(ufd);235 struct fd f = fdget(ufd);
236 struct bpf_token *token;236 struct bpf_token *token;
237 237
238 if (!f.file)238 if (!fd_file(f))
239 return ERR_PTR(-EBADF);239 return ERR_PTR(-EBADF);
240 if (f.file->f_op != &bpf_token_fops) {240 if (fd_file(f)->f_op != &bpf_token_fops) {
241 fdput(f);241 fdput(f);
242 return ERR_PTR(-EINVAL);242 return ERR_PTR(-EINVAL);
243 }243 }
244 244
245 token = f.file->private_data;245 token = fd_file(f)->private_data;
246 bpf_token_inc(token);246 bpf_token_inc(token);
247 fdput(f);247 fdput(f);
248 248
kernel/cgroup/cgroup.c+2−2
@@ -6901,10 +6901,10 @@ struct cgroup *cgroup_v1v2_get_from_fd(int fd) · 6900 unmodified lines
6901{6901{
6902 struct cgroup *cgrp;6902 struct cgroup *cgrp;
6903 struct fd f = fdget_raw(fd);6903 struct fd f = fdget_raw(fd);
6904 if (!f.file)6904 if (!fd_file(f))
6905 return ERR_PTR(-EBADF);6905 return ERR_PTR(-EBADF);
6906 6906
6907 cgrp = cgroup_v1v2_get_from_file(f.file);6907 cgrp = cgroup_v1v2_get_from_file(fd_file(f));
6908 fdput(f);6908 fdput(f);
6909 return cgrp;6909 return cgrp;
6910}6910}
kernel/events/core.c+6−6
@@ -933,10 +933,10 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event, · 932 unmodified lines
933 struct fd f = fdget(fd);933 struct fd f = fdget(fd);
934 int ret = 0;934 int ret = 0;
935 935
936 if (!f.file)936 if (!fd_file(f))
937 return -EBADF;937 return -EBADF;
938 938
939 css = css_tryget_online_from_dir(f.file->f_path.dentry,939 css = css_tryget_online_from_dir(fd_file(f)->f_path.dentry,
940 &perf_event_cgrp_subsys);940 &perf_event_cgrp_subsys);
941 if (IS_ERR(css)) {941 if (IS_ERR(css)) {
942 ret = PTR_ERR(css);942 ret = PTR_ERR(css);
@@ -5898,10 +5898,10 @@ static const struct file_operations perf_fops; · 4955 unmodified lines
5898static inline int perf_fget_light(int fd, struct fd *p)5898static inline int perf_fget_light(int fd, struct fd *p)
5899{5899{
5900 struct fd f = fdget(fd);5900 struct fd f = fdget(fd);
5901 if (!f.file)5901 if (!fd_file(f))
5902 return -EBADF;5902 return -EBADF;
5903 5903
5904 if (f.file->f_op != &perf_fops) {5904 if (fd_file(f)->f_op != &perf_fops) {
5905 fdput(f);5905 fdput(f);
5906 return -EBADF;5906 return -EBADF;
5907 }5907 }
@@ -5961,7 +5961,7 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon · 53 unmodified lines
5961 ret = perf_fget_light(arg, &output);5961 ret = perf_fget_light(arg, &output);
5962 if (ret)5962 if (ret)
5963 return ret;5963 return ret;
5964 output_event = output.file->private_data;5964 output_event = fd_file(output)->private_data;
5965 ret = perf_event_set_output(event, output_event);5965 ret = perf_event_set_output(event, output_event);
5966 fdput(output);5966 fdput(output);
5967 } else {5967 } else {
@@ -12549,7 +12549,7 @@ SYSCALL_DEFINE5(perf_event_open, · 6581 unmodified lines
12549 err = perf_fget_light(group_fd, &group);12549 err = perf_fget_light(group_fd, &group);
12550 if (err)12550 if (err)
12551 goto err_fd;12551 goto err_fd;
12552 group_leader = group.file->private_data;12552 group_leader = fd_file(group)->private_data;
12553 if (flags & PERF_FLAG_FD_OUTPUT)12553 if (flags & PERF_FLAG_FD_OUTPUT)
12554 output_event = group_leader;12554 output_event = group_leader;
12555 if (flags & PERF_FLAG_FD_NO_GROUP)12555 if (flags & PERF_FLAG_FD_NO_GROUP)
kernel/module/main.c+1−1
@@ -3211,7 +3211,7 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) · 3210 unmodified lines
3211 return -EINVAL;3211 return -EINVAL;
3212 3212
3213 f = fdget(fd);3213 f = fdget(fd);
3214 err = idempotent_init_module(f.file, uargs, flags);3214 err = idempotent_init_module(fd_file(f), uargs, flags);
3215 fdput(f);3215 fdput(f);
3216 return err;3216 return err;
3217}3217}
kernel/nsproxy.c+6−6
@@ -550,15 +550,15 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags) · 549 unmodified lines
550 struct nsset nsset = {};550 struct nsset nsset = {};
551 int err = 0;551 int err = 0;
552 552
553 if (!f.file)553 if (!fd_file(f))
554 return -EBADF;554 return -EBADF;
555 555
556 if (proc_ns_file(f.file)) {556 if (proc_ns_file(fd_file(f))) {
557 ns = get_proc_ns(file_inode(f.file));557 ns = get_proc_ns(file_inode(fd_file(f)));
558 if (flags && (ns->ops->type != flags))558 if (flags && (ns->ops->type != flags))
559 err = -EINVAL;559 err = -EINVAL;
560 flags = ns->ops->type;560 flags = ns->ops->type;
561 } else if (!IS_ERR(pidfd_pid(f.file))) {561 } else if (!IS_ERR(pidfd_pid(fd_file(f)))) {
562 err = check_setns_flags(flags);562 err = check_setns_flags(flags);
563 } else {563 } else {
564 err = -EINVAL;564 err = -EINVAL;
@@ -570,10 +570,10 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags) · 5 unmodified lines
570 if (err)570 if (err)
571 goto out;571 goto out;
572 572
573 if (proc_ns_file(f.file))573 if (proc_ns_file(fd_file(f)))
574 err = validate_ns(&nsset, ns);574 err = validate_ns(&nsset, ns);
575 else575 else
576 err = validate_nsset(&nsset, pidfd_pid(f.file));576 err = validate_nsset(&nsset, pidfd_pid(fd_file(f)));
577 if (!err) {577 if (!err) {
578 commit_nsset(&nsset);578 commit_nsset(&nsset);
579 perf_event_namespaces(current);579 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
540 struct pid *pid;540 struct pid *pid;
541 541
542 f = fdget(fd);542 f = fdget(fd);
543 if (!f.file)543 if (!fd_file(f))
544 return ERR_PTR(-EBADF);544 return ERR_PTR(-EBADF);
545 545
546 pid = pidfd_pid(f.file);546 pid = pidfd_pid(fd_file(f));
547 if (!IS_ERR(pid)) {547 if (!IS_ERR(pid)) {
548 get_pid(pid);548 get_pid(pid);
549 *flags = f.file->f_flags;549 *flags = fd_file(f)->f_flags;
550 }550 }
551 551
552 fdput(f);552 fdput(f);
@@ -755,10 +755,10 @@ SYSCALL_DEFINE3(pidfd_getfd, int, pidfd, int, fd, · 202 unmodified lines
755 return -EINVAL;755 return -EINVAL;
756 756
757 f = fdget(pidfd);757 f = fdget(pidfd);
758 if (!f.file)758 if (!fd_file(f))
759 return -EBADF;759 return -EBADF;
760 760
761 pid = pidfd_pid(f.file);761 pid = pidfd_pid(fd_file(f));
762 if (IS_ERR(pid))762 if (IS_ERR(pid))
763 ret = PTR_ERR(pid);763 ret = PTR_ERR(pid);
764 else764 else
kernel/signal.c+3−3
@@ -3922,11 +3922,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, · 3921 unmodified lines
3922 return -EINVAL;3922 return -EINVAL;
3923 3923
3924 f = fdget(pidfd);3924 f = fdget(pidfd);
3925 if (!f.file)3925 if (!fd_file(f))
3926 return -EBADF;3926 return -EBADF;
3927 3927
3928 /* Is this a pidfd? */3928 /* Is this a pidfd? */
3929 pid = pidfd_to_pid(f.file);3929 pid = pidfd_to_pid(fd_file(f));
3930 if (IS_ERR(pid)) {3930 if (IS_ERR(pid)) {
3931 ret = PTR_ERR(pid);3931 ret = PTR_ERR(pid);
3932 goto err;3932 goto err;
@@ -3939,7 +3939,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, · 6 unmodified lines
3939 switch (flags) {3939 switch (flags) {
3940 case 0:3940 case 0:
3941 /* Infer scope from the type of pidfd. */3941 /* Infer scope from the type of pidfd. */
3942 if (f.file->f_flags & PIDFD_THREAD)3942 if (fd_file(f)->f_flags & PIDFD_THREAD)
3943 type = PIDTYPE_PID;3943 type = PIDTYPE_PID;
3944 else3944 else
3945 type = PIDTYPE_TGID;3945 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
1916 int err;1916 int err;
1917 1917
1918 exe = fdget(fd);1918 exe = fdget(fd);
1919 if (!exe.file)1919 if (!fd_file(exe))
1920 return -EBADF;1920 return -EBADF;
1921 1921
1922 inode = file_inode(exe.file);1922 inode = file_inode(fd_file(exe));
1923 1923
1924 /*1924 /*
1925 * Because the original mm->exe_file points to executable file, make1925 * 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
1927 * overall picture.1927 * overall picture.
1928 */1928 */
1929 err = -EACCES;1929 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))
1931 goto exit;1931 goto exit;
1932 1932
1933 err = file_permission(exe.file, MAY_EXEC);1933 err = file_permission(fd_file(exe), MAY_EXEC);
1934 if (err)1934 if (err)
1935 goto exit;1935 goto exit;
1936 1936
1937 err = replace_mm_exe_file(mm, exe.file);1937 err = replace_mm_exe_file(mm, fd_file(exe));
1938exit:1938exit:
1939 fdput(exe);1939 fdput(exe);
1940 return err;1940 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
419 419
420 fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);420 fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);
421 f = fdget(fd);421 f = fdget(fd);
422 if (!f.file)422 if (!fd_file(f))
423 return 0;423 return 0;
424 424
425 size = nla_total_size(sizeof(struct cgroupstats));425 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
440 stats = nla_data(na);440 stats = nla_data(na);
441 memset(stats, 0, sizeof(*stats));441 memset(stats, 0, sizeof(*stats));
442 442
443 rc = cgroupstats_build(stats, f.file->f_path.dentry);443 rc = cgroupstats_build(stats, fd_file(f)->f_path.dentry);
444 if (rc < 0) {444 if (rc < 0) {
445 nlmsg_free(rep_skb);445 nlmsg_free(rep_skb);
446 goto err;446 goto err;
kernel/watch_queue.c+2−2
@@ -666,8 +666,8 @@ struct watch_queue *get_watch_queue(int fd) · 665 unmodified lines
666 struct fd f;666 struct fd f;
667 667
668 f = fdget(fd);668 f = fdget(fd);
669 if (f.file) {669 if (fd_file(f)) {
670 pipe = get_pipe_info(f.file, false);670 pipe = get_pipe_info(fd_file(f), false);
671 if (pipe && pipe->watch_queue) {671 if (pipe && pipe->watch_queue) {
672 wqueue = pipe->watch_queue;672 wqueue = pipe->watch_queue;
673 kref_get(&wqueue->usage);673 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
193 struct fd f = fdget(fd);193 struct fd f = fdget(fd);
194 int ret;194 int ret;
195 195
196 if (!f.file)196 if (!fd_file(f))
197 return -EBADF;197 return -EBADF;
198 198
199 ret = vfs_fadvise(f.file, offset, len, advice);199 ret = vfs_fadvise(fd_file(f), offset, len, advice);
200 200
201 fdput(f);201 fdput(f);
202 return ret;202 return ret;
mm/filemap.c+3−3
@@ -4393,7 +4393,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd, · 4392 unmodified lines
4393 struct cachestat cs;4393 struct cachestat cs;
4394 pgoff_t first_index, last_index;4394 pgoff_t first_index, last_index;
4395 4395
4396 if (!f.file)4396 if (!fd_file(f))
4397 return -EBADF;4397 return -EBADF;
4398 4398
4399 if (copy_from_user(&csr, cstat_range,4399 if (copy_from_user(&csr, cstat_range,
@@ -4403,7 +4403,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd, · 3 unmodified lines
4403 }4403 }
4404 4404
4405 /* hugetlbfs is not supported */4405 /* hugetlbfs is not supported */
4406 if (is_file_hugepages(f.file)) {4406 if (is_file_hugepages(fd_file(f))) {
4407 fdput(f);4407 fdput(f);
4408 return -EOPNOTSUPP;4408 return -EOPNOTSUPP;
4409 }4409 }
@@ -4417,7 +4417,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd, · 7 unmodified lines
4417 last_index =4417 last_index =
4418 csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;4418 csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
4419 memset(&cs, 0, sizeof(struct cachestat));4419 memset(&cs, 0, sizeof(struct cachestat));
4420 mapping = f.file->f_mapping;4420 mapping = fd_file(f)->f_mapping;
4421 filemap_cachestat(mapping, first_index, last_index, &cs);4421 filemap_cachestat(mapping, first_index, last_index, &cs);
4422 fdput(f);4422 fdput(f);
4423 4423
mm/memcontrol-v1.c+6−6
@@ -1857,26 +1857,26 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of, · 1856 unmodified lines
1857 INIT_WORK(&event->remove, memcg_event_remove);1857 INIT_WORK(&event->remove, memcg_event_remove);
1858 1858
1859 efile = fdget(efd);1859 efile = fdget(efd);
1860 if (!efile.file) {1860 if (!fd_file(efile)) {
1861 ret = -EBADF;1861 ret = -EBADF;
1862 goto out_kfree;1862 goto out_kfree;
1863 }1863 }
1864 1864
1865 event->eventfd = eventfd_ctx_fileget(efile.file);1865 event->eventfd = eventfd_ctx_fileget(fd_file(efile));
1866 if (IS_ERR(event->eventfd)) {1866 if (IS_ERR(event->eventfd)) {
1867 ret = PTR_ERR(event->eventfd);1867 ret = PTR_ERR(event->eventfd);
1868 goto out_put_efile;1868 goto out_put_efile;
1869 }1869 }
1870 1870
1871 cfile = fdget(cfd);1871 cfile = fdget(cfd);
1872 if (!cfile.file) {1872 if (!fd_file(cfile)) {
1873 ret = -EBADF;1873 ret = -EBADF;
1874 goto out_put_eventfd;1874 goto out_put_eventfd;
1875 }1875 }
1876 1876
1877 /* the process need read permission on control file */1877 /* the process need read permission on control file */
1878 /* AV: shouldn't we check that it's been opened for read instead? */1878 /* AV: shouldn't we check that it's been opened for read instead? */
1879 ret = file_permission(cfile.file, MAY_READ);1879 ret = file_permission(fd_file(cfile), MAY_READ);
1880 if (ret < 0)1880 if (ret < 0)
1881 goto out_put_cfile;1881 goto out_put_cfile;
1882 1882
@@ -1884,7 +1884,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of, · 1 unmodified line
1884 * The control file must be a regular cgroup1 file. As a regular cgroup1884 * The control file must be a regular cgroup1 file. As a regular cgroup
1885 * file can't be renamed, it's safe to access its name afterwards.1885 * file can't be renamed, it's safe to access its name afterwards.
1886 */1886 */
1887 cdentry = cfile.file->f_path.dentry;1887 cdentry = fd_file(cfile)->f_path.dentry;
1888 if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) {1888 if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) {
1889 ret = -EINVAL;1889 ret = -EINVAL;
1890 goto out_put_cfile;1890 goto out_put_cfile;
@@ -1936,7 +1936,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of, · 45 unmodified lines
1936 if (ret)1936 if (ret)
1937 goto out_put_css;1937 goto out_put_css;
1938 1938
1939 vfs_poll(efile.file, &event->pt);1939 vfs_poll(fd_file(efile), &event->pt);
1940 1940
1941 spin_lock_irq(&memcg->event_list_lock);1941 spin_lock_irq(&memcg->event_list_lock);
1942 list_add(&event->list, &memcg->event_list);1942 list_add(&event->list, &memcg->event_list);
mm/readahead.c+5−5
@@ -646,7 +646,7 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count) · 645 unmodified lines
646 646
647 ret = -EBADF;647 ret = -EBADF;
648 f = fdget(fd);648 f = fdget(fd);
649 if (!f.file || !(f.file->f_mode & FMODE_READ))649 if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
650 goto out;650 goto out;
651 651
652 /*652 /*
@@ -655,12 +655,12 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count) · 2 unmodified lines
655 * on this file, then we must return -EINVAL.655 * on this file, then we must return -EINVAL.
656 */656 */
657 ret = -EINVAL;657 ret = -EINVAL;
658 if (!f.file->f_mapping || !f.file->f_mapping->a_ops ||658 if (!fd_file(f)->f_mapping || !fd_file(f)->f_mapping->a_ops ||
659 (!S_ISREG(file_inode(f.file)->i_mode) &&659 (!S_ISREG(file_inode(fd_file(f))->i_mode) &&
660 !S_ISBLK(file_inode(f.file)->i_mode)))660 !S_ISBLK(file_inode(fd_file(f))->i_mode)))
661 goto out;661 goto out;
662 662
663 ret = vfs_fadvise(f.file, offset, count, POSIX_FADV_WILLNEED);663 ret = vfs_fadvise(fd_file(f), offset, count, POSIX_FADV_WILLNEED);
664out:664out:
665 fdput(f);665 fdput(f);
666 return ret;666 return ret;
net/core/net_namespace.c+3−3
@@ -711,11 +711,11 @@ struct net *get_net_ns_by_fd(int fd) · 710 unmodified lines
711 struct fd f = fdget(fd);711 struct fd f = fdget(fd);
712 struct net *net = ERR_PTR(-EINVAL);712 struct net *net = ERR_PTR(-EINVAL);
713 713
714 if (!f.file)714 if (!fd_file(f))
715 return ERR_PTR(-EBADF);715 return ERR_PTR(-EBADF);
716 716
717 if (proc_ns_file(f.file)) {717 if (proc_ns_file(fd_file(f))) {
718 struct ns_common *ns = get_proc_ns(file_inode(f.file));718 struct ns_common *ns = get_proc_ns(file_inode(fd_file(f)));
719 if (ns->ops == &netns_operations)719 if (ns->ops == &netns_operations)
720 net = get_net(container_of(ns, struct net, ns));720 net = get_net(container_of(ns, struct net, ns));
721 }721 }
net/socket.c+6−6
@@ -556,8 +556,8 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) · 555 unmodified lines
556 struct socket *sock;556 struct socket *sock;
557 557
558 *err = -EBADF;558 *err = -EBADF;
559 if (f.file) {559 if (fd_file(f)) {
560 sock = sock_from_file(f.file);560 sock = sock_from_file(fd_file(f));
561 if (likely(sock)) {561 if (likely(sock)) {
562 *fput_needed = f.flags & FDPUT_FPUT;562 *fput_needed = f.flags & FDPUT_FPUT;
563 return sock;563 return sock;
@@ -2008,8 +2008,8 @@ int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr, · 1444 unmodified lines
2008 struct fd f;2008 struct fd f;
2009 2009
2010 f = fdget(fd);2010 f = fdget(fd);
2011 if (f.file) {2011 if (fd_file(f)) {
2012 ret = __sys_accept4_file(f.file, upeer_sockaddr,2012 ret = __sys_accept4_file(fd_file(f), upeer_sockaddr,
2013 upeer_addrlen, flags);2013 upeer_addrlen, flags);
2014 fdput(f);2014 fdput(f);
2015 }2015 }
@@ -2070,12 +2070,12 @@ int __sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen) · 54 unmodified lines
2070 struct fd f;2070 struct fd f;
2071 2071
2072 f = fdget(fd);2072 f = fdget(fd);
2073 if (f.file) {2073 if (fd_file(f)) {
2074 struct sockaddr_storage address;2074 struct sockaddr_storage address;
2075 2075
2076 ret = move_addr_to_kernel(uservaddr, addrlen, &address);2076 ret = move_addr_to_kernel(uservaddr, addrlen, &address);
2077 if (!ret)2077 if (!ret)
2078 ret = __sys_connect_file(f.file, &address, addrlen, 0);2078 ret = __sys_connect_file(fd_file(f), &address, addrlen, 0);
2079 fdput(f);2079 fdput(f);
2080 }2080 }
2081 2081
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
1068 return;1068 return;
1069 1069
1070 f = fdget(kernel_fd);1070 f = fdget(kernel_fd);
1071 if (!f.file)1071 if (!fd_file(f))
1072 return;1072 return;
1073 1073
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)),
1075 buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,1075 buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,
1076 NULL, false, NULL, 0);1076 NULL, false, NULL, 0);
1077 fdput(f);1077 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
238 struct landlock_ruleset *ruleset;238 struct landlock_ruleset *ruleset;
239 239
240 ruleset_f = fdget(fd);240 ruleset_f = fdget(fd);
241 if (!ruleset_f.file)241 if (!fd_file(ruleset_f))
242 return ERR_PTR(-EBADF);242 return ERR_PTR(-EBADF);
243 243
244 /* Checks FD type and access right. */244 /* 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) {
246 ruleset = ERR_PTR(-EBADFD);246 ruleset = ERR_PTR(-EBADFD);
247 goto out_fdput;247 goto out_fdput;
248 }248 }
249 if (!(ruleset_f.file->f_mode & mode)) {249 if (!(fd_file(ruleset_f)->f_mode & mode)) {
250 ruleset = ERR_PTR(-EPERM);250 ruleset = ERR_PTR(-EPERM);
251 goto out_fdput;251 goto out_fdput;
252 }252 }
253 ruleset = ruleset_f.file->private_data;253 ruleset = fd_file(ruleset_f)->private_data;
254 if (WARN_ON_ONCE(ruleset->num_layers != 1)) {254 if (WARN_ON_ONCE(ruleset->num_layers != 1)) {
255 ruleset = ERR_PTR(-EINVAL);255 ruleset = ERR_PTR(-EINVAL);
256 goto out_fdput;256 goto out_fdput;
@@ -277,22 +277,22 @@ static int get_path_from_fd(const s32 fd, struct path *const path) · 20 unmodified lines
277 277
278 /* Handles O_PATH. */278 /* Handles O_PATH. */
279 f = fdget_raw(fd);279 f = fdget_raw(fd);
280 if (!f.file)280 if (!fd_file(f))
281 return -EBADF;281 return -EBADF;
282 /*282 /*
283 * Forbids ruleset FDs, internal filesystems (e.g. nsfs), including283 * Forbids ruleset FDs, internal filesystems (e.g. nsfs), including
284 * pseudo filesystems that will never be mountable (e.g. sockfs,284 * pseudo filesystems that will never be mountable (e.g. sockfs,
285 * pipefs).285 * pipefs).
286 */286 */
287 if ((f.file->f_op == &ruleset_fops) ||287 if ((fd_file(f)->f_op == &ruleset_fops) ||
288 (f.file->f_path.mnt->mnt_flags & MNT_INTERNAL) ||288 (fd_file(f)->f_path.mnt->mnt_flags & MNT_INTERNAL) ||
289 (f.file->f_path.dentry->d_sb->s_flags & SB_NOUSER) ||289 (fd_file(f)->f_path.dentry->d_sb->s_flags & SB_NOUSER) ||
290 d_is_negative(f.file->f_path.dentry) ||290 d_is_negative(fd_file(f)->f_path.dentry) ||
291 IS_PRIVATE(d_backing_inode(f.file->f_path.dentry))) {291 IS_PRIVATE(d_backing_inode(fd_file(f)->f_path.dentry))) {
292 err = -EBADFD;292 err = -EBADFD;
293 goto out_fdput;293 goto out_fdput;
294 }294 }
295 *path = f.file->f_path;295 *path = fd_file(f)->f_path;
296 path_get(path);296 path_get(path);
297 297
298out_fdput:298out_fdput:
security/loadpin/loadpin.c+2−2
@@ -296,7 +296,7 @@ static int read_trusted_verity_root_digests(unsigned int fd) · 295 unmodified lines
296 return -EPERM;296 return -EPERM;
297 297
298 f = fdget(fd);298 f = fdget(fd);
299 if (!f.file)299 if (!fd_file(f))
300 return -EINVAL;300 return -EINVAL;
301 301
302 data = kzalloc(SZ_4K, GFP_KERNEL);302 data = kzalloc(SZ_4K, GFP_KERNEL);
@@ -305,7 +305,7 @@ static int read_trusted_verity_root_digests(unsigned int fd) · 2 unmodified lines
305 goto err;305 goto err;
306 }306 }
307 307
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);
309 if (rc < 0)309 if (rc < 0)
310 goto err;310 goto err;
311 311
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
2250 bool nonatomic = substream->pcm->nonatomic;2250 bool nonatomic = substream->pcm->nonatomic;
2251 CLASS(fd, f)(fd);2251 CLASS(fd, f)(fd);
2252 2252
2253 if (!f.file)2253 if (!fd_file(f))
2254 return -EBADFD;2254 return -EBADFD;
2255 if (!is_pcm_file(f.file))2255 if (!is_pcm_file(fd_file(f)))
2256 return -EBADFD;2256 return -EBADFD;
2257 2257
2258 pcm_file = f.file->private_data;2258 pcm_file = fd_file(f)->private_data;
2259 substream1 = pcm_file->substream;2259 substream1 = pcm_file->substream;
2260 2260
2261 if (substream == substream1)2261 if (substream == substream1)
virt/kvm/eventfd.c+3−3
@@ -327,12 +327,12 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) · 326 unmodified lines
327 seqcount_spinlock_init(&irqfd->irq_entry_sc, &kvm->irqfds.lock);327 seqcount_spinlock_init(&irqfd->irq_entry_sc, &kvm->irqfds.lock);
328 328
329 f = fdget(args->fd);329 f = fdget(args->fd);
330 if (!f.file) {330 if (!fd_file(f)) {
331 ret = -EBADF;331 ret = -EBADF;
332 goto out;332 goto out;
333 }333 }
334 334
335 eventfd = eventfd_ctx_fileget(f.file);335 eventfd = eventfd_ctx_fileget(fd_file(f));
336 if (IS_ERR(eventfd)) {336 if (IS_ERR(eventfd)) {
337 ret = PTR_ERR(eventfd);337 ret = PTR_ERR(eventfd);
338 goto fail;338 goto fail;
@@ -419,7 +419,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args) · 80 unmodified lines
419 * Check if there was an event already pending on the eventfd419 * Check if there was an event already pending on the eventfd
420 * before we registered, and trigger it as if we didn't miss it.420 * before we registered, and trigger it as if we didn't miss it.
421 */421 */
422 events = vfs_poll(f.file, &irqfd->pt);422 events = vfs_poll(fd_file(f), &irqfd->pt);
423 423
424 if (events & EPOLLIN)424 if (events & EPOLLIN)
425 schedule_work(&irqfd->inject);425 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
194 int ret;194 int ret;
195 195
196 f = fdget(fd);196 f = fdget(fd);
197 if (!f.file)197 if (!fd_file(f))
198 return -EBADF;198 return -EBADF;
199 199
200 ret = -ENOENT;200 ret = -ENOENT;
@@ -202,7 +202,7 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd) · 1 unmodified line
202 mutex_lock(&kv->lock);202 mutex_lock(&kv->lock);
203 203
204 list_for_each_entry(kvf, &kv->file_list, node) {204 list_for_each_entry(kvf, &kv->file_list, node) {
205 if (kvf->file != f.file)205 if (kvf->file != fd_file(f))
206 continue;206 continue;
207 207
208 list_del(&kvf->node);208 list_del(&kvf->node);
@@ -240,7 +240,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev, · 31 unmodified lines
240 return -EFAULT;240 return -EFAULT;
241 241
242 f = fdget(param.groupfd);242 f = fdget(param.groupfd);
243 if (!f.file)243 if (!fd_file(f))
244 return -EBADF;244 return -EBADF;
245 245
246 ret = -ENOENT;246 ret = -ENOENT;
@@ -248,7 +248,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev, · 1 unmodified line
248 mutex_lock(&kv->lock);248 mutex_lock(&kv->lock);
249 249
250 list_for_each_entry(kvf, &kv->file_list, node) {250 list_for_each_entry(kvf, &kv->file_list, node) {
251 if (kvf->file != f.file)251 if (kvf->file != fd_file(f))
252 continue;252 continue;
253 253
254 if (!kvf->iommu_group) {254 if (!kvf->iommu_group) {