Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

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

* tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
add struct fd constructors, get rid of __to_fd()
struct fd: representation change
introduce fd_file(), convert all accessors to it.

+564 -561
+2 -2
arch/alpha/kernel/osf_sys.c
··· 160 160 .count = count 161 161 }; 162 162 163 - if (!arg.file) 163 + if (!fd_file(arg)) 164 164 return -EBADF; 165 165 166 - error = iterate_dir(arg.file, &buf.ctx); 166 + error = iterate_dir(fd_file(arg), &buf.ctx); 167 167 if (error >= 0) 168 168 error = buf.error; 169 169 if (count != buf.count)
+5 -5
arch/arm/kernel/sys_oabi-compat.c
··· 239 239 struct flock64 flock; 240 240 long err = -EBADF; 241 241 242 - if (!f.file) 242 + if (!fd_file(f)) 243 243 goto out; 244 244 245 245 switch (cmd) { 246 246 case F_GETLK64: 247 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 249 if (err) 250 250 break; 251 251 err = get_oabi_flock(&flock, argp); 252 252 if (err) 253 253 break; 254 - err = fcntl_getlk64(f.file, cmd, &flock); 254 + err = fcntl_getlk64(fd_file(f), cmd, &flock); 255 255 if (!err) 256 256 err = put_oabi_flock(&flock, argp); 257 257 break; ··· 259 259 case F_SETLKW64: 260 260 case F_OFD_SETLK: 261 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 263 if (err) 264 264 break; 265 265 err = get_oabi_flock(&flock, argp); 266 266 if (err) 267 267 break; 268 - err = fcntl_setlk64(fd, f.file, cmd, &flock); 268 + err = fcntl_setlk64(fd, fd_file(f), cmd, &flock); 269 269 break; 270 270 default: 271 271 err = sys_fcntl64(fd, cmd, arg);
+2 -2
arch/powerpc/kvm/book3s_64_vio.c
··· 118 118 struct fd f; 119 119 120 120 f = fdget(tablefd); 121 - if (!f.file) 121 + if (!fd_file(f)) 122 122 return -EBADF; 123 123 124 124 rcu_read_lock(); 125 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 127 found = true; 128 128 break; 129 129 }
+6 -6
arch/powerpc/kvm/powerpc.c
··· 1938 1938 1939 1939 r = -EBADF; 1940 1940 f = fdget(cap->args[0]); 1941 - if (!f.file) 1941 + if (!fd_file(f)) 1942 1942 break; 1943 1943 1944 1944 r = -EPERM; 1945 - dev = kvm_device_from_filp(f.file); 1945 + dev = kvm_device_from_filp(fd_file(f)); 1946 1946 if (dev) 1947 1947 r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]); 1948 1948 ··· 1957 1957 1958 1958 r = -EBADF; 1959 1959 f = fdget(cap->args[0]); 1960 - if (!f.file) 1960 + if (!fd_file(f)) 1961 1961 break; 1962 1962 1963 1963 r = -EPERM; 1964 - dev = kvm_device_from_filp(f.file); 1964 + dev = kvm_device_from_filp(fd_file(f)); 1965 1965 if (dev) { 1966 1966 if (xics_on_xive()) 1967 1967 r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]); ··· 1980 1980 1981 1981 r = -EBADF; 1982 1982 f = fdget(cap->args[0]); 1983 - if (!f.file) 1983 + if (!fd_file(f)) 1984 1984 break; 1985 1985 1986 1986 r = -ENXIO; ··· 1990 1990 } 1991 1991 1992 1992 r = -EPERM; 1993 - dev = kvm_device_from_filp(f.file); 1993 + dev = kvm_device_from_filp(fd_file(f)); 1994 1994 if (dev) 1995 1995 r = kvmppc_xive_native_connect_vcpu(dev, vcpu, 1996 1996 cap->args[1]);
+4 -4
arch/powerpc/platforms/cell/spu_syscalls.c
··· 66 66 if (flags & SPU_CREATE_AFFINITY_SPU) { 67 67 struct fd neighbor = fdget(neighbor_fd); 68 68 ret = -EBADF; 69 - if (neighbor.file) { 70 - ret = calls->create_thread(name, flags, mode, neighbor.file); 69 + if (fd_file(neighbor)) { 70 + ret = calls->create_thread(name, flags, mode, fd_file(neighbor)); 71 71 fdput(neighbor); 72 72 } 73 73 } else ··· 89 89 90 90 ret = -EBADF; 91 91 arg = fdget(fd); 92 - if (arg.file) { 93 - ret = calls->spu_run(arg.file, unpc, ustatus); 92 + if (fd_file(arg)) { 93 + ret = calls->spu_run(fd_file(arg), unpc, ustatus); 94 94 fdput(arg); 95 95 } 96 96
+2 -2
arch/x86/kernel/cpu/sgx/main.c
··· 903 903 { 904 904 struct fd f = fdget(attribute_fd); 905 905 906 - if (!f.file) 906 + if (!fd_file(f)) 907 907 return -EINVAL; 908 908 909 - if (f.file->f_op != &sgx_provision_fops) { 909 + if (fd_file(f)->f_op != &sgx_provision_fops) { 910 910 fdput(f); 911 911 return -EINVAL; 912 912 }
+8 -8
arch/x86/kvm/svm/sev.c
··· 534 534 int ret; 535 535 536 536 f = fdget(fd); 537 - if (!f.file) 537 + if (!fd_file(f)) 538 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 542 fdput(f); 543 543 return ret; ··· 2078 2078 bool charged = false; 2079 2079 int ret; 2080 2080 2081 - if (!f.file) 2081 + if (!fd_file(f)) 2082 2082 return -EBADF; 2083 2083 2084 - if (!file_is_kvm(f.file)) { 2084 + if (!file_is_kvm(fd_file(f))) { 2085 2085 ret = -EBADF; 2086 2086 goto out_fput; 2087 2087 } 2088 2088 2089 - source_kvm = f.file->private_data; 2089 + source_kvm = fd_file(f)->private_data; 2090 2090 ret = sev_lock_two_vms(kvm, source_kvm); 2091 2091 if (ret) 2092 2092 goto out_fput; ··· 2803 2803 struct kvm_sev_info *source_sev, *mirror_sev; 2804 2804 int ret; 2805 2805 2806 - if (!f.file) 2806 + if (!fd_file(f)) 2807 2807 return -EBADF; 2808 2808 2809 - if (!file_is_kvm(f.file)) { 2809 + if (!file_is_kvm(fd_file(f))) { 2810 2810 ret = -EBADF; 2811 2811 goto e_source_fput; 2812 2812 } 2813 2813 2814 - source_kvm = f.file->private_data; 2814 + source_kvm = fd_file(f)->private_data; 2815 2815 ret = sev_lock_two_vms(kvm, source_kvm); 2816 2816 if (ret) 2817 2817 goto e_source_fput;
+4 -4
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
··· 42 42 uint32_t id; 43 43 int r; 44 44 45 - if (!f.file) 45 + if (!fd_file(f)) 46 46 return -EINVAL; 47 47 48 - r = amdgpu_file_to_fpriv(f.file, &fpriv); 48 + r = amdgpu_file_to_fpriv(fd_file(f), &fpriv); 49 49 if (r) { 50 50 fdput(f); 51 51 return r; ··· 71 71 struct amdgpu_ctx *ctx; 72 72 int r; 73 73 74 - if (!f.file) 74 + if (!fd_file(f)) 75 75 return -EINVAL; 76 76 77 - r = amdgpu_file_to_fpriv(f.file, &fpriv); 77 + r = amdgpu_file_to_fpriv(fd_file(f), &fpriv); 78 78 if (r) { 79 79 fdput(f); 80 80 return r;
+3 -3
drivers/gpu/drm/drm_syncobj.c
··· 715 715 struct fd f = fdget(fd); 716 716 int ret; 717 717 718 - if (!f.file) 718 + if (!fd_file(f)) 719 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 722 fdput(f); 723 723 return -EINVAL; 724 724 } 725 725 726 726 /* take a reference to put in the idr */ 727 - syncobj = f.file->private_data; 727 + syncobj = fd_file(f)->private_data; 728 728 drm_syncobj_get(syncobj); 729 729 730 730 idr_preload(GFP_KERNEL);
+3 -3
drivers/infiniband/core/ucma.c
··· 1624 1624 1625 1625 /* Get current fd to protect against it being closed */ 1626 1626 f = fdget(cmd.fd); 1627 - if (!f.file) 1627 + if (!fd_file(f)) 1628 1628 return -ENOENT; 1629 - if (f.file->f_op != &ucma_fops) { 1629 + if (fd_file(f)->f_op != &ucma_fops) { 1630 1630 ret = -EINVAL; 1631 1631 goto file_put; 1632 1632 } 1633 - cur_file = f.file->private_data; 1633 + cur_file = fd_file(f)->private_data; 1634 1634 1635 1635 /* Validate current fd and prevent destruction of id. */ 1636 1636 ctx = ucma_get_ctx(cur_file, cmd.id);
+5 -5
drivers/infiniband/core/uverbs_cmd.c
··· 572 572 struct inode *inode = NULL; 573 573 int new_xrcd = 0; 574 574 struct ib_device *ib_dev; 575 - struct fd f = {}; 575 + struct fd f = EMPTY_FD; 576 576 int ret; 577 577 578 578 ret = uverbs_request(attrs, &cmd, sizeof(cmd)); ··· 584 584 if (cmd.fd != -1) { 585 585 /* search for file descriptor */ 586 586 f = fdget(cmd.fd); 587 - if (!f.file) { 587 + if (!fd_file(f)) { 588 588 ret = -EBADF; 589 589 goto err_tree_mutex_unlock; 590 590 } 591 591 592 - inode = file_inode(f.file); 592 + inode = file_inode(fd_file(f)); 593 593 xrcd = find_xrcd(ibudev, inode); 594 594 if (!xrcd && !(cmd.oflags & O_CREAT)) { 595 595 /* no file descriptor. Need CREATE flag */ ··· 632 632 atomic_inc(&xrcd->usecnt); 633 633 } 634 634 635 - if (f.file) 635 + if (fd_file(f)) 636 636 fdput(f); 637 637 638 638 mutex_unlock(&ibudev->xrcd_tree_mutex); ··· 648 648 uobj_alloc_abort(&obj->uobject, attrs); 649 649 650 650 err_tree_mutex_unlock: 651 - if (f.file) 651 + if (fd_file(f)) 652 652 fdput(f); 653 653 654 654 mutex_unlock(&ibudev->xrcd_tree_mutex);
+3 -3
drivers/media/mc/mc-request.c
··· 254 254 return ERR_PTR(-EBADR); 255 255 256 256 f = fdget(request_fd); 257 - if (!f.file) 257 + if (!fd_file(f)) 258 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 261 goto err_fput; 262 - req = f.file->private_data; 262 + req = fd_file(f)->private_data; 263 263 if (req->mdev != mdev) 264 264 goto err_fput; 265 265
+4 -4
drivers/media/rc/lirc_dev.c
··· 820 820 struct lirc_fh *fh; 821 821 struct rc_dev *dev; 822 822 823 - if (!f.file) 823 + if (!fd_file(f)) 824 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 827 fdput(f); 828 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 832 fdput(f); 833 833 return ERR_PTR(-EPERM); 834 834 } 835 835 836 - fh = f.file->private_data; 836 + fh = fd_file(f)->private_data; 837 837 dev = fh->rc; 838 838 839 839 get_device(&dev->dev);
+3 -3
drivers/vfio/group.c
··· 112 112 return -EFAULT; 113 113 114 114 f = fdget(fd); 115 - if (!f.file) 115 + if (!fd_file(f)) 116 116 return -EBADF; 117 117 118 118 mutex_lock(&group->group_lock); ··· 125 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 129 if (container) { 130 130 ret = vfio_container_attach_group(container, group); 131 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 135 if (!IS_ERR(iommufd)) { 136 136 if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) && 137 137 group->type == VFIO_NO_IOMMU)
+3 -3
drivers/vfio/virqfd.c
··· 134 134 INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject); 135 135 136 136 irqfd = fdget(fd); 137 - if (!irqfd.file) { 137 + if (!fd_file(irqfd)) { 138 138 ret = -EBADF; 139 139 goto err_fd; 140 140 } 141 141 142 - ctx = eventfd_ctx_fileget(irqfd.file); 142 + ctx = eventfd_ctx_fileget(fd_file(irqfd)); 143 143 if (IS_ERR(ctx)) { 144 144 ret = PTR_ERR(ctx); 145 145 goto err_ctx; ··· 171 171 init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup); 172 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 177 * Check if there was an event already pending on the eventfd
+3 -3
drivers/virt/acrn/irqfd.c
··· 125 125 INIT_WORK(&irqfd->shutdown, hsm_irqfd_shutdown_work); 126 126 127 127 f = fdget(args->fd); 128 - if (!f.file) { 128 + if (!fd_file(f)) { 129 129 ret = -EBADF; 130 130 goto out; 131 131 } 132 132 133 - eventfd = eventfd_ctx_fileget(f.file); 133 + eventfd = eventfd_ctx_fileget(fd_file(f)); 134 134 if (IS_ERR(eventfd)) { 135 135 ret = PTR_ERR(eventfd); 136 136 goto fail; ··· 157 157 mutex_unlock(&vm->irqfds_lock); 158 158 159 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 162 if (events & EPOLLIN) 163 163 acrn_irqfd_inject(irqfd);
+5 -5
drivers/xen/privcmd.c
··· 959 959 INIT_WORK(&kirqfd->shutdown, irqfd_shutdown); 960 960 961 961 f = fdget(irqfd->fd); 962 - if (!f.file) { 962 + if (!fd_file(f)) { 963 963 ret = -EBADF; 964 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 968 if (IS_ERR(kirqfd->eventfd)) { 969 969 ret = PTR_ERR(kirqfd->eventfd); 970 970 goto error_fd_put; ··· 995 995 * Check if there was an event already pending on the eventfd before we 996 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 999 if (events & EPOLLIN) 1000 1000 irqfd_inject(kirqfd); 1001 1001 ··· 1345 1345 return -ENOMEM; 1346 1346 1347 1347 f = fdget(ioeventfd->event_fd); 1348 - if (!f.file) { 1348 + if (!fd_file(f)) { 1349 1349 ret = -EBADF; 1350 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 1354 fdput(f); 1355 1355 1356 1356 if (IS_ERR(kioeventfd->eventfd)) {
+2 -2
fs/btrfs/ioctl.c
··· 1310 1310 } else { 1311 1311 struct fd src = fdget(fd); 1312 1312 struct inode *src_inode; 1313 - if (!src.file) { 1313 + if (!fd_file(src)) { 1314 1314 ret = -EINVAL; 1315 1315 goto out_drop_write; 1316 1316 } 1317 1317 1318 - src_inode = file_inode(src.file); 1318 + src_inode = file_inode(fd_file(src)); 1319 1319 if (src_inode->i_sb != file_inode(file)->i_sb) { 1320 1320 btrfs_info(BTRFS_I(file_inode(file))->root->fs_info, 1321 1321 "Snapshot src from another FS");
+2 -2
fs/eventfd.c
··· 349 349 { 350 350 struct eventfd_ctx *ctx; 351 351 struct fd f = fdget(fd); 352 - if (!f.file) 352 + if (!fd_file(f)) 353 353 return ERR_PTR(-EBADF); 354 - ctx = eventfd_ctx_fileget(f.file); 354 + ctx = eventfd_ctx_fileget(fd_file(f)); 355 355 fdput(f); 356 356 return ctx; 357 357 }
+15 -15
fs/eventpoll.c
··· 2261 2261 2262 2262 error = -EBADF; 2263 2263 f = fdget(epfd); 2264 - if (!f.file) 2264 + if (!fd_file(f)) 2265 2265 goto error_return; 2266 2266 2267 2267 /* Get the "struct file *" for the target file */ 2268 2268 tf = fdget(fd); 2269 - if (!tf.file) 2269 + if (!fd_file(tf)) 2270 2270 goto error_fput; 2271 2271 2272 2272 /* The target file descriptor must support poll */ 2273 2273 error = -EPERM; 2274 - if (!file_can_poll(tf.file)) 2274 + if (!file_can_poll(fd_file(tf))) 2275 2275 goto error_tgt_fput; 2276 2276 2277 2277 /* Check if EPOLLWAKEUP is allowed */ ··· 2284 2284 * adding an epoll file descriptor inside itself. 2285 2285 */ 2286 2286 error = -EINVAL; 2287 - if (f.file == tf.file || !is_file_epoll(f.file)) 2287 + if (fd_file(f) == fd_file(tf) || !is_file_epoll(fd_file(f))) 2288 2288 goto error_tgt_fput; 2289 2289 2290 2290 /* ··· 2295 2295 if (ep_op_has_event(op) && (epds->events & EPOLLEXCLUSIVE)) { 2296 2296 if (op == EPOLL_CTL_MOD) 2297 2297 goto error_tgt_fput; 2298 - if (op == EPOLL_CTL_ADD && (is_file_epoll(tf.file) || 2298 + if (op == EPOLL_CTL_ADD && (is_file_epoll(fd_file(tf)) || 2299 2299 (epds->events & ~EPOLLEXCLUSIVE_OK_BITS))) 2300 2300 goto error_tgt_fput; 2301 2301 } ··· 2304 2304 * At this point it is safe to assume that the "private_data" contains 2305 2305 * our own data structure. 2306 2306 */ 2307 - ep = f.file->private_data; 2307 + ep = fd_file(f)->private_data; 2308 2308 2309 2309 /* 2310 2310 * When we insert an epoll file descriptor inside another epoll file ··· 2325 2325 if (error) 2326 2326 goto error_tgt_fput; 2327 2327 if (op == EPOLL_CTL_ADD) { 2328 - if (READ_ONCE(f.file->f_ep) || ep->gen == loop_check_gen || 2329 - is_file_epoll(tf.file)) { 2328 + if (READ_ONCE(fd_file(f)->f_ep) || ep->gen == loop_check_gen || 2329 + is_file_epoll(fd_file(tf))) { 2330 2330 mutex_unlock(&ep->mtx); 2331 2331 error = epoll_mutex_lock(&epnested_mutex, 0, nonblock); 2332 2332 if (error) 2333 2333 goto error_tgt_fput; 2334 2334 loop_check_gen++; 2335 2335 full_check = 1; 2336 - if (is_file_epoll(tf.file)) { 2337 - tep = tf.file->private_data; 2336 + if (is_file_epoll(fd_file(tf))) { 2337 + tep = fd_file(tf)->private_data; 2338 2338 error = -ELOOP; 2339 2339 if (ep_loop_check(ep, tep) != 0) 2340 2340 goto error_tgt_fput; ··· 2350 2350 * above, we can be sure to be able to use the item looked up by 2351 2351 * ep_find() till we release the mutex. 2352 2352 */ 2353 - epi = ep_find(ep, tf.file, fd); 2353 + epi = ep_find(ep, fd_file(tf), fd); 2354 2354 2355 2355 error = -EINVAL; 2356 2356 switch (op) { 2357 2357 case EPOLL_CTL_ADD: 2358 2358 if (!epi) { 2359 2359 epds->events |= EPOLLERR | EPOLLHUP; 2360 - error = ep_insert(ep, epds, tf.file, fd, full_check); 2360 + error = ep_insert(ep, epds, fd_file(tf), fd, full_check); 2361 2361 } else 2362 2362 error = -EEXIST; 2363 2363 break; ··· 2438 2438 2439 2439 /* Get the "struct file *" for the eventpoll file */ 2440 2440 f = fdget(epfd); 2441 - if (!f.file) 2441 + if (!fd_file(f)) 2442 2442 return -EBADF; 2443 2443 2444 2444 /* ··· 2446 2446 * the user passed to us _is_ an eventpoll file. 2447 2447 */ 2448 2448 error = -EINVAL; 2449 - if (!is_file_epoll(f.file)) 2449 + if (!is_file_epoll(fd_file(f))) 2450 2450 goto error_fput; 2451 2451 2452 2452 /* 2453 2453 * At this point it is safe to assume that the "private_data" contains 2454 2454 * our own data structure. 2455 2455 */ 2456 - ep = f.file->private_data; 2456 + ep = fd_file(f)->private_data; 2457 2457 2458 2458 /* Time to fish for events ... */ 2459 2459 error = ep_poll(ep, events, maxevents, to);
+3 -3
fs/ext4/ioctl.c
··· 1343 1343 me.moved_len = 0; 1344 1344 1345 1345 donor = fdget(me.donor_fd); 1346 - if (!donor.file) 1346 + if (!fd_file(donor)) 1347 1347 return -EBADF; 1348 1348 1349 - if (!(donor.file->f_mode & FMODE_WRITE)) { 1349 + if (!(fd_file(donor)->f_mode & FMODE_WRITE)) { 1350 1350 err = -EBADF; 1351 1351 goto mext_out; 1352 1352 } ··· 1367 1367 if (err) 1368 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 1371 me.donor_start, me.len, &me.moved_len); 1372 1372 mnt_drop_write_file(filp); 1373 1373
+3 -3
fs/f2fs/file.c
··· 3014 3014 return -EBADF; 3015 3015 3016 3016 dst = fdget(range->dst_fd); 3017 - if (!dst.file) 3017 + if (!fd_file(dst)) 3018 3018 return -EBADF; 3019 3019 3020 - if (!(dst.file->f_mode & FMODE_WRITE)) { 3020 + if (!(fd_file(dst)->f_mode & FMODE_WRITE)) { 3021 3021 err = -EBADF; 3022 3022 goto err_out; 3023 3023 } ··· 3026 3026 if (err) 3027 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 3030 range->pos_out, range->len); 3031 3031 3032 3032 mnt_drop_write_file(filp);
+19 -19
fs/fcntl.c
··· 405 405 * overkill, but given our lockless file pointer lookup, the 406 406 * alternatives are complicated. 407 407 */ 408 - return f.file == filp; 408 + return fd_file(f) == filp; 409 409 } 410 410 411 411 /* Let the caller figure out whether a given file was just created. */ ··· 573 573 struct fd f = fdget_raw(fd); 574 574 long err = -EBADF; 575 575 576 - if (!f.file) 576 + if (!fd_file(f)) 577 577 goto out; 578 578 579 - if (unlikely(f.file->f_mode & FMODE_PATH)) { 579 + if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) { 580 580 if (!check_fcntl_cmd(cmd)) 581 581 goto out1; 582 582 } 583 583 584 - err = security_file_fcntl(f.file, cmd, arg); 584 + err = security_file_fcntl(fd_file(f), cmd, arg); 585 585 if (!err) 586 - err = do_fcntl(fd, cmd, arg, f.file); 586 + err = do_fcntl(fd, cmd, arg, fd_file(f)); 587 587 588 588 out1: 589 589 fdput(f); ··· 600 600 struct flock64 flock; 601 601 long err = -EBADF; 602 602 603 - if (!f.file) 603 + if (!fd_file(f)) 604 604 goto out; 605 605 606 - if (unlikely(f.file->f_mode & FMODE_PATH)) { 606 + if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) { 607 607 if (!check_fcntl_cmd(cmd)) 608 608 goto out1; 609 609 } 610 610 611 - err = security_file_fcntl(f.file, cmd, arg); 611 + err = security_file_fcntl(fd_file(f), cmd, arg); 612 612 if (err) 613 613 goto out1; 614 614 ··· 618 618 err = -EFAULT; 619 619 if (copy_from_user(&flock, argp, sizeof(flock))) 620 620 break; 621 - err = fcntl_getlk64(f.file, cmd, &flock); 621 + err = fcntl_getlk64(fd_file(f), cmd, &flock); 622 622 if (!err && copy_to_user(argp, &flock, sizeof(flock))) 623 623 err = -EFAULT; 624 624 break; ··· 629 629 err = -EFAULT; 630 630 if (copy_from_user(&flock, argp, sizeof(flock))) 631 631 break; 632 - err = fcntl_setlk64(fd, f.file, cmd, &flock); 632 + err = fcntl_setlk64(fd, fd_file(f), cmd, &flock); 633 633 break; 634 634 default: 635 - err = do_fcntl(fd, cmd, arg, f.file); 635 + err = do_fcntl(fd, cmd, arg, fd_file(f)); 636 636 break; 637 637 } 638 638 out1: ··· 737 737 struct flock flock; 738 738 long err = -EBADF; 739 739 740 - if (!f.file) 740 + if (!fd_file(f)) 741 741 return err; 742 742 743 - if (unlikely(f.file->f_mode & FMODE_PATH)) { 743 + if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) { 744 744 if (!check_fcntl_cmd(cmd)) 745 745 goto out_put; 746 746 } 747 747 748 - err = security_file_fcntl(f.file, cmd, arg); 748 + err = security_file_fcntl(fd_file(f), cmd, arg); 749 749 if (err) 750 750 goto out_put; 751 751 ··· 754 754 err = get_compat_flock(&flock, compat_ptr(arg)); 755 755 if (err) 756 756 break; 757 - err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock); 757 + err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock); 758 758 if (err) 759 759 break; 760 760 err = fixup_compat_flock(&flock); ··· 766 766 err = get_compat_flock64(&flock, compat_ptr(arg)); 767 767 if (err) 768 768 break; 769 - err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock); 769 + err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock); 770 770 if (!err) 771 771 err = put_compat_flock64(&flock, compat_ptr(arg)); 772 772 break; ··· 775 775 err = get_compat_flock(&flock, compat_ptr(arg)); 776 776 if (err) 777 777 break; 778 - err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock); 778 + err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock); 779 779 break; 780 780 case F_SETLK64: 781 781 case F_SETLKW64: ··· 784 784 err = get_compat_flock64(&flock, compat_ptr(arg)); 785 785 if (err) 786 786 break; 787 - err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock); 787 + err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock); 788 788 break; 789 789 default: 790 - err = do_fcntl(fd, cmd, arg, f.file); 790 + err = do_fcntl(fd, cmd, arg, fd_file(f)); 791 791 break; 792 792 } 793 793 out_put:
+2 -2
fs/fhandle.c
··· 140 140 spin_unlock(&fs->lock); 141 141 } else { 142 142 struct fd f = fdget(fd); 143 - if (!f.file) 143 + if (!fd_file(f)) 144 144 return -EBADF; 145 - *root = f.file->f_path; 145 + *root = fd_file(f)->f_path; 146 146 path_get(root); 147 147 fdput(f); 148 148 }
+13 -13
fs/file.c
··· 1124 1124 * The fput_needed flag returned by fget_light should be passed to the 1125 1125 * corresponding fput_light. 1126 1126 */ 1127 - static unsigned long __fget_light(unsigned int fd, fmode_t mask) 1127 + static inline struct fd __fget_light(unsigned int fd, fmode_t mask) 1128 1128 { 1129 1129 struct files_struct *files = current->files; 1130 1130 struct file *file; ··· 1141 1141 if (likely(atomic_read_acquire(&files->count) == 1)) { 1142 1142 file = files_lookup_fd_raw(files, fd); 1143 1143 if (!file || unlikely(file->f_mode & mask)) 1144 - return 0; 1145 - return (unsigned long)file; 1144 + return EMPTY_FD; 1145 + return BORROWED_FD(file); 1146 1146 } else { 1147 1147 file = __fget_files(files, fd, mask); 1148 1148 if (!file) 1149 - return 0; 1150 - return FDPUT_FPUT | (unsigned long)file; 1149 + return EMPTY_FD; 1150 + return CLONED_FD(file); 1151 1151 } 1152 1152 } 1153 - unsigned long __fdget(unsigned int fd) 1153 + struct fd fdget(unsigned int fd) 1154 1154 { 1155 1155 return __fget_light(fd, FMODE_PATH); 1156 1156 } 1157 - EXPORT_SYMBOL(__fdget); 1157 + EXPORT_SYMBOL(fdget); 1158 1158 1159 - unsigned long __fdget_raw(unsigned int fd) 1159 + struct fd fdget_raw(unsigned int fd) 1160 1160 { 1161 1161 return __fget_light(fd, 0); 1162 1162 } ··· 1177 1177 (file_count(file) > 1 || file->f_op->iterate_shared); 1178 1178 } 1179 1179 1180 - unsigned long __fdget_pos(unsigned int fd) 1180 + struct fd fdget_pos(unsigned int fd) 1181 1181 { 1182 - unsigned long v = __fdget(fd); 1183 - struct file *file = (struct file *)(v & ~3); 1182 + struct fd f = fdget(fd); 1183 + struct file *file = fd_file(f); 1184 1184 1185 1185 if (file && file_needs_f_pos_lock(file)) { 1186 - v |= FDPUT_POS_UNLOCK; 1186 + f.word |= FDPUT_POS_UNLOCK; 1187 1187 mutex_lock(&file->f_pos_lock); 1188 1188 } 1189 - return v; 1189 + return f; 1190 1190 } 1191 1191 1192 1192 void __f_unlock_pos(struct file *f)
+3 -3
fs/fsopen.c
··· 394 394 } 395 395 396 396 f = fdget(fd); 397 - if (!f.file) 397 + if (!fd_file(f)) 398 398 return -EBADF; 399 399 ret = -EINVAL; 400 - if (f.file->f_op != &fscontext_fops) 400 + if (fd_file(f)->f_op != &fscontext_fops) 401 401 goto out_f; 402 402 403 - fc = f.file->private_data; 403 + fc = fd_file(f)->private_data; 404 404 if (fc->ops == &legacy_fs_context_ops) { 405 405 switch (cmd) { 406 406 case FSCONFIG_SET_BINARY:
+3 -3
fs/fuse/dev.c
··· 2329 2329 return -EFAULT; 2330 2330 2331 2331 f = fdget(oldfd); 2332 - if (!f.file) 2332 + if (!fd_file(f)) 2333 2333 return -EINVAL; 2334 2334 2335 2335 /* 2336 2336 * Check against file->f_op because CUSE 2337 2337 * uses the same ioctl handler. 2338 2338 */ 2339 - if (f.file->f_op == file->f_op) 2340 - fud = fuse_get_dev(f.file); 2339 + if (fd_file(f)->f_op == file->f_op) 2340 + fud = fuse_get_dev(fd_file(f)); 2341 2341 2342 2342 res = -EINVAL; 2343 2343 if (fud) {
+15 -15
fs/ioctl.c
··· 235 235 loff_t cloned; 236 236 int ret; 237 237 238 - if (!src_file.file) 238 + if (!fd_file(src_file)) 239 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 241 olen, 0); 242 242 if (cloned < 0) 243 243 ret = cloned; ··· 895 895 struct fd f = fdget(fd); 896 896 int error; 897 897 898 - if (!f.file) 898 + if (!fd_file(f)) 899 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 902 if (error) 903 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 906 if (error == -ENOIOCTLCMD) 907 - error = vfs_ioctl(f.file, cmd, arg); 907 + error = vfs_ioctl(fd_file(f), cmd, arg); 908 908 909 909 out: 910 910 fdput(f); ··· 953 953 struct fd f = fdget(fd); 954 954 int error; 955 955 956 - if (!f.file) 956 + if (!fd_file(f)) 957 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 960 if (error) 961 961 goto out; 962 962 963 963 switch (cmd) { 964 964 /* FICLONE takes an int argument, so don't use compat_ptr() */ 965 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 967 break; 968 968 969 969 #if defined(CONFIG_X86_64) 970 970 /* these get messy on amd64 due to alignment differences */ 971 971 case FS_IOC_RESVSP_32: 972 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 974 break; 975 975 case FS_IOC_UNRESVSP_32: 976 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 978 compat_ptr(arg)); 979 979 break; 980 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 982 compat_ptr(arg)); 983 983 break; 984 984 #endif ··· 998 998 * argument. 999 999 */ 1000 1000 default: 1001 - error = do_vfs_ioctl(f.file, fd, cmd, 1001 + error = do_vfs_ioctl(fd_file(f), fd, cmd, 1002 1002 (unsigned long)compat_ptr(arg)); 1003 1003 if (error != -ENOIOCTLCMD) 1004 1004 break; 1005 1005 1006 - if (f.file->f_op->compat_ioctl) 1007 - error = f.file->f_op->compat_ioctl(f.file, cmd, arg); 1006 + if (fd_file(f)->f_op->compat_ioctl) 1007 + error = fd_file(f)->f_op->compat_ioctl(fd_file(f), cmd, arg); 1008 1008 if (error == -ENOIOCTLCMD) 1009 1009 error = -ENOTTY; 1010 1010 break;
+2 -2
fs/kernel_read_file.c
··· 178 178 struct fd f = fdget(fd); 179 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 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); 185 185 out: 186 186 fdput(f); 187 187 return ret;
+7 -7
fs/locks.c
··· 2157 2157 2158 2158 error = -EBADF; 2159 2159 f = fdget(fd); 2160 - if (!f.file) 2160 + if (!fd_file(f)) 2161 2161 return error; 2162 2162 2163 - if (type != F_UNLCK && !(f.file->f_mode & (FMODE_READ | FMODE_WRITE))) 2163 + if (type != F_UNLCK && !(fd_file(f)->f_mode & (FMODE_READ | FMODE_WRITE))) 2164 2164 goto out_putf; 2165 2165 2166 - flock_make_lock(f.file, &fl, type); 2166 + flock_make_lock(fd_file(f), &fl, type); 2167 2167 2168 - error = security_file_lock(f.file, fl.c.flc_type); 2168 + error = security_file_lock(fd_file(f), fl.c.flc_type); 2169 2169 if (error) 2170 2170 goto out_putf; 2171 2171 ··· 2173 2173 if (can_sleep) 2174 2174 fl.c.flc_flags |= FL_SLEEP; 2175 2175 2176 - if (f.file->f_op->flock) 2177 - error = f.file->f_op->flock(f.file, 2176 + if (fd_file(f)->f_op->flock) 2177 + error = fd_file(f)->f_op->flock(fd_file(f), 2178 2178 (can_sleep) ? F_SETLKW : F_SETLK, 2179 2179 &fl); 2180 2180 else 2181 - error = locks_lock_file_wait(f.file, &fl); 2181 + error = locks_lock_file_wait(fd_file(f), &fl); 2182 2182 2183 2183 locks_release_private(&fl); 2184 2184 out_putf:
+5 -5
fs/namei.c
··· 2506 2506 struct fd f = fdget_raw(nd->dfd); 2507 2507 struct dentry *dentry; 2508 2508 2509 - if (!f.file) 2509 + if (!fd_file(f)) 2510 2510 return ERR_PTR(-EBADF); 2511 2511 2512 2512 if (flags & LOOKUP_LINKAT_EMPTY) { 2513 - if (f.file->f_cred != current_cred() && 2514 - !ns_capable(f.file->f_cred->user_ns, CAP_DAC_READ_SEARCH)) { 2513 + if (fd_file(f)->f_cred != current_cred() && 2514 + !ns_capable(fd_file(f)->f_cred->user_ns, CAP_DAC_READ_SEARCH)) { 2515 2515 fdput(f); 2516 2516 return ERR_PTR(-ENOENT); 2517 2517 } 2518 2518 } 2519 2519 2520 - dentry = f.file->f_path.dentry; 2520 + dentry = fd_file(f)->f_path.dentry; 2521 2521 2522 2522 if (*s && unlikely(!d_can_lookup(dentry))) { 2523 2523 fdput(f); 2524 2524 return ERR_PTR(-ENOTDIR); 2525 2525 } 2526 2526 2527 - nd->path = f.file->f_path; 2527 + nd->path = fd_file(f)->f_path; 2528 2528 if (flags & LOOKUP_RCU) { 2529 2529 nd->inode = nd->path.dentry->d_inode; 2530 2530 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
+9 -9
fs/namespace.c
··· 4134 4134 } 4135 4135 4136 4136 f = fdget(fs_fd); 4137 - if (!f.file) 4137 + if (!fd_file(f)) 4138 4138 return -EBADF; 4139 4139 4140 4140 ret = -EINVAL; 4141 - if (f.file->f_op != &fscontext_fops) 4141 + if (fd_file(f)->f_op != &fscontext_fops) 4142 4142 goto err_fsfd; 4143 4143 4144 - fc = f.file->private_data; 4144 + fc = fd_file(f)->private_data; 4145 4145 4146 4146 ret = mutex_lock_interruptible(&fc->uapi_mutex); 4147 4147 if (ret < 0) ··· 4684 4684 return -EINVAL; 4685 4685 4686 4686 f = fdget(attr->userns_fd); 4687 - if (!f.file) 4687 + if (!fd_file(f)) 4688 4688 return -EBADF; 4689 4689 4690 - if (!proc_ns_file(f.file)) { 4690 + if (!proc_ns_file(fd_file(f))) { 4691 4691 err = -EINVAL; 4692 4692 goto out_fput; 4693 4693 } 4694 4694 4695 - ns = get_proc_ns(file_inode(f.file)); 4695 + ns = get_proc_ns(file_inode(fd_file(f))); 4696 4696 if (ns->ops->type != CLONE_NEWUSER) { 4697 4697 err = -EINVAL; 4698 4698 goto out_fput; ··· 5292 5292 struct ns_common *ns; 5293 5293 5294 5294 CLASS(fd, f)(kreq->spare); 5295 - if (!f.file) 5295 + if (fd_empty(f)) 5296 5296 return ERR_PTR(-EBADF); 5297 5297 5298 - if (!proc_ns_file(f.file)) 5298 + if (!proc_ns_file(fd_file(f))) 5299 5299 return ERR_PTR(-EINVAL); 5300 5300 5301 - ns = get_proc_ns(file_inode(f.file)); 5301 + ns = get_proc_ns(file_inode(fd_file(f))); 5302 5302 if (ns->ops->type != CLONE_NEWNS) 5303 5303 return ERR_PTR(-EINVAL); 5304 5304
+6 -6
fs/notify/fanotify/fanotify_user.c
··· 1006 1006 struct fd f = fdget(dfd); 1007 1007 1008 1008 ret = -EBADF; 1009 - if (!f.file) 1009 + if (!fd_file(f)) 1010 1010 goto out; 1011 1011 1012 1012 ret = -ENOTDIR; 1013 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 1015 fdput(f); 1016 1016 goto out; 1017 1017 } 1018 1018 1019 - *path = f.file->f_path; 1019 + *path = fd_file(f)->f_path; 1020 1020 path_get(path); 1021 1021 fdput(f); 1022 1022 } else { ··· 1753 1753 } 1754 1754 1755 1755 f = fdget(fanotify_fd); 1756 - if (unlikely(!f.file)) 1756 + if (unlikely(!fd_file(f))) 1757 1757 return -EBADF; 1758 1758 1759 1759 /* verify that this is indeed an fanotify instance */ 1760 1760 ret = -EINVAL; 1761 - if (unlikely(f.file->f_op != &fanotify_fops)) 1761 + if (unlikely(fd_file(f)->f_op != &fanotify_fops)) 1762 1762 goto fput_and_out; 1763 - group = f.file->private_data; 1763 + group = fd_file(f)->private_data; 1764 1764 1765 1765 /* 1766 1766 * An unprivileged user is not allowed to setup mount nor filesystem
+6 -6
fs/notify/inotify/inotify_user.c
··· 753 753 return -EINVAL; 754 754 755 755 f = fdget(fd); 756 - if (unlikely(!f.file)) 756 + if (unlikely(!fd_file(f))) 757 757 return -EBADF; 758 758 759 759 /* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */ ··· 763 763 } 764 764 765 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 767 ret = -EINVAL; 768 768 goto fput_and_out; 769 769 } ··· 780 780 781 781 /* inode held in place by reference to path; group by fget on fd */ 782 782 inode = path.dentry->d_inode; 783 - group = f.file->private_data; 783 + group = fd_file(f)->private_data; 784 784 785 785 /* create/update an inode mark */ 786 786 ret = inotify_update_watch(group, inode, mask); ··· 798 798 int ret = -EINVAL; 799 799 800 800 f = fdget(fd); 801 - if (unlikely(!f.file)) 801 + if (unlikely(!fd_file(f))) 802 802 return -EBADF; 803 803 804 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 806 goto out; 807 807 808 - group = f.file->private_data; 808 + group = fd_file(f)->private_data; 809 809 810 810 i_mark = inotify_idr_find(group, wd); 811 811 if (unlikely(!i_mark))
+3 -3
fs/ocfs2/cluster/heartbeat.c
··· 1785 1785 goto out; 1786 1786 1787 1787 f = fdget(fd); 1788 - if (f.file == NULL) 1788 + if (fd_file(f) == NULL) 1789 1789 goto out; 1790 1790 1791 1791 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 || 1792 1792 reg->hr_block_bytes == 0) 1793 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 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 1799 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL); 1800 1800 if (IS_ERR(reg->hr_bdev_file)) { 1801 1801 ret = PTR_ERR(reg->hr_bdev_file);
+12 -12
fs/open.c
··· 193 193 if (length < 0) 194 194 return -EINVAL; 195 195 f = fdget(fd); 196 - if (!f.file) 196 + if (!fd_file(f)) 197 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 201 fdput(f); 202 202 return error; ··· 352 352 struct fd f = fdget(fd); 353 353 int error = -EBADF; 354 354 355 - if (f.file) { 356 - error = vfs_fallocate(f.file, mode, offset, len); 355 + if (fd_file(f)) { 356 + error = vfs_fallocate(fd_file(f), mode, offset, len); 357 357 fdput(f); 358 358 } 359 359 return error; ··· 584 584 int error; 585 585 586 586 error = -EBADF; 587 - if (!f.file) 587 + if (!fd_file(f)) 588 588 goto out; 589 589 590 590 error = -ENOTDIR; 591 - if (!d_can_lookup(f.file->f_path.dentry)) 591 + if (!d_can_lookup(fd_file(f)->f_path.dentry)) 592 592 goto out_putf; 593 593 594 - error = file_permission(f.file, MAY_EXEC | MAY_CHDIR); 594 + error = file_permission(fd_file(f), MAY_EXEC | MAY_CHDIR); 595 595 if (!error) 596 - set_fs_pwd(current->fs, &f.file->f_path); 596 + set_fs_pwd(current->fs, &fd_file(f)->f_path); 597 597 out_putf: 598 598 fdput(f); 599 599 out: ··· 674 674 struct fd f = fdget(fd); 675 675 int err = -EBADF; 676 676 677 - if (f.file) { 678 - err = vfs_fchmod(f.file, mode); 677 + if (fd_file(f)) { 678 + err = vfs_fchmod(fd_file(f), mode); 679 679 fdput(f); 680 680 } 681 681 return err; ··· 868 868 struct fd f = fdget(fd); 869 869 int error = -EBADF; 870 870 871 - if (f.file) { 872 - error = vfs_fchown(f.file, user, group); 871 + if (fd_file(f)) { 872 + error = vfs_fchown(fd_file(f), user, group); 873 873 fdput(f); 874 874 } 875 875 return error;
+35 -33
fs/overlayfs/file.c
··· 93 93 bool allow_meta) 94 94 { 95 95 struct dentry *dentry = file_dentry(file); 96 + struct file *realfile = file->private_data; 96 97 struct path realpath; 97 98 int err; 98 99 99 - real->flags = 0; 100 - real->file = file->private_data; 100 + real->word = (unsigned long)realfile; 101 101 102 102 if (allow_meta) { 103 103 ovl_path_real(dentry, &realpath); ··· 113 113 return -EIO; 114 114 115 115 /* Has it been copied up since we'd opened it? */ 116 - if (unlikely(file_inode(real->file) != d_inode(realpath.dentry))) { 117 - real->flags = FDPUT_FPUT; 118 - real->file = ovl_open_realfile(file, &realpath); 119 - 120 - return PTR_ERR_OR_ZERO(real->file); 116 + if (unlikely(file_inode(realfile) != d_inode(realpath.dentry))) { 117 + struct file *f = ovl_open_realfile(file, &realpath); 118 + if (IS_ERR(f)) 119 + return PTR_ERR(f); 120 + real->word = (unsigned long)ovl_open_realfile(file, &realpath) | FDPUT_FPUT; 121 + return 0; 121 122 } 122 123 123 124 /* Did the flags change since open? */ 124 - if (unlikely((file->f_flags ^ real->file->f_flags) & ~OVL_OPEN_FLAGS)) 125 - return ovl_change_flags(real->file, file->f_flags); 125 + if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS)) 126 + return ovl_change_flags(realfile, file->f_flags); 126 127 127 128 return 0; 128 129 } ··· 131 130 static int ovl_real_fdget(const struct file *file, struct fd *real) 132 131 { 133 132 if (d_is_dir(file_dentry(file))) { 134 - real->flags = 0; 135 - real->file = ovl_dir_real_file(file, false); 136 - 137 - return PTR_ERR_OR_ZERO(real->file); 133 + struct file *f = ovl_dir_real_file(file, false); 134 + if (IS_ERR(f)) 135 + return PTR_ERR(f); 136 + real->word = (unsigned long)f; 137 + return 0; 138 138 } 139 139 140 140 return ovl_real_fdget_meta(file, real, false); ··· 211 209 * files, so we use the real file to perform seeks. 212 210 */ 213 211 ovl_inode_lock(inode); 214 - real.file->f_pos = file->f_pos; 212 + fd_file(real)->f_pos = file->f_pos; 215 213 216 214 old_cred = ovl_override_creds(inode->i_sb); 217 - ret = vfs_llseek(real.file, offset, whence); 215 + ret = vfs_llseek(fd_file(real), offset, whence); 218 216 revert_creds(old_cred); 219 217 220 - file->f_pos = real.file->f_pos; 218 + file->f_pos = fd_file(real)->f_pos; 221 219 ovl_inode_unlock(inode); 222 220 223 221 fdput(real); ··· 277 275 if (ret) 278 276 return ret; 279 277 280 - 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, 281 279 &ctx); 282 280 fdput(real); 283 281 ··· 316 314 * this property in case it is set by the issuer. 317 315 */ 318 316 ifl &= ~IOCB_DIO_CALLER_COMP; 319 - ret = backing_file_write_iter(real.file, iter, iocb, ifl, &ctx); 317 + ret = backing_file_write_iter(fd_file(real), iter, iocb, ifl, &ctx); 320 318 fdput(real); 321 319 322 320 out_unlock: ··· 341 339 if (ret) 342 340 return ret; 343 341 344 - 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); 345 343 fdput(real); 346 344 347 345 return ret; ··· 350 348 /* 351 349 * Calling iter_file_splice_write() directly from overlay's f_op may deadlock 352 350 * due to lock order inversion between pipe->mutex in iter_file_splice_write() 353 - * and file_start_write(real.file) in ovl_write_iter(). 351 + * and file_start_write(fd_file(real)) in ovl_write_iter(). 354 352 * 355 353 * So do everything ovl_write_iter() does and call iter_file_splice_write() on 356 354 * the real file. ··· 375 373 if (ret) 376 374 goto out_unlock; 377 375 378 - 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); 379 377 fdput(real); 380 378 381 379 out_unlock: ··· 399 397 return ret; 400 398 401 399 /* Don't sync lower file for fear of receiving EROFS error */ 402 - if (file_inode(real.file) == ovl_inode_upper(file_inode(file))) { 400 + if (file_inode(fd_file(real)) == ovl_inode_upper(file_inode(file))) { 403 401 old_cred = ovl_override_creds(file_inode(file)->i_sb); 404 - ret = vfs_fsync_range(real.file, start, end, datasync); 402 + ret = vfs_fsync_range(fd_file(real), start, end, datasync); 405 403 revert_creds(old_cred); 406 404 } 407 405 ··· 441 439 goto out_unlock; 442 440 443 441 old_cred = ovl_override_creds(file_inode(file)->i_sb); 444 - ret = vfs_fallocate(real.file, mode, offset, len); 442 + ret = vfs_fallocate(fd_file(real), mode, offset, len); 445 443 revert_creds(old_cred); 446 444 447 445 /* Update size */ ··· 466 464 return ret; 467 465 468 466 old_cred = ovl_override_creds(file_inode(file)->i_sb); 469 - ret = vfs_fadvise(real.file, offset, len, advice); 467 + ret = vfs_fadvise(fd_file(real), offset, len, advice); 470 468 revert_creds(old_cred); 471 469 472 470 fdput(real); ··· 511 509 old_cred = ovl_override_creds(file_inode(file_out)->i_sb); 512 510 switch (op) { 513 511 case OVL_COPY: 514 - ret = vfs_copy_file_range(real_in.file, pos_in, 515 - real_out.file, pos_out, len, flags); 512 + ret = vfs_copy_file_range(fd_file(real_in), pos_in, 513 + fd_file(real_out), pos_out, len, flags); 516 514 break; 517 515 518 516 case OVL_CLONE: 519 - ret = vfs_clone_file_range(real_in.file, pos_in, 520 - real_out.file, pos_out, len, flags); 517 + ret = vfs_clone_file_range(fd_file(real_in), pos_in, 518 + fd_file(real_out), pos_out, len, flags); 521 519 break; 522 520 523 521 case OVL_DEDUPE: 524 - ret = vfs_dedupe_file_range_one(real_in.file, pos_in, 525 - real_out.file, pos_out, len, 522 + ret = vfs_dedupe_file_range_one(fd_file(real_in), pos_in, 523 + fd_file(real_out), pos_out, len, 526 524 flags); 527 525 break; 528 526 } ··· 585 583 if (err) 586 584 return err; 587 585 588 - if (real.file->f_op->flush) { 586 + if (fd_file(real)->f_op->flush) { 589 587 old_cred = ovl_override_creds(file_inode(file)->i_sb); 590 - err = real.file->f_op->flush(real.file, id); 588 + err = fd_file(real)->f_op->flush(fd_file(real), id); 591 589 revert_creds(old_cred); 592 590 } 593 591 fdput(real);
+4 -4
fs/quota/quota.c
··· 980 980 int ret; 981 981 982 982 f = fdget_raw(fd); 983 - if (!f.file) 983 + if (!fd_file(f)) 984 984 return -EBADF; 985 985 986 986 ret = -EINVAL; ··· 988 988 goto out; 989 989 990 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 992 if (ret) 993 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 997 if (quotactl_cmd_onoff(cmds)) 998 998 down_write(&sb->s_umount); 999 999 else ··· 1007 1007 up_read(&sb->s_umount); 1008 1008 1009 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); 1011 1011 out: 1012 1012 fdput(f); 1013 1013 return ret;
+59 -59
fs/read_write.c
··· 387 387 { 388 388 off_t retval; 389 389 struct fd f = fdget_pos(fd); 390 - if (!f.file) 390 + if (!fd_file(f)) 391 391 return -EBADF; 392 392 393 393 retval = -EINVAL; 394 394 if (whence <= SEEK_MAX) { 395 - loff_t res = vfs_llseek(f.file, offset, whence); 395 + loff_t res = vfs_llseek(fd_file(f), offset, whence); 396 396 retval = res; 397 397 if (res != (loff_t)retval) 398 398 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */ ··· 423 423 struct fd f = fdget_pos(fd); 424 424 loff_t offset; 425 425 426 - if (!f.file) 426 + if (!fd_file(f)) 427 427 return -EBADF; 428 428 429 429 retval = -EINVAL; 430 430 if (whence > SEEK_MAX) 431 431 goto out_putf; 432 432 433 - offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low, 433 + offset = vfs_llseek(fd_file(f), ((loff_t) offset_high << 32) | offset_low, 434 434 whence); 435 435 436 436 retval = (int)offset; ··· 703 703 struct fd f = fdget_pos(fd); 704 704 ssize_t ret = -EBADF; 705 705 706 - if (f.file) { 707 - loff_t pos, *ppos = file_ppos(f.file); 706 + if (fd_file(f)) { 707 + loff_t pos, *ppos = file_ppos(fd_file(f)); 708 708 if (ppos) { 709 709 pos = *ppos; 710 710 ppos = &pos; 711 711 } 712 - ret = vfs_read(f.file, buf, count, ppos); 712 + ret = vfs_read(fd_file(f), buf, count, ppos); 713 713 if (ret >= 0 && ppos) 714 - f.file->f_pos = pos; 714 + fd_file(f)->f_pos = pos; 715 715 fdput_pos(f); 716 716 } 717 717 return ret; ··· 727 727 struct fd f = fdget_pos(fd); 728 728 ssize_t ret = -EBADF; 729 729 730 - if (f.file) { 731 - loff_t pos, *ppos = file_ppos(f.file); 730 + if (fd_file(f)) { 731 + loff_t pos, *ppos = file_ppos(fd_file(f)); 732 732 if (ppos) { 733 733 pos = *ppos; 734 734 ppos = &pos; 735 735 } 736 - ret = vfs_write(f.file, buf, count, ppos); 736 + ret = vfs_write(fd_file(f), buf, count, ppos); 737 737 if (ret >= 0 && ppos) 738 - f.file->f_pos = pos; 738 + fd_file(f)->f_pos = pos; 739 739 fdput_pos(f); 740 740 } 741 741 ··· 758 758 return -EINVAL; 759 759 760 760 f = fdget(fd); 761 - if (f.file) { 761 + if (fd_file(f)) { 762 762 ret = -ESPIPE; 763 - if (f.file->f_mode & FMODE_PREAD) 764 - ret = vfs_read(f.file, buf, count, &pos); 763 + if (fd_file(f)->f_mode & FMODE_PREAD) 764 + ret = vfs_read(fd_file(f), buf, count, &pos); 765 765 fdput(f); 766 766 } 767 767 ··· 792 792 return -EINVAL; 793 793 794 794 f = fdget(fd); 795 - if (f.file) { 795 + if (fd_file(f)) { 796 796 ret = -ESPIPE; 797 - if (f.file->f_mode & FMODE_PWRITE) 798 - ret = vfs_write(f.file, buf, count, &pos); 797 + if (fd_file(f)->f_mode & FMODE_PWRITE) 798 + ret = vfs_write(fd_file(f), buf, count, &pos); 799 799 fdput(f); 800 800 } 801 801 ··· 1078 1078 struct fd f = fdget_pos(fd); 1079 1079 ssize_t ret = -EBADF; 1080 1080 1081 - if (f.file) { 1082 - loff_t pos, *ppos = file_ppos(f.file); 1081 + if (fd_file(f)) { 1082 + loff_t pos, *ppos = file_ppos(fd_file(f)); 1083 1083 if (ppos) { 1084 1084 pos = *ppos; 1085 1085 ppos = &pos; 1086 1086 } 1087 - ret = vfs_readv(f.file, vec, vlen, ppos, flags); 1087 + ret = vfs_readv(fd_file(f), vec, vlen, ppos, flags); 1088 1088 if (ret >= 0 && ppos) 1089 - f.file->f_pos = pos; 1089 + fd_file(f)->f_pos = pos; 1090 1090 fdput_pos(f); 1091 1091 } 1092 1092 ··· 1102 1102 struct fd f = fdget_pos(fd); 1103 1103 ssize_t ret = -EBADF; 1104 1104 1105 - if (f.file) { 1106 - loff_t pos, *ppos = file_ppos(f.file); 1105 + if (fd_file(f)) { 1106 + loff_t pos, *ppos = file_ppos(fd_file(f)); 1107 1107 if (ppos) { 1108 1108 pos = *ppos; 1109 1109 ppos = &pos; 1110 1110 } 1111 - ret = vfs_writev(f.file, vec, vlen, ppos, flags); 1111 + ret = vfs_writev(fd_file(f), vec, vlen, ppos, flags); 1112 1112 if (ret >= 0 && ppos) 1113 - f.file->f_pos = pos; 1113 + fd_file(f)->f_pos = pos; 1114 1114 fdput_pos(f); 1115 1115 } 1116 1116 ··· 1136 1136 return -EINVAL; 1137 1137 1138 1138 f = fdget(fd); 1139 - if (f.file) { 1139 + if (fd_file(f)) { 1140 1140 ret = -ESPIPE; 1141 - if (f.file->f_mode & FMODE_PREAD) 1142 - ret = vfs_readv(f.file, vec, vlen, &pos, flags); 1141 + if (fd_file(f)->f_mode & FMODE_PREAD) 1142 + ret = vfs_readv(fd_file(f), vec, vlen, &pos, flags); 1143 1143 fdput(f); 1144 1144 } 1145 1145 ··· 1159 1159 return -EINVAL; 1160 1160 1161 1161 f = fdget(fd); 1162 - if (f.file) { 1162 + if (fd_file(f)) { 1163 1163 ret = -ESPIPE; 1164 - if (f.file->f_mode & FMODE_PWRITE) 1165 - ret = vfs_writev(f.file, vec, vlen, &pos, flags); 1164 + if (fd_file(f)->f_mode & FMODE_PWRITE) 1165 + ret = vfs_writev(fd_file(f), vec, vlen, &pos, flags); 1166 1166 fdput(f); 1167 1167 } 1168 1168 ··· 1328 1328 */ 1329 1329 retval = -EBADF; 1330 1330 in = fdget(in_fd); 1331 - if (!in.file) 1331 + if (!fd_file(in)) 1332 1332 goto out; 1333 - if (!(in.file->f_mode & FMODE_READ)) 1333 + if (!(fd_file(in)->f_mode & FMODE_READ)) 1334 1334 goto fput_in; 1335 1335 retval = -ESPIPE; 1336 1336 if (!ppos) { 1337 - pos = in.file->f_pos; 1337 + pos = fd_file(in)->f_pos; 1338 1338 } else { 1339 1339 pos = *ppos; 1340 - if (!(in.file->f_mode & FMODE_PREAD)) 1340 + if (!(fd_file(in)->f_mode & FMODE_PREAD)) 1341 1341 goto fput_in; 1342 1342 } 1343 - retval = rw_verify_area(READ, in.file, &pos, count); 1343 + retval = rw_verify_area(READ, fd_file(in), &pos, count); 1344 1344 if (retval < 0) 1345 1345 goto fput_in; 1346 1346 if (count > MAX_RW_COUNT) ··· 1351 1351 */ 1352 1352 retval = -EBADF; 1353 1353 out = fdget(out_fd); 1354 - if (!out.file) 1354 + if (!fd_file(out)) 1355 1355 goto fput_in; 1356 - if (!(out.file->f_mode & FMODE_WRITE)) 1356 + if (!(fd_file(out)->f_mode & FMODE_WRITE)) 1357 1357 goto fput_out; 1358 - in_inode = file_inode(in.file); 1359 - out_inode = file_inode(out.file); 1360 - out_pos = out.file->f_pos; 1358 + in_inode = file_inode(fd_file(in)); 1359 + out_inode = file_inode(fd_file(out)); 1360 + out_pos = fd_file(out)->f_pos; 1361 1361 1362 1362 if (!max) 1363 1363 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes); ··· 1377 1377 * and the application is arguably buggy if it doesn't expect 1378 1378 * EAGAIN on a non-blocking file descriptor. 1379 1379 */ 1380 - if (in.file->f_flags & O_NONBLOCK) 1380 + if (fd_file(in)->f_flags & O_NONBLOCK) 1381 1381 fl = SPLICE_F_NONBLOCK; 1382 1382 #endif 1383 - opipe = get_pipe_info(out.file, true); 1383 + opipe = get_pipe_info(fd_file(out), true); 1384 1384 if (!opipe) { 1385 - retval = rw_verify_area(WRITE, out.file, &out_pos, count); 1385 + retval = rw_verify_area(WRITE, fd_file(out), &out_pos, count); 1386 1386 if (retval < 0) 1387 1387 goto fput_out; 1388 - retval = do_splice_direct(in.file, &pos, out.file, &out_pos, 1388 + retval = do_splice_direct(fd_file(in), &pos, fd_file(out), &out_pos, 1389 1389 count, fl); 1390 1390 } else { 1391 - if (out.file->f_flags & O_NONBLOCK) 1391 + if (fd_file(out)->f_flags & O_NONBLOCK) 1392 1392 fl |= SPLICE_F_NONBLOCK; 1393 1393 1394 - retval = splice_file_to_pipe(in.file, opipe, &pos, count, fl); 1394 + retval = splice_file_to_pipe(fd_file(in), opipe, &pos, count, fl); 1395 1395 } 1396 1396 1397 1397 if (retval > 0) { 1398 1398 add_rchar(current, retval); 1399 1399 add_wchar(current, retval); 1400 - fsnotify_access(in.file); 1401 - fsnotify_modify(out.file); 1402 - out.file->f_pos = out_pos; 1400 + fsnotify_access(fd_file(in)); 1401 + fsnotify_modify(fd_file(out)); 1402 + fd_file(out)->f_pos = out_pos; 1403 1403 if (ppos) 1404 1404 *ppos = pos; 1405 1405 else 1406 - in.file->f_pos = pos; 1406 + fd_file(in)->f_pos = pos; 1407 1407 } 1408 1408 1409 1409 inc_syscr(current); ··· 1676 1676 ssize_t ret = -EBADF; 1677 1677 1678 1678 f_in = fdget(fd_in); 1679 - if (!f_in.file) 1679 + if (!fd_file(f_in)) 1680 1680 goto out2; 1681 1681 1682 1682 f_out = fdget(fd_out); 1683 - if (!f_out.file) 1683 + if (!fd_file(f_out)) 1684 1684 goto out1; 1685 1685 1686 1686 ret = -EFAULT; ··· 1688 1688 if (copy_from_user(&pos_in, off_in, sizeof(loff_t))) 1689 1689 goto out; 1690 1690 } else { 1691 - pos_in = f_in.file->f_pos; 1691 + pos_in = fd_file(f_in)->f_pos; 1692 1692 } 1693 1693 1694 1694 if (off_out) { 1695 1695 if (copy_from_user(&pos_out, off_out, sizeof(loff_t))) 1696 1696 goto out; 1697 1697 } else { 1698 - pos_out = f_out.file->f_pos; 1698 + pos_out = fd_file(f_out)->f_pos; 1699 1699 } 1700 1700 1701 1701 ret = -EINVAL; 1702 1702 if (flags != 0) 1703 1703 goto out; 1704 1704 1705 - ret = vfs_copy_file_range(f_in.file, pos_in, f_out.file, pos_out, len, 1705 + ret = vfs_copy_file_range(fd_file(f_in), pos_in, fd_file(f_out), pos_out, len, 1706 1706 flags); 1707 1707 if (ret > 0) { 1708 1708 pos_in += ret; ··· 1712 1712 if (copy_to_user(off_in, &pos_in, sizeof(loff_t))) 1713 1713 ret = -EFAULT; 1714 1714 } else { 1715 - f_in.file->f_pos = pos_in; 1715 + fd_file(f_in)->f_pos = pos_in; 1716 1716 } 1717 1717 1718 1718 if (off_out) { 1719 1719 if (copy_to_user(off_out, &pos_out, sizeof(loff_t))) 1720 1720 ret = -EFAULT; 1721 1721 } else { 1722 - f_out.file->f_pos = pos_out; 1722 + fd_file(f_out)->f_pos = pos_out; 1723 1723 } 1724 1724 } 1725 1725
+10 -10
fs/readdir.c
··· 225 225 .dirent = dirent 226 226 }; 227 227 228 - if (!f.file) 228 + if (!fd_file(f)) 229 229 return -EBADF; 230 230 231 - error = iterate_dir(f.file, &buf.ctx); 231 + error = iterate_dir(fd_file(f), &buf.ctx); 232 232 if (buf.result) 233 233 error = buf.result; 234 234 ··· 318 318 int error; 319 319 320 320 f = fdget_pos(fd); 321 - if (!f.file) 321 + if (!fd_file(f)) 322 322 return -EBADF; 323 323 324 - error = iterate_dir(f.file, &buf.ctx); 324 + error = iterate_dir(fd_file(f), &buf.ctx); 325 325 if (error >= 0) 326 326 error = buf.error; 327 327 if (buf.prev_reclen) { ··· 401 401 int error; 402 402 403 403 f = fdget_pos(fd); 404 - if (!f.file) 404 + if (!fd_file(f)) 405 405 return -EBADF; 406 406 407 - error = iterate_dir(f.file, &buf.ctx); 407 + error = iterate_dir(fd_file(f), &buf.ctx); 408 408 if (error >= 0) 409 409 error = buf.error; 410 410 if (buf.prev_reclen) { ··· 483 483 .dirent = dirent 484 484 }; 485 485 486 - if (!f.file) 486 + if (!fd_file(f)) 487 487 return -EBADF; 488 488 489 - error = iterate_dir(f.file, &buf.ctx); 489 + error = iterate_dir(fd_file(f), &buf.ctx); 490 490 if (buf.result) 491 491 error = buf.result; 492 492 ··· 569 569 int error; 570 570 571 571 f = fdget_pos(fd); 572 - if (!f.file) 572 + if (!fd_file(f)) 573 573 return -EBADF; 574 574 575 - error = iterate_dir(f.file, &buf.ctx); 575 + error = iterate_dir(fd_file(f), &buf.ctx); 576 576 if (error >= 0) 577 577 error = buf.error; 578 578 if (buf.prev_reclen) {
+1 -1
fs/remap_range.c
··· 537 537 538 538 for (i = 0, info = same->info; i < count; i++, info++) { 539 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 542 if (!dst_file) { 543 543 info->status = -EBADF;
+4 -4
fs/select.c
··· 529 529 continue; 530 530 mask = EPOLLNVAL; 531 531 f = fdget(i); 532 - if (f.file) { 532 + if (fd_file(f)) { 533 533 wait_key_set(wait, in, out, bit, 534 534 busy_flag); 535 - mask = vfs_poll(f.file, wait); 535 + mask = vfs_poll(fd_file(f), wait); 536 536 537 537 fdput(f); 538 538 } ··· 863 863 goto out; 864 864 mask = EPOLLNVAL; 865 865 f = fdget(fd); 866 - if (!f.file) 866 + if (!fd_file(f)) 867 867 goto out; 868 868 869 869 /* userland u16 ->events contains POLL... bitmap */ 870 870 filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP; 871 871 pwait->_key = filter | busy_flag; 872 - mask = vfs_poll(f.file, pwait); 872 + mask = vfs_poll(fd_file(f), pwait); 873 873 if (mask & busy_flag) 874 874 *can_busy_poll = true; 875 875 mask &= filter; /* Mask out unneeded events. */
+3 -3
fs/signalfd.c
··· 289 289 fd_install(ufd, file); 290 290 } else { 291 291 struct fd f = fdget(ufd); 292 - if (!f.file) 292 + if (!fd_file(f)) 293 293 return -EBADF; 294 - ctx = f.file->private_data; 295 - if (f.file->f_op != &signalfd_fops) { 294 + ctx = fd_file(f)->private_data; 295 + if (fd_file(f)->f_op != &signalfd_fops) { 296 296 fdput(f); 297 297 return -EINVAL; 298 298 }
+4 -4
fs/smb/client/ioctl.c
··· 90 90 } 91 91 92 92 src_file = fdget(srcfd); 93 - if (!src_file.file) { 93 + if (!fd_file(src_file)) { 94 94 rc = -EBADF; 95 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 99 rc = -EBADF; 100 100 cifs_dbg(VFS, "src file seems to be from a different filesystem type\n"); 101 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 105 rc = -EINVAL; 106 106 if (S_ISDIR(src_inode->i_mode)) 107 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 110 src_inode->i_size, 0); 111 111 if (rc > 0) 112 112 rc = 0;
+11 -11
fs/splice.c
··· 1566 1566 1567 1567 static int vmsplice_type(struct fd f, int *type) 1568 1568 { 1569 - if (!f.file) 1569 + if (!fd_file(f)) 1570 1570 return -EBADF; 1571 - if (f.file->f_mode & FMODE_WRITE) { 1571 + if (fd_file(f)->f_mode & FMODE_WRITE) { 1572 1572 *type = ITER_SOURCE; 1573 - } else if (f.file->f_mode & FMODE_READ) { 1573 + } else if (fd_file(f)->f_mode & FMODE_READ) { 1574 1574 *type = ITER_DEST; 1575 1575 } else { 1576 1576 fdput(f); ··· 1621 1621 if (!iov_iter_count(&iter)) 1622 1622 error = 0; 1623 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 1625 else 1626 - error = vmsplice_to_user(f.file, &iter, flags); 1626 + error = vmsplice_to_user(fd_file(f), &iter, flags); 1627 1627 1628 1628 kfree(iov); 1629 1629 out_fdput: ··· 1646 1646 1647 1647 error = -EBADF; 1648 1648 in = fdget(fd_in); 1649 - if (in.file) { 1649 + if (fd_file(in)) { 1650 1650 out = fdget(fd_out); 1651 - if (out.file) { 1652 - error = __do_splice(in.file, off_in, out.file, off_out, 1651 + if (fd_file(out)) { 1652 + error = __do_splice(fd_file(in), off_in, fd_file(out), off_out, 1653 1653 len, flags); 1654 1654 fdput(out); 1655 1655 } ··· 2016 2016 2017 2017 error = -EBADF; 2018 2018 in = fdget(fdin); 2019 - if (in.file) { 2019 + if (fd_file(in)) { 2020 2020 out = fdget(fdout); 2021 - if (out.file) { 2022 - error = do_tee(in.file, out.file, len, flags); 2021 + if (fd_file(out)) { 2022 + error = do_tee(fd_file(in), fd_file(out), len, flags); 2023 2023 fdput(out); 2024 2024 } 2025 2025 fdput(in);
+4 -4
fs/stat.c
··· 224 224 int error; 225 225 226 226 f = fdget_raw(fd); 227 - if (!f.file) 227 + if (!fd_file(f)) 228 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 230 fdput(f); 231 231 return error; 232 232 } ··· 277 277 u32 request_mask) 278 278 { 279 279 CLASS(fd_raw, f)(fd); 280 - if (!f.file) 280 + if (!fd_file(f)) 281 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 /**
+2 -2
fs/statfs.c
··· 116 116 { 117 117 struct fd f = fdget_raw(fd); 118 118 int error = -EBADF; 119 - if (f.file) { 120 - error = vfs_statfs(&f.file->f_path, st); 119 + if (fd_file(f)) { 120 + error = vfs_statfs(&fd_file(f)->f_path, st); 121 121 fdput(f); 122 122 } 123 123 return error;
+7 -7
fs/sync.c
··· 152 152 struct super_block *sb; 153 153 int ret, ret2; 154 154 155 - if (!f.file) 155 + if (!fd_file(f)) 156 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 159 down_read(&sb->s_umount); 160 160 ret = sync_filesystem(sb); 161 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 165 fdput(f); 166 166 return ret ? ret : ret2; ··· 208 208 struct fd f = fdget(fd); 209 209 int ret = -EBADF; 210 210 211 - if (f.file) { 212 - ret = vfs_fsync(f.file, datasync); 211 + if (fd_file(f)) { 212 + ret = vfs_fsync(fd_file(f), datasync); 213 213 fdput(f); 214 214 } 215 215 return ret; ··· 360 360 361 361 ret = -EBADF; 362 362 f = fdget(fd); 363 - if (f.file) 364 - ret = sync_file_range(f.file, offset, nbytes, flags); 363 + if (fd_file(f)) 364 + ret = sync_file_range(fd_file(f), offset, nbytes, flags); 365 365 366 366 fdput(f); 367 367 return ret;
+4 -4
fs/timerfd.c
··· 397 397 static int timerfd_fget(int fd, struct fd *p) 398 398 { 399 399 struct fd f = fdget(fd); 400 - if (!f.file) 400 + if (!fd_file(f)) 401 401 return -EBADF; 402 - if (f.file->f_op != &timerfd_fops) { 402 + if (fd_file(f)->f_op != &timerfd_fops) { 403 403 fdput(f); 404 404 return -EINVAL; 405 405 } ··· 482 482 ret = timerfd_fget(ufd, &f); 483 483 if (ret) 484 484 return ret; 485 - ctx = f.file->private_data; 485 + ctx = fd_file(f)->private_data; 486 486 487 487 if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) { 488 488 fdput(f); ··· 546 546 int ret = timerfd_fget(ufd, &f); 547 547 if (ret) 548 548 return ret; 549 - ctx = f.file->private_data; 549 + ctx = fd_file(f)->private_data; 550 550 551 551 spin_lock_irq(&ctx->wqh.lock); 552 552 if (ctx->expired && ctx->tintv) {
+2 -2
fs/utimes.c
··· 115 115 return -EINVAL; 116 116 117 117 f = fdget(fd); 118 - if (!f.file) 118 + if (!fd_file(f)) 119 119 return -EBADF; 120 - error = vfs_utimes(&f.file->f_path, times); 120 + error = vfs_utimes(&fd_file(f)->f_path, times); 121 121 fdput(f); 122 122 return error; 123 123 }
+18 -18
fs/xattr.c
··· 697 697 int error; 698 698 699 699 CLASS(fd, f)(fd); 700 - if (!f.file) 700 + if (!fd_file(f)) 701 701 return -EBADF; 702 702 703 - audit_file(f.file); 703 + audit_file(fd_file(f)); 704 704 error = setxattr_copy(name, &ctx); 705 705 if (error) 706 706 return error; 707 707 708 - error = mnt_want_write_file(f.file); 708 + error = mnt_want_write_file(fd_file(f)); 709 709 if (!error) { 710 - error = do_setxattr(file_mnt_idmap(f.file), 711 - f.file->f_path.dentry, &ctx); 712 - mnt_drop_write_file(f.file); 710 + error = do_setxattr(file_mnt_idmap(fd_file(f)), 711 + fd_file(f)->f_path.dentry, &ctx); 712 + mnt_drop_write_file(fd_file(f)); 713 713 } 714 714 kvfree(ctx.kvalue); 715 715 return error; ··· 812 812 struct fd f = fdget(fd); 813 813 ssize_t error = -EBADF; 814 814 815 - if (!f.file) 815 + if (!fd_file(f)) 816 816 return error; 817 - audit_file(f.file); 818 - error = getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry, 817 + audit_file(fd_file(f)); 818 + error = getxattr(file_mnt_idmap(fd_file(f)), fd_file(f)->f_path.dentry, 819 819 name, value, size); 820 820 fdput(f); 821 821 return error; ··· 888 888 struct fd f = fdget(fd); 889 889 ssize_t error = -EBADF; 890 890 891 - if (!f.file) 891 + if (!fd_file(f)) 892 892 return error; 893 - audit_file(f.file); 894 - error = listxattr(f.file->f_path.dentry, list, size); 893 + audit_file(fd_file(f)); 894 + error = listxattr(fd_file(f)->f_path.dentry, list, size); 895 895 fdput(f); 896 896 return error; 897 897 } ··· 954 954 char kname[XATTR_NAME_MAX + 1]; 955 955 int error = -EBADF; 956 956 957 - if (!f.file) 957 + if (!fd_file(f)) 958 958 return error; 959 - audit_file(f.file); 959 + audit_file(fd_file(f)); 960 960 961 961 error = strncpy_from_user(kname, name, sizeof(kname)); 962 962 if (error == 0 || error == sizeof(kname)) ··· 964 964 if (error < 0) 965 965 return error; 966 966 967 - error = mnt_want_write_file(f.file); 967 + error = mnt_want_write_file(fd_file(f)); 968 968 if (!error) { 969 - error = removexattr(file_mnt_idmap(f.file), 970 - f.file->f_path.dentry, kname); 971 - mnt_drop_write_file(f.file); 969 + error = removexattr(file_mnt_idmap(fd_file(f)), 970 + fd_file(f)->f_path.dentry, kname); 971 + mnt_drop_write_file(fd_file(f)); 972 972 } 973 973 fdput(f); 974 974 return error;
+4 -4
fs/xfs/xfs_exchrange.c
··· 829 829 fxr.flags = args.flags; 830 830 831 831 file1 = fdget(args.file1_fd); 832 - if (!file1.file) 832 + if (!fd_file(file1)) 833 833 return -EBADF; 834 - fxr.file1 = file1.file; 834 + fxr.file1 = fd_file(file1); 835 835 836 836 error = xfs_exchange_range(&fxr); 837 837 fdput(file1); ··· 935 935 fxr.file2_ctime.tv_nsec = kern_f->file2_ctime_nsec; 936 936 937 937 file1 = fdget(args.file1_fd); 938 - if (!file1.file) 938 + if (fd_empty(file1)) 939 939 return -EBADF; 940 - fxr.file1 = file1.file; 940 + fxr.file1 = fd_file(file1); 941 941 942 942 error = xfs_exchange_range(&fxr); 943 943 fdput(file1);
+3 -3
fs/xfs/xfs_handle.c
··· 85 85 int hsize; 86 86 xfs_handle_t handle; 87 87 struct inode *inode; 88 - struct fd f = {NULL}; 88 + struct fd f = EMPTY_FD; 89 89 struct path path; 90 90 int error; 91 91 struct xfs_inode *ip; 92 92 93 93 if (cmd == XFS_IOC_FD_TO_HANDLE) { 94 94 f = fdget(hreq->fd); 95 - if (!f.file) 95 + if (!fd_file(f)) 96 96 return -EBADF; 97 - inode = file_inode(f.file); 97 + inode = file_inode(fd_file(f)); 98 98 } else { 99 99 error = user_path_at(AT_FDCWD, hreq->path, 0, &path); 100 100 if (error)
+14 -14
fs/xfs/xfs_ioctl.c
··· 886 886 887 887 /* Pull information for the target fd */ 888 888 f = fdget((int)sxp->sx_fdtarget); 889 - if (!f.file) { 889 + if (!fd_file(f)) { 890 890 error = -EINVAL; 891 891 goto out; 892 892 } 893 893 894 - if (!(f.file->f_mode & FMODE_WRITE) || 895 - !(f.file->f_mode & FMODE_READ) || 896 - (f.file->f_flags & O_APPEND)) { 894 + if (!(fd_file(f)->f_mode & FMODE_WRITE) || 895 + !(fd_file(f)->f_mode & FMODE_READ) || 896 + (fd_file(f)->f_flags & O_APPEND)) { 897 897 error = -EBADF; 898 898 goto out_put_file; 899 899 } 900 900 901 901 tmp = fdget((int)sxp->sx_fdtmp); 902 - if (!tmp.file) { 902 + if (!fd_file(tmp)) { 903 903 error = -EINVAL; 904 904 goto out_put_file; 905 905 } 906 906 907 - if (!(tmp.file->f_mode & FMODE_WRITE) || 908 - !(tmp.file->f_mode & FMODE_READ) || 909 - (tmp.file->f_flags & O_APPEND)) { 907 + if (!(fd_file(tmp)->f_mode & FMODE_WRITE) || 908 + !(fd_file(tmp)->f_mode & FMODE_READ) || 909 + (fd_file(tmp)->f_flags & O_APPEND)) { 910 910 error = -EBADF; 911 911 goto out_put_tmp_file; 912 912 } 913 913 914 - if (IS_SWAPFILE(file_inode(f.file)) || 915 - IS_SWAPFILE(file_inode(tmp.file))) { 914 + if (IS_SWAPFILE(file_inode(fd_file(f))) || 915 + IS_SWAPFILE(file_inode(fd_file(tmp)))) { 916 916 error = -EINVAL; 917 917 goto out_put_tmp_file; 918 918 } ··· 922 922 * before we cast and access them as XFS structures as we have no 923 923 * control over what the user passes us here. 924 924 */ 925 - if (f.file->f_op != &xfs_file_operations || 926 - tmp.file->f_op != &xfs_file_operations) { 925 + if (fd_file(f)->f_op != &xfs_file_operations || 926 + fd_file(tmp)->f_op != &xfs_file_operations) { 927 927 error = -EINVAL; 928 928 goto out_put_tmp_file; 929 929 } 930 930 931 - ip = XFS_I(file_inode(f.file)); 932 - tip = XFS_I(file_inode(tmp.file)); 931 + ip = XFS_I(file_inode(fd_file(f))); 932 + tip = XFS_I(file_inode(fd_file(tmp))); 933 933 934 934 if (ip->i_mount != tip->i_mount) { 935 935 error = -EINVAL;
+1 -1
include/linux/cleanup.h
··· 98 98 * DEFINE_CLASS(fdget, struct fd, fdput(_T), fdget(fd), int fd) 99 99 * 100 100 * CLASS(fdget, f)(fd); 101 - * if (!f.file) 101 + * if (!fd_file(f)) 102 102 * return -EBADF; 103 103 * 104 104 * // use 'f' without concern
+29 -28
include/linux/file.h
··· 36 36 fput(file); 37 37 } 38 38 39 + /* either a reference to struct file + flags 40 + * (cloned vs. borrowed, pos locked), with 41 + * flags stored in lower bits of value, 42 + * or empty (represented by 0). 43 + */ 39 44 struct fd { 40 - struct file *file; 41 - unsigned int flags; 45 + unsigned long word; 42 46 }; 43 47 #define FDPUT_FPUT 1 44 48 #define FDPUT_POS_UNLOCK 2 45 49 50 + #define fd_file(f) ((struct file *)((f).word & ~(FDPUT_FPUT|FDPUT_POS_UNLOCK))) 51 + static inline bool fd_empty(struct fd f) 52 + { 53 + return unlikely(!f.word); 54 + } 55 + 56 + #define EMPTY_FD (struct fd){0} 57 + static inline struct fd BORROWED_FD(struct file *f) 58 + { 59 + return (struct fd){(unsigned long)f}; 60 + } 61 + static inline struct fd CLONED_FD(struct file *f) 62 + { 63 + return (struct fd){(unsigned long)f | FDPUT_FPUT}; 64 + } 65 + 46 66 static inline void fdput(struct fd fd) 47 67 { 48 - if (fd.flags & FDPUT_FPUT) 49 - fput(fd.file); 68 + if (fd.word & FDPUT_FPUT) 69 + fput(fd_file(fd)); 50 70 } 51 71 52 72 extern struct file *fget(unsigned int fd); 53 73 extern struct file *fget_raw(unsigned int fd); 54 74 extern struct file *fget_task(struct task_struct *task, unsigned int fd); 55 - extern unsigned long __fdget(unsigned int fd); 56 - extern unsigned long __fdget_raw(unsigned int fd); 57 - extern unsigned long __fdget_pos(unsigned int fd); 58 75 extern void __f_unlock_pos(struct file *); 59 76 60 - static inline struct fd __to_fd(unsigned long v) 61 - { 62 - return (struct fd){(struct file *)(v & ~3),v & 3}; 63 - } 64 - 65 - static inline struct fd fdget(unsigned int fd) 66 - { 67 - return __to_fd(__fdget(fd)); 68 - } 69 - 70 - static inline struct fd fdget_raw(unsigned int fd) 71 - { 72 - return __to_fd(__fdget_raw(fd)); 73 - } 74 - 75 - static inline struct fd fdget_pos(int fd) 76 - { 77 - return __to_fd(__fdget_pos(fd)); 78 - } 77 + struct fd fdget(unsigned int fd); 78 + struct fd fdget_raw(unsigned int fd); 79 + struct fd fdget_pos(unsigned int fd); 79 80 80 81 static inline void fdput_pos(struct fd f) 81 82 { 82 - if (f.flags & FDPUT_POS_UNLOCK) 83 - __f_unlock_pos(f.file); 83 + if (f.word & FDPUT_POS_UNLOCK) 84 + __f_unlock_pos(fd_file(f)); 84 85 fdput(f); 85 86 } 86 87
+5 -5
io_uring/sqpoll.c
··· 109 109 struct fd f; 110 110 111 111 f = fdget(p->wq_fd); 112 - if (!f.file) 112 + if (!fd_file(f)) 113 113 return ERR_PTR(-ENXIO); 114 - if (!io_is_uring_fops(f.file)) { 114 + if (!io_is_uring_fops(fd_file(f))) { 115 115 fdput(f); 116 116 return ERR_PTR(-EINVAL); 117 117 } 118 118 119 - ctx_attach = f.file->private_data; 119 + ctx_attach = fd_file(f)->private_data; 120 120 sqd = ctx_attach->sq_data; 121 121 if (!sqd) { 122 122 fdput(f); ··· 419 419 struct fd f; 420 420 421 421 f = fdget(p->wq_fd); 422 - if (!f.file) 422 + if (!fd_file(f)) 423 423 return -ENXIO; 424 - if (!io_is_uring_fops(f.file)) { 424 + if (!io_is_uring_fops(fd_file(f))) { 425 425 fdput(f); 426 426 return -EINVAL; 427 427 }
+25 -25
ipc/mqueue.c
··· 1085 1085 audit_mq_sendrecv(mqdes, msg_len, msg_prio, ts); 1086 1086 1087 1087 f = fdget(mqdes); 1088 - if (unlikely(!f.file)) { 1088 + if (unlikely(!fd_file(f))) { 1089 1089 ret = -EBADF; 1090 1090 goto out; 1091 1091 } 1092 1092 1093 - inode = file_inode(f.file); 1094 - if (unlikely(f.file->f_op != &mqueue_file_operations)) { 1093 + inode = file_inode(fd_file(f)); 1094 + if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) { 1095 1095 ret = -EBADF; 1096 1096 goto out_fput; 1097 1097 } 1098 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 1102 ret = -EBADF; 1103 1103 goto out_fput; 1104 1104 } ··· 1138 1138 } 1139 1139 1140 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 1142 ret = -EAGAIN; 1143 1143 } else { 1144 1144 wait.task = current; ··· 1199 1199 audit_mq_sendrecv(mqdes, msg_len, 0, ts); 1200 1200 1201 1201 f = fdget(mqdes); 1202 - if (unlikely(!f.file)) { 1202 + if (unlikely(!fd_file(f))) { 1203 1203 ret = -EBADF; 1204 1204 goto out; 1205 1205 } 1206 1206 1207 - inode = file_inode(f.file); 1208 - if (unlikely(f.file->f_op != &mqueue_file_operations)) { 1207 + inode = file_inode(fd_file(f)); 1208 + if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) { 1209 1209 ret = -EBADF; 1210 1210 goto out_fput; 1211 1211 } 1212 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 1216 ret = -EBADF; 1217 1217 goto out_fput; 1218 1218 } ··· 1242 1242 } 1243 1243 1244 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 1246 spin_unlock(&info->lock); 1247 1247 ret = -EAGAIN; 1248 1248 } else { ··· 1356 1356 /* and attach it to the socket */ 1357 1357 retry: 1358 1358 f = fdget(notification->sigev_signo); 1359 - if (!f.file) { 1359 + if (!fd_file(f)) { 1360 1360 ret = -EBADF; 1361 1361 goto out; 1362 1362 } 1363 - sock = netlink_getsockbyfilp(f.file); 1363 + sock = netlink_getsockbyfilp(fd_file(f)); 1364 1364 fdput(f); 1365 1365 if (IS_ERR(sock)) { 1366 1366 ret = PTR_ERR(sock); ··· 1379 1379 } 1380 1380 1381 1381 f = fdget(mqdes); 1382 - if (!f.file) { 1382 + if (!fd_file(f)) { 1383 1383 ret = -EBADF; 1384 1384 goto out; 1385 1385 } 1386 1386 1387 - inode = file_inode(f.file); 1388 - if (unlikely(f.file->f_op != &mqueue_file_operations)) { 1387 + inode = file_inode(fd_file(f)); 1388 + if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) { 1389 1389 ret = -EBADF; 1390 1390 goto out_fput; 1391 1391 } ··· 1460 1460 return -EINVAL; 1461 1461 1462 1462 f = fdget(mqdes); 1463 - if (!f.file) 1463 + if (!fd_file(f)) 1464 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 1467 fdput(f); 1468 1468 return -EBADF; 1469 1469 } 1470 1470 1471 - inode = file_inode(f.file); 1471 + inode = file_inode(fd_file(f)); 1472 1472 info = MQUEUE_I(inode); 1473 1473 1474 1474 spin_lock(&info->lock); 1475 1475 1476 1476 if (old) { 1477 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 1480 if (new) { 1481 1481 audit_mq_getsetattr(mqdes, new); 1482 - spin_lock(&f.file->f_lock); 1482 + spin_lock(&fd_file(f)->f_lock); 1483 1483 if (new->mq_flags & O_NONBLOCK) 1484 - f.file->f_flags |= O_NONBLOCK; 1484 + fd_file(f)->f_flags |= O_NONBLOCK; 1485 1485 else 1486 - f.file->f_flags &= ~O_NONBLOCK; 1487 - spin_unlock(&f.file->f_lock); 1486 + fd_file(f)->f_flags &= ~O_NONBLOCK; 1487 + spin_unlock(&fd_file(f)->f_lock); 1488 1488 1489 1489 inode_set_atime_to_ts(inode, inode_set_ctime_current(inode)); 1490 1490 }
+7 -7
kernel/bpf/bpf_inode_storage.c
··· 80 80 struct bpf_local_storage_data *sdata; 81 81 struct fd f = fdget_raw(*(int *)key); 82 82 83 - if (!f.file) 83 + if (!fd_file(f)) 84 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 87 fdput(f); 88 88 return sdata ? sdata->data : NULL; 89 89 } ··· 94 94 struct bpf_local_storage_data *sdata; 95 95 struct fd f = fdget_raw(*(int *)key); 96 96 97 - if (!f.file) 97 + if (!fd_file(f)) 98 98 return -EBADF; 99 - if (!inode_storage_ptr(file_inode(f.file))) { 99 + if (!inode_storage_ptr(file_inode(fd_file(f)))) { 100 100 fdput(f); 101 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 105 (struct bpf_local_storage_map *)map, 106 106 value, map_flags, GFP_ATOMIC); 107 107 fdput(f); ··· 126 126 struct fd f = fdget_raw(*(int *)key); 127 127 int err; 128 128 129 - if (!f.file) 129 + if (!fd_file(f)) 130 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 133 fdput(f); 134 134 return err; 135 135 }
+3 -3
kernel/bpf/btf.c
··· 7715 7715 7716 7716 f = fdget(fd); 7717 7717 7718 - if (!f.file) 7718 + if (!fd_file(f)) 7719 7719 return ERR_PTR(-EBADF); 7720 7720 7721 - if (f.file->f_op != &btf_fops) { 7721 + if (fd_file(f)->f_op != &btf_fops) { 7722 7722 fdput(f); 7723 7723 return ERR_PTR(-EINVAL); 7724 7724 } 7725 7725 7726 - btf = f.file->private_data; 7726 + btf = fd_file(f)->private_data; 7727 7727 refcount_inc(&btf->refcnt); 7728 7728 fdput(f); 7729 7729
+21 -21
kernel/bpf/syscall.c
··· 837 837 838 838 static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f) 839 839 { 840 - fmode_t mode = f.file->f_mode; 840 + fmode_t mode = fd_file(f)->f_mode; 841 841 842 842 /* Our file permissions may have been overridden by global 843 843 * map permissions facing syscall side. ··· 1430 1430 */ 1431 1431 struct bpf_map *__bpf_map_get(struct fd f) 1432 1432 { 1433 - if (!f.file) 1433 + if (!fd_file(f)) 1434 1434 return ERR_PTR(-EBADF); 1435 - if (f.file->f_op != &bpf_map_fops) { 1435 + if (fd_file(f)->f_op != &bpf_map_fops) { 1436 1436 fdput(f); 1437 1437 return ERR_PTR(-EINVAL); 1438 1438 } 1439 1439 1440 - return f.file->private_data; 1440 + return fd_file(f)->private_data; 1441 1441 } 1442 1442 1443 1443 void bpf_map_inc(struct bpf_map *map) ··· 1658 1658 goto free_key; 1659 1659 } 1660 1660 1661 - err = bpf_map_update_value(map, f.file, key, value, attr->flags); 1661 + err = bpf_map_update_value(map, fd_file(f), key, value, attr->flags); 1662 1662 if (!err) 1663 1663 maybe_wait_bpf_programs(map); 1664 1664 ··· 2416 2416 2417 2417 static struct bpf_prog *____bpf_prog_get(struct fd f) 2418 2418 { 2419 - if (!f.file) 2419 + if (!fd_file(f)) 2420 2420 return ERR_PTR(-EBADF); 2421 - if (f.file->f_op != &bpf_prog_fops) { 2421 + if (fd_file(f)->f_op != &bpf_prog_fops) { 2422 2422 fdput(f); 2423 2423 return ERR_PTR(-EINVAL); 2424 2424 } 2425 2425 2426 - return f.file->private_data; 2426 + return fd_file(f)->private_data; 2427 2427 } 2428 2428 2429 2429 void bpf_prog_add(struct bpf_prog *prog, int i) ··· 3266 3266 struct fd f = fdget(ufd); 3267 3267 struct bpf_link *link; 3268 3268 3269 - if (!f.file) 3269 + if (!fd_file(f)) 3270 3270 return ERR_PTR(-EBADF); 3271 - if (f.file->f_op != &bpf_link_fops && f.file->f_op != &bpf_link_fops_poll) { 3271 + if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll) { 3272 3272 fdput(f); 3273 3273 return ERR_PTR(-EINVAL); 3274 3274 } 3275 3275 3276 - link = f.file->private_data; 3276 + link = fd_file(f)->private_data; 3277 3277 bpf_link_inc(link); 3278 3278 fdput(f); 3279 3279 ··· 4989 4989 return -EINVAL; 4990 4990 4991 4991 f = fdget(ufd); 4992 - if (!f.file) 4992 + if (!fd_file(f)) 4993 4993 return -EBADFD; 4994 4994 4995 - if (f.file->f_op == &bpf_prog_fops) 4996 - err = bpf_prog_get_info_by_fd(f.file, f.file->private_data, attr, 4995 + if (fd_file(f)->f_op == &bpf_prog_fops) 4996 + err = bpf_prog_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, 4997 4997 uattr); 4998 - else if (f.file->f_op == &bpf_map_fops) 4999 - err = bpf_map_get_info_by_fd(f.file, f.file->private_data, attr, 4998 + else if (fd_file(f)->f_op == &bpf_map_fops) 4999 + err = bpf_map_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, 5000 5000 uattr); 5001 - else if (f.file->f_op == &btf_fops) 5002 - err = bpf_btf_get_info_by_fd(f.file, f.file->private_data, attr, uattr); 5003 - else if (f.file->f_op == &bpf_link_fops || f.file->f_op == &bpf_link_fops_poll) 5004 - err = bpf_link_get_info_by_fd(f.file, f.file->private_data, 5001 + else if (fd_file(f)->f_op == &btf_fops) 5002 + err = bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, uattr); 5003 + else if (fd_file(f)->f_op == &bpf_link_fops || fd_file(f)->f_op == &bpf_link_fops_poll) 5004 + err = bpf_link_get_info_by_fd(fd_file(f), fd_file(f)->private_data, 5005 5005 attr, uattr); 5006 5006 else 5007 5007 err = -EINVAL; ··· 5222 5222 else if (cmd == BPF_MAP_LOOKUP_AND_DELETE_BATCH) 5223 5223 BPF_DO_BATCH(map->ops->map_lookup_and_delete_batch, map, attr, uattr); 5224 5224 else if (cmd == BPF_MAP_UPDATE_BATCH) 5225 - BPF_DO_BATCH(map->ops->map_update_batch, map, f.file, attr, uattr); 5225 + BPF_DO_BATCH(map->ops->map_update_batch, map, fd_file(f), attr, uattr); 5226 5226 else 5227 5227 BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr); 5228 5228 err_put:
+5 -5
kernel/bpf/token.c
··· 122 122 int err, fd; 123 123 124 124 f = fdget(attr->token_create.bpffs_fd); 125 - if (!f.file) 125 + if (!fd_file(f)) 126 126 return -EBADF; 127 127 128 - path = f.file->f_path; 128 + path = fd_file(f)->f_path; 129 129 path_get(&path); 130 130 fdput(f); 131 131 ··· 235 235 struct fd f = fdget(ufd); 236 236 struct bpf_token *token; 237 237 238 - if (!f.file) 238 + if (!fd_file(f)) 239 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 241 fdput(f); 242 242 return ERR_PTR(-EINVAL); 243 243 } 244 244 245 - token = f.file->private_data; 245 + token = fd_file(f)->private_data; 246 246 bpf_token_inc(token); 247 247 fdput(f); 248 248
+2 -2
kernel/cgroup/cgroup.c
··· 6968 6968 { 6969 6969 struct cgroup *cgrp; 6970 6970 struct fd f = fdget_raw(fd); 6971 - if (!f.file) 6971 + if (!fd_file(f)) 6972 6972 return ERR_PTR(-EBADF); 6973 6973 6974 - cgrp = cgroup_v1v2_get_from_file(f.file); 6974 + cgrp = cgroup_v1v2_get_from_file(fd_file(f)); 6975 6975 fdput(f); 6976 6976 return cgrp; 6977 6977 }
+7 -7
kernel/events/core.c
··· 969 969 struct fd f = fdget(fd); 970 970 int ret = 0; 971 971 972 - if (!f.file) 972 + if (!fd_file(f)) 973 973 return -EBADF; 974 974 975 - css = css_tryget_online_from_dir(f.file->f_path.dentry, 975 + css = css_tryget_online_from_dir(fd_file(f)->f_path.dentry, 976 976 &perf_event_cgrp_subsys); 977 977 if (IS_ERR(css)) { 978 978 ret = PTR_ERR(css); ··· 6001 6001 static inline int perf_fget_light(int fd, struct fd *p) 6002 6002 { 6003 6003 struct fd f = fdget(fd); 6004 - if (!f.file) 6004 + if (!fd_file(f)) 6005 6005 return -EBADF; 6006 6006 6007 - if (f.file->f_op != &perf_fops) { 6007 + if (fd_file(f)->f_op != &perf_fops) { 6008 6008 fdput(f); 6009 6009 return -EBADF; 6010 6010 } ··· 6064 6064 ret = perf_fget_light(arg, &output); 6065 6065 if (ret) 6066 6066 return ret; 6067 - output_event = output.file->private_data; 6067 + output_event = fd_file(output)->private_data; 6068 6068 ret = perf_event_set_output(event, output_event); 6069 6069 fdput(output); 6070 6070 } else { ··· 12665 12665 struct perf_event_attr attr; 12666 12666 struct perf_event_context *ctx; 12667 12667 struct file *event_file = NULL; 12668 - struct fd group = {NULL, 0}; 12668 + struct fd group = EMPTY_FD; 12669 12669 struct task_struct *task = NULL; 12670 12670 struct pmu *pmu; 12671 12671 int event_fd; ··· 12740 12740 err = perf_fget_light(group_fd, &group); 12741 12741 if (err) 12742 12742 goto err_fd; 12743 - group_leader = group.file->private_data; 12743 + group_leader = fd_file(group)->private_data; 12744 12744 if (flags & PERF_FLAG_FD_OUTPUT) 12745 12745 output_event = group_leader; 12746 12746 if (flags & PERF_FLAG_FD_NO_GROUP)
+1 -1
kernel/module/main.c
··· 3234 3234 return -EINVAL; 3235 3235 3236 3236 f = fdget(fd); 3237 - err = idempotent_init_module(f.file, uargs, flags); 3237 + err = idempotent_init_module(fd_file(f), uargs, flags); 3238 3238 fdput(f); 3239 3239 return err; 3240 3240 }
+6 -6
kernel/nsproxy.c
··· 550 550 struct nsset nsset = {}; 551 551 int err = 0; 552 552 553 - if (!f.file) 553 + if (!fd_file(f)) 554 554 return -EBADF; 555 555 556 - if (proc_ns_file(f.file)) { 557 - ns = get_proc_ns(file_inode(f.file)); 556 + if (proc_ns_file(fd_file(f))) { 557 + ns = get_proc_ns(file_inode(fd_file(f))); 558 558 if (flags && (ns->ops->type != flags)) 559 559 err = -EINVAL; 560 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 562 err = check_setns_flags(flags); 563 563 } else { 564 564 err = -EINVAL; ··· 570 570 if (err) 571 571 goto out; 572 572 573 - if (proc_ns_file(f.file)) 573 + if (proc_ns_file(fd_file(f))) 574 574 err = validate_ns(&nsset, ns); 575 575 else 576 - err = validate_nsset(&nsset, pidfd_pid(f.file)); 576 + err = validate_nsset(&nsset, pidfd_pid(fd_file(f))); 577 577 if (!err) { 578 578 commit_nsset(&nsset); 579 579 perf_event_namespaces(current);
+5 -5
kernel/pid.c
··· 540 540 struct pid *pid; 541 541 542 542 f = fdget(fd); 543 - if (!f.file) 543 + if (!fd_file(f)) 544 544 return ERR_PTR(-EBADF); 545 545 546 - pid = pidfd_pid(f.file); 546 + pid = pidfd_pid(fd_file(f)); 547 547 if (!IS_ERR(pid)) { 548 548 get_pid(pid); 549 - *flags = f.file->f_flags; 549 + *flags = fd_file(f)->f_flags; 550 550 } 551 551 552 552 fdput(f); ··· 755 755 return -EINVAL; 756 756 757 757 f = fdget(pidfd); 758 - if (!f.file) 758 + if (!fd_file(f)) 759 759 return -EBADF; 760 760 761 - pid = pidfd_pid(f.file); 761 + pid = pidfd_pid(fd_file(f)); 762 762 if (IS_ERR(pid)) 763 763 ret = PTR_ERR(pid); 764 764 else
+3 -3
kernel/signal.c
··· 3941 3941 return -EINVAL; 3942 3942 3943 3943 f = fdget(pidfd); 3944 - if (!f.file) 3944 + if (!fd_file(f)) 3945 3945 return -EBADF; 3946 3946 3947 3947 /* Is this a pidfd? */ 3948 - pid = pidfd_to_pid(f.file); 3948 + pid = pidfd_to_pid(fd_file(f)); 3949 3949 if (IS_ERR(pid)) { 3950 3950 ret = PTR_ERR(pid); 3951 3951 goto err; ··· 3958 3958 switch (flags) { 3959 3959 case 0: 3960 3960 /* Infer scope from the type of pidfd. */ 3961 - if (f.file->f_flags & PIDFD_THREAD) 3961 + if (fd_file(f)->f_flags & PIDFD_THREAD) 3962 3962 type = PIDTYPE_PID; 3963 3963 else 3964 3964 type = PIDTYPE_TGID;
+5 -5
kernel/sys.c
··· 1916 1916 int err; 1917 1917 1918 1918 exe = fdget(fd); 1919 - if (!exe.file) 1919 + if (!fd_file(exe)) 1920 1920 return -EBADF; 1921 1921 1922 - inode = file_inode(exe.file); 1922 + inode = file_inode(fd_file(exe)); 1923 1923 1924 1924 /* 1925 1925 * Because the original mm->exe_file points to executable file, make ··· 1927 1927 * overall picture. 1928 1928 */ 1929 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 1931 goto exit; 1932 1932 1933 - err = file_permission(exe.file, MAY_EXEC); 1933 + err = file_permission(fd_file(exe), MAY_EXEC); 1934 1934 if (err) 1935 1935 goto exit; 1936 1936 1937 - err = replace_mm_exe_file(mm, exe.file); 1937 + err = replace_mm_exe_file(mm, fd_file(exe)); 1938 1938 exit: 1939 1939 fdput(exe); 1940 1940 return err;
+2 -2
kernel/taskstats.c
··· 419 419 420 420 fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]); 421 421 f = fdget(fd); 422 - if (!f.file) 422 + if (!fd_file(f)) 423 423 return 0; 424 424 425 425 size = nla_total_size(sizeof(struct cgroupstats)); ··· 440 440 stats = nla_data(na); 441 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 444 if (rc < 0) { 445 445 nlmsg_free(rep_skb); 446 446 goto err;
+2 -2
kernel/watch_queue.c
··· 666 666 struct fd f; 667 667 668 668 f = fdget(fd); 669 - if (f.file) { 670 - pipe = get_pipe_info(f.file, false); 669 + if (fd_file(f)) { 670 + pipe = get_pipe_info(fd_file(f), false); 671 671 if (pipe && pipe->watch_queue) { 672 672 wqueue = pipe->watch_queue; 673 673 kref_get(&wqueue->usage);
+2 -2
mm/fadvise.c
··· 193 193 struct fd f = fdget(fd); 194 194 int ret; 195 195 196 - if (!f.file) 196 + if (!fd_file(f)) 197 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 201 fdput(f); 202 202 return ret;
+3 -3
mm/filemap.c
··· 4423 4423 struct cachestat cs; 4424 4424 pgoff_t first_index, last_index; 4425 4425 4426 - if (!f.file) 4426 + if (!fd_file(f)) 4427 4427 return -EBADF; 4428 4428 4429 4429 if (copy_from_user(&csr, cstat_range, ··· 4433 4433 } 4434 4434 4435 4435 /* hugetlbfs is not supported */ 4436 - if (is_file_hugepages(f.file)) { 4436 + if (is_file_hugepages(fd_file(f))) { 4437 4437 fdput(f); 4438 4438 return -EOPNOTSUPP; 4439 4439 } ··· 4447 4447 last_index = 4448 4448 csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT; 4449 4449 memset(&cs, 0, sizeof(struct cachestat)); 4450 - mapping = f.file->f_mapping; 4450 + mapping = fd_file(f)->f_mapping; 4451 4451 filemap_cachestat(mapping, first_index, last_index, &cs); 4452 4452 fdput(f); 4453 4453
+6 -6
mm/memcontrol-v1.c
··· 1947 1947 INIT_WORK(&event->remove, memcg_event_remove); 1948 1948 1949 1949 efile = fdget(efd); 1950 - if (!efile.file) { 1950 + if (!fd_file(efile)) { 1951 1951 ret = -EBADF; 1952 1952 goto out_kfree; 1953 1953 } 1954 1954 1955 - event->eventfd = eventfd_ctx_fileget(efile.file); 1955 + event->eventfd = eventfd_ctx_fileget(fd_file(efile)); 1956 1956 if (IS_ERR(event->eventfd)) { 1957 1957 ret = PTR_ERR(event->eventfd); 1958 1958 goto out_put_efile; 1959 1959 } 1960 1960 1961 1961 cfile = fdget(cfd); 1962 - if (!cfile.file) { 1962 + if (!fd_file(cfile)) { 1963 1963 ret = -EBADF; 1964 1964 goto out_put_eventfd; 1965 1965 } 1966 1966 1967 1967 /* the process need read permission on control file */ 1968 1968 /* AV: shouldn't we check that it's been opened for read instead? */ 1969 - ret = file_permission(cfile.file, MAY_READ); 1969 + ret = file_permission(fd_file(cfile), MAY_READ); 1970 1970 if (ret < 0) 1971 1971 goto out_put_cfile; 1972 1972 ··· 1974 1974 * The control file must be a regular cgroup1 file. As a regular cgroup 1975 1975 * file can't be renamed, it's safe to access its name afterwards. 1976 1976 */ 1977 - cdentry = cfile.file->f_path.dentry; 1977 + cdentry = fd_file(cfile)->f_path.dentry; 1978 1978 if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) { 1979 1979 ret = -EINVAL; 1980 1980 goto out_put_cfile; ··· 2032 2032 if (ret) 2033 2033 goto out_put_css; 2034 2034 2035 - vfs_poll(efile.file, &event->pt); 2035 + vfs_poll(fd_file(efile), &event->pt); 2036 2036 2037 2037 spin_lock_irq(&memcg->event_list_lock); 2038 2038 list_add(&event->list, &memcg->event_list);
+5 -5
mm/readahead.c
··· 678 678 679 679 ret = -EBADF; 680 680 f = fdget(fd); 681 - if (!f.file || !(f.file->f_mode & FMODE_READ)) 681 + if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ)) 682 682 goto out; 683 683 684 684 /* ··· 687 687 * on this file, then we must return -EINVAL. 688 688 */ 689 689 ret = -EINVAL; 690 - if (!f.file->f_mapping || !f.file->f_mapping->a_ops || 691 - (!S_ISREG(file_inode(f.file)->i_mode) && 692 - !S_ISBLK(file_inode(f.file)->i_mode))) 690 + if (!fd_file(f)->f_mapping || !fd_file(f)->f_mapping->a_ops || 691 + (!S_ISREG(file_inode(fd_file(f))->i_mode) && 692 + !S_ISBLK(file_inode(fd_file(f))->i_mode))) 693 693 goto out; 694 694 695 - ret = vfs_fadvise(f.file, offset, count, POSIX_FADV_WILLNEED); 695 + ret = vfs_fadvise(fd_file(f), offset, count, POSIX_FADV_WILLNEED); 696 696 out: 697 697 fdput(f); 698 698 return ret;
+3 -3
net/core/net_namespace.c
··· 697 697 struct fd f = fdget(fd); 698 698 struct net *net = ERR_PTR(-EINVAL); 699 699 700 - if (!f.file) 700 + if (!fd_file(f)) 701 701 return ERR_PTR(-EBADF); 702 702 703 - if (proc_ns_file(f.file)) { 704 - struct ns_common *ns = get_proc_ns(file_inode(f.file)); 703 + if (proc_ns_file(fd_file(f))) { 704 + struct ns_common *ns = get_proc_ns(file_inode(fd_file(f))); 705 705 if (ns->ops == &netns_operations) 706 706 net = get_net(container_of(ns, struct net, ns)); 707 707 }
+7 -7
net/socket.c
··· 556 556 struct socket *sock; 557 557 558 558 *err = -EBADF; 559 - if (f.file) { 560 - sock = sock_from_file(f.file); 559 + if (fd_file(f)) { 560 + sock = sock_from_file(fd_file(f)); 561 561 if (likely(sock)) { 562 - *fput_needed = f.flags & FDPUT_FPUT; 562 + *fput_needed = f.word & FDPUT_FPUT; 563 563 return sock; 564 564 } 565 565 *err = -ENOTSOCK; ··· 2014 2014 struct fd f; 2015 2015 2016 2016 f = fdget(fd); 2017 - if (f.file) { 2018 - ret = __sys_accept4_file(f.file, upeer_sockaddr, 2017 + if (fd_file(f)) { 2018 + ret = __sys_accept4_file(fd_file(f), upeer_sockaddr, 2019 2019 upeer_addrlen, flags); 2020 2020 fdput(f); 2021 2021 } ··· 2076 2076 struct fd f; 2077 2077 2078 2078 f = fdget(fd); 2079 - if (f.file) { 2079 + if (fd_file(f)) { 2080 2080 struct sockaddr_storage address; 2081 2081 2082 2082 ret = move_addr_to_kernel(uservaddr, addrlen, &address); 2083 2083 if (!ret) 2084 - ret = __sys_connect_file(f.file, &address, addrlen, 0); 2084 + ret = __sys_connect_file(fd_file(f), &address, addrlen, 0); 2085 2085 fdput(f); 2086 2086 } 2087 2087
+2 -2
security/integrity/ima/ima_main.c
··· 1068 1068 return; 1069 1069 1070 1070 f = fdget(kernel_fd); 1071 - if (!f.file) 1071 + if (!fd_file(f)) 1072 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 1075 buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0, 1076 1076 NULL, false, NULL, 0); 1077 1077 fdput(f);
+11 -11
security/landlock/syscalls.c
··· 238 238 struct landlock_ruleset *ruleset; 239 239 240 240 ruleset_f = fdget(fd); 241 - if (!ruleset_f.file) 241 + if (!fd_file(ruleset_f)) 242 242 return ERR_PTR(-EBADF); 243 243 244 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 246 ruleset = ERR_PTR(-EBADFD); 247 247 goto out_fdput; 248 248 } 249 - if (!(ruleset_f.file->f_mode & mode)) { 249 + if (!(fd_file(ruleset_f)->f_mode & mode)) { 250 250 ruleset = ERR_PTR(-EPERM); 251 251 goto out_fdput; 252 252 } 253 - ruleset = ruleset_f.file->private_data; 253 + ruleset = fd_file(ruleset_f)->private_data; 254 254 if (WARN_ON_ONCE(ruleset->num_layers != 1)) { 255 255 ruleset = ERR_PTR(-EINVAL); 256 256 goto out_fdput; ··· 277 277 278 278 /* Handles O_PATH. */ 279 279 f = fdget_raw(fd); 280 - if (!f.file) 280 + if (!fd_file(f)) 281 281 return -EBADF; 282 282 /* 283 283 * Forbids ruleset FDs, internal filesystems (e.g. nsfs), including 284 284 * pseudo filesystems that will never be mountable (e.g. sockfs, 285 285 * pipefs). 286 286 */ 287 - if ((f.file->f_op == &ruleset_fops) || 288 - (f.file->f_path.mnt->mnt_flags & MNT_INTERNAL) || 289 - (f.file->f_path.dentry->d_sb->s_flags & SB_NOUSER) || 290 - d_is_negative(f.file->f_path.dentry) || 291 - IS_PRIVATE(d_backing_inode(f.file->f_path.dentry))) { 287 + if ((fd_file(f)->f_op == &ruleset_fops) || 288 + (fd_file(f)->f_path.mnt->mnt_flags & MNT_INTERNAL) || 289 + (fd_file(f)->f_path.dentry->d_sb->s_flags & SB_NOUSER) || 290 + d_is_negative(fd_file(f)->f_path.dentry) || 291 + IS_PRIVATE(d_backing_inode(fd_file(f)->f_path.dentry))) { 292 292 err = -EBADFD; 293 293 goto out_fdput; 294 294 } 295 - *path = f.file->f_path; 295 + *path = fd_file(f)->f_path; 296 296 path_get(path); 297 297 298 298 out_fdput:
+2 -2
security/loadpin/loadpin.c
··· 296 296 return -EPERM; 297 297 298 298 f = fdget(fd); 299 - if (!f.file) 299 + if (!fd_file(f)) 300 300 return -EINVAL; 301 301 302 302 data = kzalloc(SZ_4K, GFP_KERNEL); ··· 305 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 309 if (rc < 0) 310 310 goto err; 311 311
+3 -3
sound/core/pcm_native.c
··· 2250 2250 bool nonatomic = substream->pcm->nonatomic; 2251 2251 CLASS(fd, f)(fd); 2252 2252 2253 - if (!f.file) 2253 + if (!fd_file(f)) 2254 2254 return -EBADFD; 2255 - if (!is_pcm_file(f.file)) 2255 + if (!is_pcm_file(fd_file(f))) 2256 2256 return -EBADFD; 2257 2257 2258 - pcm_file = f.file->private_data; 2258 + pcm_file = fd_file(f)->private_data; 2259 2259 substream1 = pcm_file->substream; 2260 2260 2261 2261 if (substream == substream1)
+3 -3
virt/kvm/eventfd.c
··· 328 328 seqcount_spinlock_init(&irqfd->irq_entry_sc, &kvm->irqfds.lock); 329 329 330 330 f = fdget(args->fd); 331 - if (!f.file) { 331 + if (!fd_file(f)) { 332 332 ret = -EBADF; 333 333 goto out; 334 334 } 335 335 336 - eventfd = eventfd_ctx_fileget(f.file); 336 + eventfd = eventfd_ctx_fileget(fd_file(f)); 337 337 if (IS_ERR(eventfd)) { 338 338 ret = PTR_ERR(eventfd); 339 339 goto fail; ··· 420 420 * Check if there was an event already pending on the eventfd 421 421 * before we registered, and trigger it as if we didn't miss it. 422 422 */ 423 - events = vfs_poll(f.file, &irqfd->pt); 423 + events = vfs_poll(fd_file(f), &irqfd->pt); 424 424 425 425 if (events & EPOLLIN) 426 426 schedule_work(&irqfd->inject);
+4 -4
virt/kvm/vfio.c
··· 194 194 int ret; 195 195 196 196 f = fdget(fd); 197 - if (!f.file) 197 + if (!fd_file(f)) 198 198 return -EBADF; 199 199 200 200 ret = -ENOENT; ··· 202 202 mutex_lock(&kv->lock); 203 203 204 204 list_for_each_entry(kvf, &kv->file_list, node) { 205 - if (kvf->file != f.file) 205 + if (kvf->file != fd_file(f)) 206 206 continue; 207 207 208 208 list_del(&kvf->node); ··· 240 240 return -EFAULT; 241 241 242 242 f = fdget(param.groupfd); 243 - if (!f.file) 243 + if (!fd_file(f)) 244 244 return -EBADF; 245 245 246 246 ret = -ENOENT; ··· 248 248 mutex_lock(&kv->lock); 249 249 250 250 list_for_each_entry(kvf, &kv->file_list, node) { 251 - if (kvf->file != f.file) 251 + if (kvf->file != fd_file(f)) 252 252 continue; 253 253 254 254 if (!kvf->iommu_group) {