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

switch simple cases of fget_light to fdget

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 2903ff01 a5b470ba

+631 -761
+6 -9
arch/alpha/kernel/osf_sys.c
··· 144 144 struct osf_dirent __user *, dirent, unsigned int, count, 145 145 long __user *, basep) 146 146 { 147 - int error, fput_needed; 148 - struct file *file; 147 + int error; 148 + struct fd arg = fdget(fd); 149 149 struct osf_dirent_callback buf; 150 150 151 - error = -EBADF; 152 - file = fget_light(fd, &fput_needed); 153 - if (!file) 154 - goto out; 151 + if (!arg.file) 152 + return -EBADF; 155 153 156 154 buf.dirent = dirent; 157 155 buf.basep = basep; 158 156 buf.count = count; 159 157 buf.error = 0; 160 158 161 - error = vfs_readdir(file, osf_filldir, &buf); 159 + error = vfs_readdir(arg.file, osf_filldir, &buf); 162 160 if (error >= 0) 163 161 error = buf.error; 164 162 if (count != buf.count) 165 163 error = count - buf.count; 166 164 167 - fput_light(file, fput_needed); 168 - out: 165 + fdput(arg); 169 166 return error; 170 167 } 171 168
+7 -8
arch/ia64/kernel/perfmon.c
··· 4780 4780 asmlinkage long 4781 4781 sys_perfmonctl (int fd, int cmd, void __user *arg, int count) 4782 4782 { 4783 - struct file *file = NULL; 4783 + struct fd f = {NULL, 0}; 4784 4784 pfm_context_t *ctx = NULL; 4785 4785 unsigned long flags = 0UL; 4786 4786 void *args_k = NULL; ··· 4789 4789 int narg, completed_args = 0, call_made = 0, cmd_flags; 4790 4790 int (*func)(pfm_context_t *ctx, void *arg, int count, struct pt_regs *regs); 4791 4791 int (*getsize)(void *arg, size_t *sz); 4792 - int fput_needed; 4793 4792 #define PFM_MAX_ARGSIZE 4096 4794 4793 4795 4794 /* ··· 4877 4878 4878 4879 ret = -EBADF; 4879 4880 4880 - file = fget_light(fd, &fput_needed); 4881 - if (unlikely(file == NULL)) { 4881 + f = fdget(fd); 4882 + if (unlikely(f.file == NULL)) { 4882 4883 DPRINT(("invalid fd %d\n", fd)); 4883 4884 goto error_args; 4884 4885 } 4885 - if (unlikely(PFM_IS_FILE(file) == 0)) { 4886 + if (unlikely(PFM_IS_FILE(f.file) == 0)) { 4886 4887 DPRINT(("fd %d not related to perfmon\n", fd)); 4887 4888 goto error_args; 4888 4889 } 4889 4890 4890 - ctx = file->private_data; 4891 + ctx = f.file->private_data; 4891 4892 if (unlikely(ctx == NULL)) { 4892 4893 DPRINT(("no context for fd %d\n", fd)); 4893 4894 goto error_args; ··· 4917 4918 if (call_made && PFM_CMD_RW_ARG(cmd) && copy_to_user(arg, args_k, base_sz*count)) ret = -EFAULT; 4918 4919 4919 4920 error_args: 4920 - if (file) 4921 - fput_light(file, fput_needed); 4921 + if (f.file) 4922 + fdput(f); 4922 4923 4923 4924 kfree(args_k); 4924 4925
+8 -9
arch/parisc/hpux/fs.c
··· 109 109 110 110 int hpux_getdents(unsigned int fd, struct hpux_dirent __user *dirent, unsigned int count) 111 111 { 112 - struct file * file; 112 + struct fd arg; 113 113 struct hpux_dirent __user * lastdirent; 114 114 struct getdents_callback buf; 115 - int error = -EBADF, fput_needed; 115 + int error; 116 116 117 - file = fget_light(fd, &fput_needed); 118 - if (!file) 119 - goto out; 117 + arg = fdget(fd); 118 + if (!arg.file) 119 + return -EBADF; 120 120 121 121 buf.current_dir = dirent; 122 122 buf.previous = NULL; 123 123 buf.count = count; 124 124 buf.error = 0; 125 125 126 - error = vfs_readdir(file, filldir, &buf); 126 + error = vfs_readdir(arg.file, filldir, &buf); 127 127 if (error >= 0) 128 128 error = buf.error; 129 129 lastdirent = buf.previous; 130 130 if (lastdirent) { 131 - if (put_user(file->f_pos, &lastdirent->d_off)) 131 + if (put_user(arg.file->f_pos, &lastdirent->d_off)) 132 132 error = -EFAULT; 133 133 else 134 134 error = count - buf.count; 135 135 } 136 136 137 - fput_light(file, fput_needed); 138 - out: 137 + fdput(arg); 139 138 return error; 140 139 } 141 140
+9 -12
arch/powerpc/platforms/cell/spu_syscalls.c
··· 69 69 umode_t, mode, int, neighbor_fd) 70 70 { 71 71 long ret; 72 - struct file *neighbor; 73 - int fput_needed; 74 72 struct spufs_calls *calls; 75 73 76 74 calls = spufs_calls_get(); ··· 76 78 return -ENOSYS; 77 79 78 80 if (flags & SPU_CREATE_AFFINITY_SPU) { 81 + struct fd neighbor = fdget(neighbor_fd); 79 82 ret = -EBADF; 80 - neighbor = fget_light(neighbor_fd, &fput_needed); 81 - if (neighbor) { 82 - ret = calls->create_thread(name, flags, mode, neighbor); 83 - fput_light(neighbor, fput_needed); 83 + if (neighbor.file) { 84 + ret = calls->create_thread(name, flags, mode, neighbor.file); 85 + fdput(neighbor); 84 86 } 85 87 } else 86 88 ret = calls->create_thread(name, flags, mode, NULL); ··· 92 94 asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus) 93 95 { 94 96 long ret; 95 - struct file *filp; 96 - int fput_needed; 97 + struct fd arg; 97 98 struct spufs_calls *calls; 98 99 99 100 calls = spufs_calls_get(); ··· 100 103 return -ENOSYS; 101 104 102 105 ret = -EBADF; 103 - filp = fget_light(fd, &fput_needed); 104 - if (filp) { 105 - ret = calls->spu_run(filp, unpc, ustatus); 106 - fput_light(filp, fput_needed); 106 + arg = fdget(fd); 107 + if (arg.file) { 108 + ret = calls->spu_run(arg.file, unpc, ustatus); 109 + fdput(arg); 107 110 } 108 111 109 112 spufs_calls_put(calls);
+6 -6
drivers/infiniband/core/ucma.c
··· 1184 1184 struct rdma_ucm_migrate_id cmd; 1185 1185 struct rdma_ucm_migrate_resp resp; 1186 1186 struct ucma_context *ctx; 1187 - struct file *filp; 1187 + struct fd f; 1188 1188 struct ucma_file *cur_file; 1189 - int ret = 0, fput_needed; 1189 + int ret = 0; 1190 1190 1191 1191 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 1192 1192 return -EFAULT; 1193 1193 1194 1194 /* Get current fd to protect against it being closed */ 1195 - filp = fget_light(cmd.fd, &fput_needed); 1196 - if (!filp) 1195 + f = fdget(cmd.fd); 1196 + if (!f.file) 1197 1197 return -ENOENT; 1198 1198 1199 1199 /* Validate current fd and prevent destruction of id. */ 1200 - ctx = ucma_get_ctx(filp->private_data, cmd.id); 1200 + ctx = ucma_get_ctx(f.file->private_data, cmd.id); 1201 1201 if (IS_ERR(ctx)) { 1202 1202 ret = PTR_ERR(ctx); 1203 1203 goto file_put; ··· 1231 1231 1232 1232 ucma_put_ctx(ctx); 1233 1233 file_put: 1234 - fput_light(filp, fput_needed); 1234 + fdput(f); 1235 1235 return ret; 1236 1236 } 1237 1237
+9 -9
drivers/infiniband/core/uverbs_cmd.c
··· 705 705 struct ib_udata udata; 706 706 struct ib_uxrcd_object *obj; 707 707 struct ib_xrcd *xrcd = NULL; 708 - struct file *f = NULL; 708 + struct fd f = {NULL, 0}; 709 709 struct inode *inode = NULL; 710 - int ret = 0, fput_needed; 710 + int ret = 0; 711 711 int new_xrcd = 0; 712 712 713 713 if (out_len < sizeof resp) ··· 724 724 725 725 if (cmd.fd != -1) { 726 726 /* search for file descriptor */ 727 - f = fget_light(cmd.fd, &fput_needed); 728 - if (!f) { 727 + f = fdget(cmd.fd); 728 + if (!f.file) { 729 729 ret = -EBADF; 730 730 goto err_tree_mutex_unlock; 731 731 } 732 732 733 - inode = f->f_dentry->d_inode; 733 + inode = f.file->f_path.dentry->d_inode; 734 734 xrcd = find_xrcd(file->device, inode); 735 735 if (!xrcd && !(cmd.oflags & O_CREAT)) { 736 736 /* no file descriptor. Need CREATE flag */ ··· 795 795 goto err_copy; 796 796 } 797 797 798 - if (f) 799 - fput_light(f, fput_needed); 798 + if (f.file) 799 + fdput(f); 800 800 801 801 mutex_lock(&file->mutex); 802 802 list_add_tail(&obj->uobject.list, &file->ucontext->xrcd_list); ··· 825 825 put_uobj_write(&obj->uobject); 826 826 827 827 err_tree_mutex_unlock: 828 - if (f) 829 - fput_light(f, fput_needed); 828 + if (f.file) 829 + fdput(f); 830 830 831 831 mutex_unlock(&file->device->xrcd_tree_mutex); 832 832
+5 -7
drivers/infiniband/core/uverbs_main.c
··· 541 541 struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd) 542 542 { 543 543 struct ib_uverbs_event_file *ev_file = NULL; 544 - struct file *filp; 545 - int fput_needed; 544 + struct fd f = fdget(fd); 546 545 547 - filp = fget_light(fd, &fput_needed); 548 - if (!filp) 546 + if (!f.file) 549 547 return NULL; 550 548 551 - if (filp->f_op != &uverbs_event_fops) 549 + if (f.file->f_op != &uverbs_event_fops) 552 550 goto out; 553 551 554 - ev_file = filp->private_data; 552 + ev_file = f.file->private_data; 555 553 if (ev_file->is_async) { 556 554 ev_file = NULL; 557 555 goto out; ··· 558 560 kref_get(&ev_file->ref); 559 561 560 562 out: 561 - fput_light(filp, fput_needed); 563 + fdput(f); 562 564 return ev_file; 563 565 } 564 566
+8 -9
drivers/vfio/vfio.c
··· 1014 1014 1015 1015 static int vfio_group_set_container(struct vfio_group *group, int container_fd) 1016 1016 { 1017 - struct file *filep; 1017 + struct fd f; 1018 1018 struct vfio_container *container; 1019 1019 struct vfio_iommu_driver *driver; 1020 - int ret = 0, fput_needed; 1020 + int ret = 0; 1021 1021 1022 1022 if (atomic_read(&group->container_users)) 1023 1023 return -EINVAL; 1024 1024 1025 - filep = fget_light(container_fd, &fput_needed); 1026 - if (!filep) 1025 + f = fdget(container_fd); 1026 + if (!f.file) 1027 1027 return -EBADF; 1028 1028 1029 1029 /* Sanity check, is this really our fd? */ 1030 - if (filep->f_op != &vfio_fops) { 1031 - fput_light(filep, fput_needed); 1030 + if (f.file->f_op != &vfio_fops) { 1031 + fdput(f); 1032 1032 return -EINVAL; 1033 1033 } 1034 1034 1035 - container = filep->private_data; 1035 + container = f.file->private_data; 1036 1036 WARN_ON(!container); /* fget ensures we don't race vfio_release */ 1037 1037 1038 1038 mutex_lock(&container->group_lock); ··· 1054 1054 1055 1055 unlock_out: 1056 1056 mutex_unlock(&container->group_lock); 1057 - fput_light(filep, fput_needed); 1058 - 1057 + fdput(f); 1059 1058 return ret; 1060 1059 } 1061 1060
+5 -7
drivers/video/msm/mdp.c
··· 257 257 unsigned long *start, unsigned long *len, 258 258 struct file **filep) 259 259 { 260 - int put_needed, ret = 0; 261 - struct file *file; 262 - 263 - file = fget_light(img->memory_id, &put_needed); 264 - if (file == NULL) 260 + int ret = 0; 261 + struct fd f = fdget(img->memory_id); 262 + if (f.file == NULL) 265 263 return -1; 266 264 267 - if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) { 265 + if (MAJOR(f.file->f_dentry->d_inode->i_rdev) == FB_MAJOR) { 268 266 *start = info->fix.smem_start; 269 267 *len = info->fix.smem_len; 270 268 } else 271 269 ret = -1; 272 - fput_light(file, put_needed); 270 + fdput(f); 273 271 274 272 return ret; 275 273 }
+12 -14
fs/btrfs/ioctl.c
··· 1397 1397 u64 *transid, bool readonly, 1398 1398 struct btrfs_qgroup_inherit **inherit) 1399 1399 { 1400 - struct file *src_file; 1401 1400 int namelen; 1402 1401 int ret = 0; 1403 1402 ··· 1420 1421 ret = btrfs_mksubvol(&file->f_path, name, namelen, 1421 1422 NULL, transid, readonly, inherit); 1422 1423 } else { 1424 + struct fd src = fdget(fd); 1423 1425 struct inode *src_inode; 1424 - int fput_needed; 1425 - src_file = fget_light(fd, &fput_needed); 1426 - if (!src_file) { 1426 + if (!src.file) { 1427 1427 ret = -EINVAL; 1428 1428 goto out_drop_write; 1429 1429 } 1430 1430 1431 - src_inode = src_file->f_path.dentry->d_inode; 1431 + src_inode = src.file->f_path.dentry->d_inode; 1432 1432 if (src_inode->i_sb != file->f_path.dentry->d_inode->i_sb) { 1433 1433 printk(KERN_INFO "btrfs: Snapshot src from " 1434 1434 "another FS\n"); ··· 1437 1439 BTRFS_I(src_inode)->root, 1438 1440 transid, readonly, inherit); 1439 1441 } 1440 - fput_light(src_file, fput_needed); 1442 + fdput(src); 1441 1443 } 1442 1444 out_drop_write: 1443 1445 mnt_drop_write_file(file); ··· 2339 2341 { 2340 2342 struct inode *inode = fdentry(file)->d_inode; 2341 2343 struct btrfs_root *root = BTRFS_I(inode)->root; 2342 - struct file *src_file; 2344 + struct fd src_file; 2343 2345 struct inode *src; 2344 2346 struct btrfs_trans_handle *trans; 2345 2347 struct btrfs_path *path; ··· 2348 2350 struct btrfs_key key; 2349 2351 u32 nritems; 2350 2352 int slot; 2351 - int ret, fput_needed; 2353 + int ret; 2352 2354 u64 len = olen; 2353 2355 u64 bs = root->fs_info->sb->s_blocksize; 2354 2356 u64 hint_byte; ··· 2374 2376 if (ret) 2375 2377 return ret; 2376 2378 2377 - src_file = fget_light(srcfd, &fput_needed); 2378 - if (!src_file) { 2379 + src_file = fdget(srcfd); 2380 + if (!src_file.file) { 2379 2381 ret = -EBADF; 2380 2382 goto out_drop_write; 2381 2383 } 2382 2384 2383 2385 ret = -EXDEV; 2384 - if (src_file->f_path.mnt != file->f_path.mnt) 2386 + if (src_file.file->f_path.mnt != file->f_path.mnt) 2385 2387 goto out_fput; 2386 2388 2387 - src = src_file->f_dentry->d_inode; 2389 + src = src_file.file->f_dentry->d_inode; 2388 2390 2389 2391 ret = -EINVAL; 2390 2392 if (src == inode) 2391 2393 goto out_fput; 2392 2394 2393 2395 /* the src must be open for reading */ 2394 - if (!(src_file->f_mode & FMODE_READ)) 2396 + if (!(src_file.file->f_mode & FMODE_READ)) 2395 2397 goto out_fput; 2396 2398 2397 2399 /* don't make the dst file partly checksummed */ ··· 2722 2724 vfree(buf); 2723 2725 btrfs_free_path(path); 2724 2726 out_fput: 2725 - fput_light(src_file, fput_needed); 2727 + fdput(src_file); 2726 2728 out_drop_write: 2727 2729 mnt_drop_write_file(file); 2728 2730 return ret;
+7 -7
fs/coda/inode.c
··· 107 107 108 108 static int get_device_index(struct coda_mount_data *data) 109 109 { 110 - struct file *file; 110 + struct fd f; 111 111 struct inode *inode; 112 - int idx, fput_needed; 112 + int idx; 113 113 114 114 if (data == NULL) { 115 115 printk("coda_read_super: Bad mount data\n"); ··· 121 121 return -1; 122 122 } 123 123 124 - file = fget_light(data->fd, &fput_needed); 125 - if (!file) 124 + f = fdget(data->fd); 125 + if (!f.file) 126 126 goto Ebadf; 127 - inode = file->f_path.dentry->d_inode; 127 + inode = f.file->f_path.dentry->d_inode; 128 128 if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) { 129 - fput_light(file, fput_needed); 129 + fdput(f); 130 130 goto Ebadf; 131 131 } 132 132 133 133 idx = iminor(inode); 134 - fput_light(file, fput_needed); 134 + fdput(f); 135 135 136 136 if (idx < 0 || idx >= MAX_CODADEVS) { 137 137 printk("coda_read_super: Bad minor number\n");
+40 -50
fs/compat.c
··· 870 870 struct compat_old_linux_dirent __user *dirent, unsigned int count) 871 871 { 872 872 int error; 873 - struct file *file; 874 - int fput_needed; 873 + struct fd f = fdget(fd); 875 874 struct compat_readdir_callback buf; 876 875 877 - file = fget_light(fd, &fput_needed); 878 - if (!file) 876 + if (!f.file) 879 877 return -EBADF; 880 878 881 879 buf.result = 0; 882 880 buf.dirent = dirent; 883 881 884 - error = vfs_readdir(file, compat_fillonedir, &buf); 882 + error = vfs_readdir(f.file, compat_fillonedir, &buf); 885 883 if (buf.result) 886 884 error = buf.result; 887 885 888 - fput_light(file, fput_needed); 886 + fdput(f); 889 887 return error; 890 888 } 891 889 ··· 947 949 asmlinkage long compat_sys_getdents(unsigned int fd, 948 950 struct compat_linux_dirent __user *dirent, unsigned int count) 949 951 { 950 - struct file * file; 952 + struct fd f; 951 953 struct compat_linux_dirent __user * lastdirent; 952 954 struct compat_getdents_callback buf; 953 - int fput_needed; 954 955 int error; 955 956 956 957 if (!access_ok(VERIFY_WRITE, dirent, count)) 957 958 return -EFAULT; 958 959 959 - file = fget_light(fd, &fput_needed); 960 - if (!file) 960 + f = fdget(fd); 961 + if (!f.file) 961 962 return -EBADF; 962 963 963 964 buf.current_dir = dirent; ··· 964 967 buf.count = count; 965 968 buf.error = 0; 966 969 967 - error = vfs_readdir(file, compat_filldir, &buf); 970 + error = vfs_readdir(f.file, compat_filldir, &buf); 968 971 if (error >= 0) 969 972 error = buf.error; 970 973 lastdirent = buf.previous; 971 974 if (lastdirent) { 972 - if (put_user(file->f_pos, &lastdirent->d_off)) 975 + if (put_user(f.file->f_pos, &lastdirent->d_off)) 973 976 error = -EFAULT; 974 977 else 975 978 error = count - buf.count; 976 979 } 977 - fput_light(file, fput_needed); 980 + fdput(f); 978 981 return error; 979 982 } 980 983 ··· 1032 1035 asmlinkage long compat_sys_getdents64(unsigned int fd, 1033 1036 struct linux_dirent64 __user * dirent, unsigned int count) 1034 1037 { 1035 - struct file * file; 1038 + struct fd f; 1036 1039 struct linux_dirent64 __user * lastdirent; 1037 1040 struct compat_getdents_callback64 buf; 1038 - int fput_needed; 1039 1041 int error; 1040 1042 1041 1043 if (!access_ok(VERIFY_WRITE, dirent, count)) 1042 1044 return -EFAULT; 1043 1045 1044 - file = fget_light(fd, &fput_needed); 1045 - if (!file) 1046 + f = fdget(fd); 1047 + if (!f.file) 1046 1048 return -EBADF; 1047 1049 1048 1050 buf.current_dir = dirent; ··· 1049 1053 buf.count = count; 1050 1054 buf.error = 0; 1051 1055 1052 - error = vfs_readdir(file, compat_filldir64, &buf); 1056 + error = vfs_readdir(f.file, compat_filldir64, &buf); 1053 1057 if (error >= 0) 1054 1058 error = buf.error; 1055 1059 lastdirent = buf.previous; 1056 1060 if (lastdirent) { 1057 - typeof(lastdirent->d_off) d_off = file->f_pos; 1061 + typeof(lastdirent->d_off) d_off = f.file->f_pos; 1058 1062 if (__put_user_unaligned(d_off, &lastdirent->d_off)) 1059 1063 error = -EFAULT; 1060 1064 else 1061 1065 error = count - buf.count; 1062 1066 } 1063 - fput_light(file, fput_needed); 1067 + fdput(f); 1064 1068 return error; 1065 1069 } 1066 1070 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */ ··· 1148 1152 compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec, 1149 1153 unsigned long vlen) 1150 1154 { 1151 - struct file *file; 1152 - int fput_needed; 1155 + struct fd f = fdget(fd); 1153 1156 ssize_t ret; 1154 1157 loff_t pos; 1155 1158 1156 - file = fget_light(fd, &fput_needed); 1157 - if (!file) 1159 + if (!f.file) 1158 1160 return -EBADF; 1159 - pos = file->f_pos; 1160 - ret = compat_readv(file, vec, vlen, &pos); 1161 - file->f_pos = pos; 1162 - fput_light(file, fput_needed); 1161 + pos = f.file->f_pos; 1162 + ret = compat_readv(f.file, vec, vlen, &pos); 1163 + f.file->f_pos = pos; 1164 + fdput(f); 1163 1165 return ret; 1164 1166 } 1165 1167 ··· 1165 1171 compat_sys_preadv64(unsigned long fd, const struct compat_iovec __user *vec, 1166 1172 unsigned long vlen, loff_t pos) 1167 1173 { 1168 - struct file *file; 1169 - int fput_needed; 1174 + struct fd f; 1170 1175 ssize_t ret; 1171 1176 1172 1177 if (pos < 0) 1173 1178 return -EINVAL; 1174 - file = fget_light(fd, &fput_needed); 1175 - if (!file) 1179 + f = fdget(fd); 1180 + if (!f.file) 1176 1181 return -EBADF; 1177 1182 ret = -ESPIPE; 1178 - if (file->f_mode & FMODE_PREAD) 1179 - ret = compat_readv(file, vec, vlen, &pos); 1180 - fput_light(file, fput_needed); 1183 + if (f.file->f_mode & FMODE_PREAD) 1184 + ret = compat_readv(f.file, vec, vlen, &pos); 1185 + fdput(f); 1181 1186 return ret; 1182 1187 } 1183 1188 ··· 1214 1221 compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, 1215 1222 unsigned long vlen) 1216 1223 { 1217 - struct file *file; 1218 - int fput_needed; 1224 + struct fd f = fdget(fd); 1219 1225 ssize_t ret; 1220 1226 loff_t pos; 1221 1227 1222 - file = fget_light(fd, &fput_needed); 1223 - if (!file) 1228 + if (!f.file) 1224 1229 return -EBADF; 1225 - pos = file->f_pos; 1226 - ret = compat_writev(file, vec, vlen, &pos); 1227 - file->f_pos = pos; 1228 - fput_light(file, fput_needed); 1230 + pos = f.file->f_pos; 1231 + ret = compat_writev(f.file, vec, vlen, &pos); 1232 + f.file->f_pos = pos; 1233 + fdput(f); 1229 1234 return ret; 1230 1235 } 1231 1236 ··· 1231 1240 compat_sys_pwritev64(unsigned long fd, const struct compat_iovec __user *vec, 1232 1241 unsigned long vlen, loff_t pos) 1233 1242 { 1234 - struct file *file; 1235 - int fput_needed; 1243 + struct fd f; 1236 1244 ssize_t ret; 1237 1245 1238 1246 if (pos < 0) 1239 1247 return -EINVAL; 1240 - file = fget_light(fd, &fput_needed); 1241 - if (!file) 1248 + f = fdget(fd); 1249 + if (!f.file) 1242 1250 return -EBADF; 1243 1251 ret = -ESPIPE; 1244 - if (file->f_mode & FMODE_PWRITE) 1245 - ret = compat_writev(file, vec, vlen, &pos); 1246 - fput_light(file, fput_needed); 1252 + if (f.file->f_mode & FMODE_PWRITE) 1253 + ret = compat_writev(f.file, vec, vlen, &pos); 1254 + fdput(f); 1247 1255 return ret; 1248 1256 } 1249 1257
+12 -15
fs/compat_ioctl.c
··· 1531 1531 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, 1532 1532 unsigned long arg) 1533 1533 { 1534 - struct file *filp; 1534 + struct fd f = fdget(fd); 1535 1535 int error = -EBADF; 1536 - int fput_needed; 1537 - 1538 - filp = fget_light(fd, &fput_needed); 1539 - if (!filp) 1536 + if (!f.file) 1540 1537 goto out; 1541 1538 1542 1539 /* RED-PEN how should LSM module know it's handling 32bit? */ 1543 - error = security_file_ioctl(filp, cmd, arg); 1540 + error = security_file_ioctl(f.file, cmd, arg); 1544 1541 if (error) 1545 1542 goto out_fput; 1546 1543 ··· 1557 1560 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) 1558 1561 case FS_IOC_RESVSP_32: 1559 1562 case FS_IOC_RESVSP64_32: 1560 - error = compat_ioctl_preallocate(filp, compat_ptr(arg)); 1563 + error = compat_ioctl_preallocate(f.file, compat_ptr(arg)); 1561 1564 goto out_fput; 1562 1565 #else 1563 1566 case FS_IOC_RESVSP: 1564 1567 case FS_IOC_RESVSP64: 1565 - error = ioctl_preallocate(filp, compat_ptr(arg)); 1568 + error = ioctl_preallocate(f.file, compat_ptr(arg)); 1566 1569 goto out_fput; 1567 1570 #endif 1568 1571 1569 1572 case FIBMAP: 1570 1573 case FIGETBSZ: 1571 1574 case FIONREAD: 1572 - if (S_ISREG(filp->f_path.dentry->d_inode->i_mode)) 1575 + if (S_ISREG(f.file->f_path.dentry->d_inode->i_mode)) 1573 1576 break; 1574 1577 /*FALL THROUGH*/ 1575 1578 1576 1579 default: 1577 - if (filp->f_op && filp->f_op->compat_ioctl) { 1578 - error = filp->f_op->compat_ioctl(filp, cmd, arg); 1580 + if (f.file->f_op && f.file->f_op->compat_ioctl) { 1581 + error = f.file->f_op->compat_ioctl(f.file, cmd, arg); 1579 1582 if (error != -ENOIOCTLCMD) 1580 1583 goto out_fput; 1581 1584 } 1582 1585 1583 - if (!filp->f_op || !filp->f_op->unlocked_ioctl) 1586 + if (!f.file->f_op || !f.file->f_op->unlocked_ioctl) 1584 1587 goto do_ioctl; 1585 1588 break; 1586 1589 } ··· 1588 1591 if (compat_ioctl_check_table(XFORM(cmd))) 1589 1592 goto found_handler; 1590 1593 1591 - error = do_ioctl_trans(fd, cmd, arg, filp); 1594 + error = do_ioctl_trans(fd, cmd, arg, f.file); 1592 1595 if (error == -ENOIOCTLCMD) 1593 1596 error = -ENOTTY; 1594 1597 ··· 1597 1600 found_handler: 1598 1601 arg = (unsigned long)compat_ptr(arg); 1599 1602 do_ioctl: 1600 - error = do_vfs_ioctl(filp, fd, cmd, arg); 1603 + error = do_vfs_ioctl(f.file, fd, cmd, arg); 1601 1604 out_fput: 1602 - fput_light(filp, fput_needed); 1605 + fdput(f); 1603 1606 out: 1604 1607 return error; 1605 1608 }
+10 -15
fs/eventpoll.c
··· 1809 1809 SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events, 1810 1810 int, maxevents, int, timeout) 1811 1811 { 1812 - int error, fput_needed; 1813 - struct file *file; 1812 + int error; 1813 + struct fd f; 1814 1814 struct eventpoll *ep; 1815 1815 1816 1816 /* The maximum number of event must be greater than zero */ ··· 1818 1818 return -EINVAL; 1819 1819 1820 1820 /* Verify that the area passed by the user is writeable */ 1821 - if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) { 1822 - error = -EFAULT; 1823 - goto error_return; 1824 - } 1821 + if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) 1822 + return -EFAULT; 1825 1823 1826 1824 /* Get the "struct file *" for the eventpoll file */ 1827 - error = -EBADF; 1828 - file = fget_light(epfd, &fput_needed); 1829 - if (!file) 1830 - goto error_return; 1825 + f = fdget(epfd); 1826 + if (!f.file) 1827 + return -EBADF; 1831 1828 1832 1829 /* 1833 1830 * We have to check that the file structure underneath the fd 1834 1831 * the user passed to us _is_ an eventpoll file. 1835 1832 */ 1836 1833 error = -EINVAL; 1837 - if (!is_file_epoll(file)) 1834 + if (!is_file_epoll(f.file)) 1838 1835 goto error_fput; 1839 1836 1840 1837 /* 1841 1838 * At this point it is safe to assume that the "private_data" contains 1842 1839 * our own data structure. 1843 1840 */ 1844 - ep = file->private_data; 1841 + ep = f.file->private_data; 1845 1842 1846 1843 /* Time to fish for events ... */ 1847 1844 error = ep_poll(ep, events, maxevents, timeout); 1848 1845 1849 1846 error_fput: 1850 - fput_light(file, fput_needed); 1851 - error_return: 1852 - 1847 + fdput(f); 1853 1848 return error; 1854 1849 } 1855 1850
+7 -7
fs/ext4/ioctl.c
··· 233 233 234 234 case EXT4_IOC_MOVE_EXT: { 235 235 struct move_extent me; 236 - struct file *donor_filp; 237 - int err, fput_needed; 236 + struct fd donor; 237 + int err; 238 238 239 239 if (!(filp->f_mode & FMODE_READ) || 240 240 !(filp->f_mode & FMODE_WRITE)) ··· 245 245 return -EFAULT; 246 246 me.moved_len = 0; 247 247 248 - donor_filp = fget_light(me.donor_fd, &fput_needed); 249 - if (!donor_filp) 248 + donor = fdget(me.donor_fd); 249 + if (!donor.file) 250 250 return -EBADF; 251 251 252 - if (!(donor_filp->f_mode & FMODE_WRITE)) { 252 + if (!(donor.file->f_mode & FMODE_WRITE)) { 253 253 err = -EBADF; 254 254 goto mext_out; 255 255 } ··· 266 266 if (err) 267 267 goto mext_out; 268 268 269 - err = ext4_move_extents(filp, donor_filp, me.orig_start, 269 + err = ext4_move_extents(filp, donor.file, me.orig_start, 270 270 me.donor_start, me.len, &me.moved_len); 271 271 mnt_drop_write_file(filp); 272 272 ··· 274 274 &me, sizeof(me))) 275 275 err = -EFAULT; 276 276 mext_out: 277 - fput_light(donor_filp, fput_needed); 277 + fdput(donor); 278 278 return err; 279 279 } 280 280
+14 -18
fs/fcntl.c
··· 348 348 349 349 SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) 350 350 { 351 - struct file *filp; 352 - int fput_needed; 351 + struct fd f = fdget_raw(fd); 353 352 long err = -EBADF; 354 353 355 - filp = fget_raw_light(fd, &fput_needed); 356 - if (!filp) 354 + if (!f.file) 357 355 goto out; 358 356 359 - if (unlikely(filp->f_mode & FMODE_PATH)) { 357 + if (unlikely(f.file->f_mode & FMODE_PATH)) { 360 358 if (!check_fcntl_cmd(cmd)) 361 359 goto out1; 362 360 } 363 361 364 - err = security_file_fcntl(filp, cmd, arg); 362 + err = security_file_fcntl(f.file, cmd, arg); 365 363 if (!err) 366 - err = do_fcntl(fd, cmd, arg, filp); 364 + err = do_fcntl(fd, cmd, arg, f.file); 367 365 368 366 out1: 369 - fput_light(filp, fput_needed); 367 + fdput(f); 370 368 out: 371 369 return err; 372 370 } ··· 373 375 SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, 374 376 unsigned long, arg) 375 377 { 376 - struct file * filp; 378 + struct fd f = fdget_raw(fd); 377 379 long err = -EBADF; 378 - int fput_needed; 379 380 380 - filp = fget_raw_light(fd, &fput_needed); 381 - if (!filp) 381 + if (!f.file) 382 382 goto out; 383 383 384 - if (unlikely(filp->f_mode & FMODE_PATH)) { 384 + if (unlikely(f.file->f_mode & FMODE_PATH)) { 385 385 if (!check_fcntl_cmd(cmd)) 386 386 goto out1; 387 387 } 388 388 389 - err = security_file_fcntl(filp, cmd, arg); 389 + err = security_file_fcntl(f.file, cmd, arg); 390 390 if (err) 391 391 goto out1; 392 392 393 393 switch (cmd) { 394 394 case F_GETLK64: 395 - err = fcntl_getlk64(filp, (struct flock64 __user *) arg); 395 + err = fcntl_getlk64(f.file, (struct flock64 __user *) arg); 396 396 break; 397 397 case F_SETLK64: 398 398 case F_SETLKW64: 399 - err = fcntl_setlk64(fd, filp, cmd, 399 + err = fcntl_setlk64(fd, f.file, cmd, 400 400 (struct flock64 __user *) arg); 401 401 break; 402 402 default: 403 - err = do_fcntl(fd, cmd, arg, filp); 403 + err = do_fcntl(fd, cmd, arg, f.file); 404 404 break; 405 405 } 406 406 out1: 407 - fput_light(filp, fput_needed); 407 + fdput(f); 408 408 out: 409 409 return err; 410 410 }
+7 -10
fs/fhandle.c
··· 113 113 114 114 static struct vfsmount *get_vfsmount_from_fd(int fd) 115 115 { 116 - struct path path; 116 + struct vfsmount *mnt; 117 117 118 118 if (fd == AT_FDCWD) { 119 119 struct fs_struct *fs = current->fs; 120 120 spin_lock(&fs->lock); 121 - path = fs->pwd; 122 - mntget(path.mnt); 121 + mnt = mntget(fs->pwd.mnt); 123 122 spin_unlock(&fs->lock); 124 123 } else { 125 - int fput_needed; 126 - struct file *file = fget_light(fd, &fput_needed); 127 - if (!file) 124 + struct fd f = fdget(fd); 125 + if (!f.file) 128 126 return ERR_PTR(-EBADF); 129 - path = file->f_path; 130 - mntget(path.mnt); 131 - fput_light(file, fput_needed); 127 + mnt = mntget(f.file->f_path.mnt); 128 + fdput(f); 132 129 } 133 - return path.mnt; 130 + return mnt; 134 131 } 135 132 136 133 static int vfs_dentry_acceptable(void *context, struct dentry *dentry)
+8 -15
fs/ioctl.c
··· 603 603 604 604 SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) 605 605 { 606 - struct file *filp; 607 - int error = -EBADF; 608 - int fput_needed; 606 + int error; 607 + struct fd f = fdget(fd); 609 608 610 - filp = fget_light(fd, &fput_needed); 611 - if (!filp) 612 - goto out; 613 - 614 - error = security_file_ioctl(filp, cmd, arg); 615 - if (error) 616 - goto out_fput; 617 - 618 - error = do_vfs_ioctl(filp, fd, cmd, arg); 619 - out_fput: 620 - fput_light(filp, fput_needed); 621 - out: 609 + if (!f.file) 610 + return -EBADF; 611 + error = security_file_ioctl(f.file, cmd, arg); 612 + if (!error) 613 + error = do_vfs_ioctl(f.file, fd, cmd, arg); 614 + fdput(f); 622 615 return error; 623 616 }
+9 -11
fs/locks.c
··· 1625 1625 */ 1626 1626 SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) 1627 1627 { 1628 - struct file *filp; 1629 - int fput_needed; 1628 + struct fd f = fdget(fd); 1630 1629 struct file_lock *lock; 1631 1630 int can_sleep, unlock; 1632 1631 int error; 1633 1632 1634 1633 error = -EBADF; 1635 - filp = fget_light(fd, &fput_needed); 1636 - if (!filp) 1634 + if (!f.file) 1637 1635 goto out; 1638 1636 1639 1637 can_sleep = !(cmd & LOCK_NB); ··· 1639 1641 unlock = (cmd == LOCK_UN); 1640 1642 1641 1643 if (!unlock && !(cmd & LOCK_MAND) && 1642 - !(filp->f_mode & (FMODE_READ|FMODE_WRITE))) 1644 + !(f.file->f_mode & (FMODE_READ|FMODE_WRITE))) 1643 1645 goto out_putf; 1644 1646 1645 - error = flock_make_lock(filp, &lock, cmd); 1647 + error = flock_make_lock(f.file, &lock, cmd); 1646 1648 if (error) 1647 1649 goto out_putf; 1648 1650 if (can_sleep) 1649 1651 lock->fl_flags |= FL_SLEEP; 1650 1652 1651 - error = security_file_lock(filp, lock->fl_type); 1653 + error = security_file_lock(f.file, lock->fl_type); 1652 1654 if (error) 1653 1655 goto out_free; 1654 1656 1655 - if (filp->f_op && filp->f_op->flock) 1656 - error = filp->f_op->flock(filp, 1657 + if (f.file->f_op && f.file->f_op->flock) 1658 + error = f.file->f_op->flock(f.file, 1657 1659 (can_sleep) ? F_SETLKW : F_SETLK, 1658 1660 lock); 1659 1661 else 1660 - error = flock_lock_file_wait(filp, lock); 1662 + error = flock_lock_file_wait(f.file, lock); 1661 1663 1662 1664 out_free: 1663 1665 locks_free_lock(lock); 1664 1666 1665 1667 out_putf: 1666 - fput_light(filp, fput_needed); 1668 + fdput(f); 1667 1669 out: 1668 1670 return error; 1669 1671 }
+17 -22
fs/namei.c
··· 1797 1797 struct nameidata *nd, struct file **fp) 1798 1798 { 1799 1799 int retval = 0; 1800 - int fput_needed; 1801 - struct file *file; 1802 1800 1803 1801 nd->last_type = LAST_ROOT; /* if there are only slashes... */ 1804 1802 nd->flags = flags | LOOKUP_JUMPED; ··· 1848 1850 get_fs_pwd(current->fs, &nd->path); 1849 1851 } 1850 1852 } else { 1853 + struct fd f = fdget_raw(dfd); 1851 1854 struct dentry *dentry; 1852 1855 1853 - file = fget_raw_light(dfd, &fput_needed); 1854 - retval = -EBADF; 1855 - if (!file) 1856 - goto out_fail; 1856 + if (!f.file) 1857 + return -EBADF; 1857 1858 1858 - dentry = file->f_path.dentry; 1859 + dentry = f.file->f_path.dentry; 1859 1860 1860 1861 if (*name) { 1861 - retval = -ENOTDIR; 1862 - if (!S_ISDIR(dentry->d_inode->i_mode)) 1863 - goto fput_fail; 1862 + if (!S_ISDIR(dentry->d_inode->i_mode)) { 1863 + fdput(f); 1864 + return -ENOTDIR; 1865 + } 1864 1866 1865 1867 retval = inode_permission(dentry->d_inode, MAY_EXEC); 1866 - if (retval) 1867 - goto fput_fail; 1868 + if (retval) { 1869 + fdput(f); 1870 + return retval; 1871 + } 1868 1872 } 1869 1873 1870 - nd->path = file->f_path; 1874 + nd->path = f.file->f_path; 1871 1875 if (flags & LOOKUP_RCU) { 1872 - if (fput_needed) 1873 - *fp = file; 1876 + if (f.need_put) 1877 + *fp = f.file; 1874 1878 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); 1875 1879 lock_rcu_walk(); 1876 1880 } else { 1877 - path_get(&file->f_path); 1878 - fput_light(file, fput_needed); 1881 + path_get(&nd->path); 1882 + fdput(f); 1879 1883 } 1880 1884 } 1881 1885 1882 1886 nd->inode = nd->path.dentry->d_inode; 1883 1887 return 0; 1884 - 1885 - fput_fail: 1886 - fput_light(file, fput_needed); 1887 - out_fail: 1888 - return retval; 1889 1888 } 1890 1889 1891 1890 static inline int lookup_last(struct nameidata *nd, struct path *path)
+13 -15
fs/notify/fanotify/fanotify_user.c
··· 451 451 dfd, filename, flags); 452 452 453 453 if (filename == NULL) { 454 - struct file *file; 455 - int fput_needed; 454 + struct fd f = fdget(dfd); 456 455 457 456 ret = -EBADF; 458 - file = fget_light(dfd, &fput_needed); 459 - if (!file) 457 + if (!f.file) 460 458 goto out; 461 459 462 460 ret = -ENOTDIR; 463 461 if ((flags & FAN_MARK_ONLYDIR) && 464 - !(S_ISDIR(file->f_path.dentry->d_inode->i_mode))) { 465 - fput_light(file, fput_needed); 462 + !(S_ISDIR(f.file->f_path.dentry->d_inode->i_mode))) { 463 + fdput(f); 466 464 goto out; 467 465 } 468 466 469 - *path = file->f_path; 467 + *path = f.file->f_path; 470 468 path_get(path); 471 - fput_light(file, fput_needed); 469 + fdput(f); 472 470 } else { 473 471 unsigned int lookup_flags = 0; 474 472 ··· 746 748 struct inode *inode = NULL; 747 749 struct vfsmount *mnt = NULL; 748 750 struct fsnotify_group *group; 749 - struct file *filp; 751 + struct fd f; 750 752 struct path path; 751 - int ret, fput_needed; 753 + int ret; 752 754 753 755 pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", 754 756 __func__, fanotify_fd, flags, dfd, pathname, mask); ··· 782 784 #endif 783 785 return -EINVAL; 784 786 785 - filp = fget_light(fanotify_fd, &fput_needed); 786 - if (unlikely(!filp)) 787 + f = fdget(fanotify_fd); 788 + if (unlikely(!f.file)) 787 789 return -EBADF; 788 790 789 791 /* verify that this is indeed an fanotify instance */ 790 792 ret = -EINVAL; 791 - if (unlikely(filp->f_op != &fanotify_fops)) 793 + if (unlikely(f.file->f_op != &fanotify_fops)) 792 794 goto fput_and_out; 793 - group = filp->private_data; 795 + group = f.file->private_data; 794 796 795 797 /* 796 798 * group->priority == FS_PRIO_0 == FAN_CLASS_NOTIF. These are not ··· 837 839 838 840 path_put(&path); 839 841 fput_and_out: 840 - fput_light(filp, fput_needed); 842 + fdput(f); 841 843 return ret; 842 844 } 843 845
+14 -14
fs/notify/inotify/inotify_user.c
··· 757 757 struct fsnotify_group *group; 758 758 struct inode *inode; 759 759 struct path path; 760 - struct file *filp; 761 - int ret, fput_needed; 760 + struct fd f; 761 + int ret; 762 762 unsigned flags = 0; 763 763 764 - filp = fget_light(fd, &fput_needed); 765 - if (unlikely(!filp)) 764 + f = fdget(fd); 765 + if (unlikely(!f.file)) 766 766 return -EBADF; 767 767 768 768 /* verify that this is indeed an inotify instance */ 769 - if (unlikely(filp->f_op != &inotify_fops)) { 769 + if (unlikely(f.file->f_op != &inotify_fops)) { 770 770 ret = -EINVAL; 771 771 goto fput_and_out; 772 772 } ··· 782 782 783 783 /* inode held in place by reference to path; group by fget on fd */ 784 784 inode = path.dentry->d_inode; 785 - group = filp->private_data; 785 + group = f.file->private_data; 786 786 787 787 /* create/update an inode mark */ 788 788 ret = inotify_update_watch(group, inode, mask); 789 789 path_put(&path); 790 790 fput_and_out: 791 - fput_light(filp, fput_needed); 791 + fdput(f); 792 792 return ret; 793 793 } 794 794 ··· 796 796 { 797 797 struct fsnotify_group *group; 798 798 struct inotify_inode_mark *i_mark; 799 - struct file *filp; 800 - int ret = 0, fput_needed; 799 + struct fd f; 800 + int ret = 0; 801 801 802 - filp = fget_light(fd, &fput_needed); 803 - if (unlikely(!filp)) 802 + f = fdget(fd); 803 + if (unlikely(!f.file)) 804 804 return -EBADF; 805 805 806 806 /* verify that this is indeed an inotify instance */ 807 807 ret = -EINVAL; 808 - if (unlikely(filp->f_op != &inotify_fops)) 808 + if (unlikely(f.file->f_op != &inotify_fops)) 809 809 goto out; 810 810 811 - group = filp->private_data; 811 + group = f.file->private_data; 812 812 813 813 ret = -EINVAL; 814 814 i_mark = inotify_idr_find(group, wd); ··· 823 823 fsnotify_put_mark(&i_mark->fsn_mark); 824 824 825 825 out: 826 - fput_light(filp, fput_needed); 826 + fdput(f); 827 827 return ret; 828 828 } 829 829
+19 -20
fs/ocfs2/cluster/heartbeat.c
··· 1746 1746 long fd; 1747 1747 int sectsize; 1748 1748 char *p = (char *)page; 1749 - struct file *filp = NULL; 1750 - struct inode *inode = NULL; 1749 + struct fd f; 1750 + struct inode *inode; 1751 1751 ssize_t ret = -EINVAL; 1752 1752 int live_threshold; 1753 - int fput_needed; 1754 1753 1755 1754 if (reg->hr_bdev) 1756 1755 goto out; ··· 1766 1767 if (fd < 0 || fd >= INT_MAX) 1767 1768 goto out; 1768 1769 1769 - filp = fget_light(fd, &fput_needed); 1770 - if (filp == NULL) 1770 + f = fdget(fd); 1771 + if (f.file == NULL) 1771 1772 goto out; 1772 1773 1773 1774 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 || 1774 1775 reg->hr_block_bytes == 0) 1775 - goto out; 1776 + goto out2; 1776 1777 1777 - inode = igrab(filp->f_mapping->host); 1778 + inode = igrab(f.file->f_mapping->host); 1778 1779 if (inode == NULL) 1779 - goto out; 1780 + goto out2; 1780 1781 1781 1782 if (!S_ISBLK(inode->i_mode)) 1782 - goto out; 1783 + goto out3; 1783 1784 1784 - reg->hr_bdev = I_BDEV(filp->f_mapping->host); 1785 + reg->hr_bdev = I_BDEV(f.file->f_mapping->host); 1785 1786 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, NULL); 1786 1787 if (ret) { 1787 1788 reg->hr_bdev = NULL; 1788 - goto out; 1789 + goto out3; 1789 1790 } 1790 1791 inode = NULL; 1791 1792 ··· 1797 1798 "blocksize %u incorrect for device, expected %d", 1798 1799 reg->hr_block_bytes, sectsize); 1799 1800 ret = -EINVAL; 1800 - goto out; 1801 + goto out3; 1801 1802 } 1802 1803 1803 1804 o2hb_init_region_params(reg); ··· 1811 1812 ret = o2hb_map_slot_data(reg); 1812 1813 if (ret) { 1813 1814 mlog_errno(ret); 1814 - goto out; 1815 + goto out3; 1815 1816 } 1816 1817 1817 1818 ret = o2hb_populate_slot_data(reg); 1818 1819 if (ret) { 1819 1820 mlog_errno(ret); 1820 - goto out; 1821 + goto out3; 1821 1822 } 1822 1823 1823 1824 INIT_DELAYED_WORK(&reg->hr_write_timeout_work, o2hb_write_timeout); ··· 1847 1848 if (IS_ERR(hb_task)) { 1848 1849 ret = PTR_ERR(hb_task); 1849 1850 mlog_errno(ret); 1850 - goto out; 1851 + goto out3; 1851 1852 } 1852 1853 1853 1854 spin_lock(&o2hb_live_lock); ··· 1863 1864 1864 1865 if (reg->hr_aborted_start) { 1865 1866 ret = -EIO; 1866 - goto out; 1867 + goto out3; 1867 1868 } 1868 1869 1869 1870 /* Ok, we were woken. Make sure it wasn't by drop_item() */ ··· 1882 1883 printk(KERN_NOTICE "o2hb: Heartbeat started on region %s (%s)\n", 1883 1884 config_item_name(&reg->hr_item), reg->hr_dev_name); 1884 1885 1886 + out3: 1887 + iput(inode); 1888 + out2: 1889 + fdput(f); 1885 1890 out: 1886 - if (filp) 1887 - fput_light(filp, fput_needed); 1888 - if (inode) 1889 - iput(inode); 1890 1891 if (ret < 0) { 1891 1892 if (reg->hr_bdev) { 1892 1893 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE);
+30 -34
fs/open.c
··· 134 134 { 135 135 struct inode *inode; 136 136 struct dentry *dentry; 137 - struct file *file; 138 - int error, fput_needed; 137 + struct fd f; 138 + int error; 139 139 140 140 error = -EINVAL; 141 141 if (length < 0) 142 142 goto out; 143 143 error = -EBADF; 144 - file = fget_light(fd, &fput_needed); 145 - if (!file) 144 + f = fdget(fd); 145 + if (!f.file) 146 146 goto out; 147 147 148 148 /* explicitly opened as large or we are on 64-bit box */ 149 - if (file->f_flags & O_LARGEFILE) 149 + if (f.file->f_flags & O_LARGEFILE) 150 150 small = 0; 151 151 152 - dentry = file->f_path.dentry; 152 + dentry = f.file->f_path.dentry; 153 153 inode = dentry->d_inode; 154 154 error = -EINVAL; 155 - if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE)) 155 + if (!S_ISREG(inode->i_mode) || !(f.file->f_mode & FMODE_WRITE)) 156 156 goto out_putf; 157 157 158 158 error = -EINVAL; ··· 165 165 goto out_putf; 166 166 167 167 sb_start_write(inode->i_sb); 168 - error = locks_verify_truncate(inode, file, length); 168 + error = locks_verify_truncate(inode, f.file, length); 169 169 if (!error) 170 - error = security_path_truncate(&file->f_path); 170 + error = security_path_truncate(&f.file->f_path); 171 171 if (!error) 172 - error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file); 172 + error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file); 173 173 sb_end_write(inode->i_sb); 174 174 out_putf: 175 - fput_light(file, fput_needed); 175 + fdput(f); 176 176 out: 177 177 return error; 178 178 } ··· 276 276 277 277 SYSCALL_DEFINE(fallocate)(int fd, int mode, loff_t offset, loff_t len) 278 278 { 279 - struct file *file; 280 - int error = -EBADF, fput_needed; 279 + struct fd f = fdget(fd); 280 + int error = -EBADF; 281 281 282 - file = fget_light(fd, &fput_needed); 283 - if (file) { 284 - error = do_fallocate(file, mode, offset, len); 285 - fput_light(file, fput_needed); 282 + if (f.file) { 283 + error = do_fallocate(f.file, mode, offset, len); 284 + fdput(f); 286 285 } 287 - 288 286 return error; 289 287 } 290 288 ··· 398 400 399 401 SYSCALL_DEFINE1(fchdir, unsigned int, fd) 400 402 { 401 - struct file *file; 403 + struct fd f = fdget_raw(fd); 402 404 struct inode *inode; 403 - int error, fput_needed; 405 + int error = -EBADF; 404 406 405 407 error = -EBADF; 406 - file = fget_raw_light(fd, &fput_needed); 407 - if (!file) 408 + if (!f.file) 408 409 goto out; 409 410 410 - inode = file->f_path.dentry->d_inode; 411 + inode = f.file->f_path.dentry->d_inode; 411 412 412 413 error = -ENOTDIR; 413 414 if (!S_ISDIR(inode->i_mode)) ··· 414 417 415 418 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR); 416 419 if (!error) 417 - set_fs_pwd(current->fs, &file->f_path); 420 + set_fs_pwd(current->fs, &f.file->f_path); 418 421 out_putf: 419 - fput_light(file, fput_needed); 422 + fdput(f); 420 423 out: 421 424 return error; 422 425 } ··· 579 582 580 583 SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) 581 584 { 582 - struct file *file; 583 - int error = -EBADF, fput_needed; 585 + struct fd f = fdget(fd); 586 + int error = -EBADF; 584 587 585 - file = fget_light(fd, &fput_needed); 586 - if (!file) 588 + if (!f.file) 587 589 goto out; 588 590 589 - error = mnt_want_write_file(file); 591 + error = mnt_want_write_file(f.file); 590 592 if (error) 591 593 goto out_fput; 592 - audit_inode(NULL, file->f_path.dentry); 593 - error = chown_common(&file->f_path, user, group); 594 - mnt_drop_write_file(file); 594 + audit_inode(NULL, f.file->f_path.dentry); 595 + error = chown_common(&f.file->f_path, user, group); 596 + mnt_drop_write_file(f.file); 595 597 out_fput: 596 - fput_light(file, fput_needed); 598 + fdput(f); 597 599 out: 598 600 return error; 599 601 }
+77 -99
fs/read_write.c
··· 232 232 SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, origin) 233 233 { 234 234 off_t retval; 235 - struct file * file; 236 - int fput_needed; 237 - 238 - retval = -EBADF; 239 - file = fget_light(fd, &fput_needed); 240 - if (!file) 241 - goto bad; 235 + struct fd f = fdget(fd); 236 + if (!f.file) 237 + return -EBADF; 242 238 243 239 retval = -EINVAL; 244 240 if (origin <= SEEK_MAX) { 245 - loff_t res = vfs_llseek(file, offset, origin); 241 + loff_t res = vfs_llseek(f.file, offset, origin); 246 242 retval = res; 247 243 if (res != (loff_t)retval) 248 244 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */ 249 245 } 250 - fput_light(file, fput_needed); 251 - bad: 246 + fdput(f); 252 247 return retval; 253 248 } 254 249 ··· 253 258 unsigned int, origin) 254 259 { 255 260 int retval; 256 - struct file * file; 261 + struct fd f = fdget(fd); 257 262 loff_t offset; 258 - int fput_needed; 259 263 260 - retval = -EBADF; 261 - file = fget_light(fd, &fput_needed); 262 - if (!file) 263 - goto bad; 264 + if (!f.file) 265 + return -EBADF; 264 266 265 267 retval = -EINVAL; 266 268 if (origin > SEEK_MAX) 267 269 goto out_putf; 268 270 269 - offset = vfs_llseek(file, ((loff_t) offset_high << 32) | offset_low, 271 + offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low, 270 272 origin); 271 273 272 274 retval = (int)offset; ··· 273 281 retval = 0; 274 282 } 275 283 out_putf: 276 - fput_light(file, fput_needed); 277 - bad: 284 + fdput(f); 278 285 return retval; 279 286 } 280 287 #endif ··· 452 461 453 462 SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count) 454 463 { 455 - struct file *file; 464 + struct fd f = fdget(fd); 456 465 ssize_t ret = -EBADF; 457 - int fput_needed; 458 466 459 - file = fget_light(fd, &fput_needed); 460 - if (file) { 461 - loff_t pos = file_pos_read(file); 462 - ret = vfs_read(file, buf, count, &pos); 463 - file_pos_write(file, pos); 464 - fput_light(file, fput_needed); 467 + if (f.file) { 468 + loff_t pos = file_pos_read(f.file); 469 + ret = vfs_read(f.file, buf, count, &pos); 470 + file_pos_write(f.file, pos); 471 + fdput(f); 465 472 } 466 - 467 473 return ret; 468 474 } 469 475 470 476 SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, 471 477 size_t, count) 472 478 { 473 - struct file *file; 479 + struct fd f = fdget(fd); 474 480 ssize_t ret = -EBADF; 475 - int fput_needed; 476 481 477 - file = fget_light(fd, &fput_needed); 478 - if (file) { 479 - loff_t pos = file_pos_read(file); 480 - ret = vfs_write(file, buf, count, &pos); 481 - file_pos_write(file, pos); 482 - fput_light(file, fput_needed); 482 + if (f.file) { 483 + loff_t pos = file_pos_read(f.file); 484 + ret = vfs_write(f.file, buf, count, &pos); 485 + file_pos_write(f.file, pos); 486 + fdput(f); 483 487 } 484 488 485 489 return ret; ··· 483 497 SYSCALL_DEFINE(pread64)(unsigned int fd, char __user *buf, 484 498 size_t count, loff_t pos) 485 499 { 486 - struct file *file; 500 + struct fd f; 487 501 ssize_t ret = -EBADF; 488 - int fput_needed; 489 502 490 503 if (pos < 0) 491 504 return -EINVAL; 492 505 493 - file = fget_light(fd, &fput_needed); 494 - if (file) { 506 + f = fdget(fd); 507 + if (f.file) { 495 508 ret = -ESPIPE; 496 - if (file->f_mode & FMODE_PREAD) 497 - ret = vfs_read(file, buf, count, &pos); 498 - fput_light(file, fput_needed); 509 + if (f.file->f_mode & FMODE_PREAD) 510 + ret = vfs_read(f.file, buf, count, &pos); 511 + fdput(f); 499 512 } 500 513 501 514 return ret; ··· 511 526 SYSCALL_DEFINE(pwrite64)(unsigned int fd, const char __user *buf, 512 527 size_t count, loff_t pos) 513 528 { 514 - struct file *file; 529 + struct fd f; 515 530 ssize_t ret = -EBADF; 516 - int fput_needed; 517 531 518 532 if (pos < 0) 519 533 return -EINVAL; 520 534 521 - file = fget_light(fd, &fput_needed); 522 - if (file) { 535 + f = fdget(fd); 536 + if (f.file) { 523 537 ret = -ESPIPE; 524 - if (file->f_mode & FMODE_PWRITE) 525 - ret = vfs_write(file, buf, count, &pos); 526 - fput_light(file, fput_needed); 538 + if (f.file->f_mode & FMODE_PWRITE) 539 + ret = vfs_write(f.file, buf, count, &pos); 540 + fdput(f); 527 541 } 528 542 529 543 return ret; ··· 773 789 SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec, 774 790 unsigned long, vlen) 775 791 { 776 - struct file *file; 792 + struct fd f = fdget(fd); 777 793 ssize_t ret = -EBADF; 778 - int fput_needed; 779 794 780 - file = fget_light(fd, &fput_needed); 781 - if (file) { 782 - loff_t pos = file_pos_read(file); 783 - ret = vfs_readv(file, vec, vlen, &pos); 784 - file_pos_write(file, pos); 785 - fput_light(file, fput_needed); 795 + if (f.file) { 796 + loff_t pos = file_pos_read(f.file); 797 + ret = vfs_readv(f.file, vec, vlen, &pos); 798 + file_pos_write(f.file, pos); 799 + fdput(f); 786 800 } 787 801 788 802 if (ret > 0) ··· 792 810 SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec, 793 811 unsigned long, vlen) 794 812 { 795 - struct file *file; 813 + struct fd f = fdget(fd); 796 814 ssize_t ret = -EBADF; 797 - int fput_needed; 798 815 799 - file = fget_light(fd, &fput_needed); 800 - if (file) { 801 - loff_t pos = file_pos_read(file); 802 - ret = vfs_writev(file, vec, vlen, &pos); 803 - file_pos_write(file, pos); 804 - fput_light(file, fput_needed); 816 + if (f.file) { 817 + loff_t pos = file_pos_read(f.file); 818 + ret = vfs_writev(f.file, vec, vlen, &pos); 819 + file_pos_write(f.file, pos); 820 + fdput(f); 805 821 } 806 822 807 823 if (ret > 0) ··· 818 838 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h) 819 839 { 820 840 loff_t pos = pos_from_hilo(pos_h, pos_l); 821 - struct file *file; 841 + struct fd f; 822 842 ssize_t ret = -EBADF; 823 - int fput_needed; 824 843 825 844 if (pos < 0) 826 845 return -EINVAL; 827 846 828 - file = fget_light(fd, &fput_needed); 829 - if (file) { 847 + f = fdget(fd); 848 + if (f.file) { 830 849 ret = -ESPIPE; 831 - if (file->f_mode & FMODE_PREAD) 832 - ret = vfs_readv(file, vec, vlen, &pos); 833 - fput_light(file, fput_needed); 850 + if (f.file->f_mode & FMODE_PREAD) 851 + ret = vfs_readv(f.file, vec, vlen, &pos); 852 + fdput(f); 834 853 } 835 854 836 855 if (ret > 0) ··· 842 863 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h) 843 864 { 844 865 loff_t pos = pos_from_hilo(pos_h, pos_l); 845 - struct file *file; 866 + struct fd f; 846 867 ssize_t ret = -EBADF; 847 - int fput_needed; 848 868 849 869 if (pos < 0) 850 870 return -EINVAL; 851 871 852 - file = fget_light(fd, &fput_needed); 853 - if (file) { 872 + f = fdget(fd); 873 + if (f.file) { 854 874 ret = -ESPIPE; 855 - if (file->f_mode & FMODE_PWRITE) 856 - ret = vfs_writev(file, vec, vlen, &pos); 857 - fput_light(file, fput_needed); 875 + if (f.file->f_mode & FMODE_PWRITE) 876 + ret = vfs_writev(f.file, vec, vlen, &pos); 877 + fdput(f); 858 878 } 859 879 860 880 if (ret > 0) ··· 865 887 static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, 866 888 size_t count, loff_t max) 867 889 { 868 - struct file * in_file, * out_file; 869 - struct inode * in_inode, * out_inode; 890 + struct fd in, out; 891 + struct inode *in_inode, *out_inode; 870 892 loff_t pos; 871 893 ssize_t retval; 872 - int fput_needed_in, fput_needed_out, fl; 894 + int fl; 873 895 874 896 /* 875 897 * Get input file, and verify that it is ok.. 876 898 */ 877 899 retval = -EBADF; 878 - in_file = fget_light(in_fd, &fput_needed_in); 879 - if (!in_file) 900 + in = fdget(in_fd); 901 + if (!in.file) 880 902 goto out; 881 - if (!(in_file->f_mode & FMODE_READ)) 903 + if (!(in.file->f_mode & FMODE_READ)) 882 904 goto fput_in; 883 905 retval = -ESPIPE; 884 906 if (!ppos) 885 - ppos = &in_file->f_pos; 907 + ppos = &in.file->f_pos; 886 908 else 887 - if (!(in_file->f_mode & FMODE_PREAD)) 909 + if (!(in.file->f_mode & FMODE_PREAD)) 888 910 goto fput_in; 889 - retval = rw_verify_area(READ, in_file, ppos, count); 911 + retval = rw_verify_area(READ, in.file, ppos, count); 890 912 if (retval < 0) 891 913 goto fput_in; 892 914 count = retval; ··· 895 917 * Get output file, and verify that it is ok.. 896 918 */ 897 919 retval = -EBADF; 898 - out_file = fget_light(out_fd, &fput_needed_out); 899 - if (!out_file) 920 + out = fdget(out_fd); 921 + if (!out.file) 900 922 goto fput_in; 901 - if (!(out_file->f_mode & FMODE_WRITE)) 923 + if (!(out.file->f_mode & FMODE_WRITE)) 902 924 goto fput_out; 903 925 retval = -EINVAL; 904 - in_inode = in_file->f_path.dentry->d_inode; 905 - out_inode = out_file->f_path.dentry->d_inode; 906 - retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count); 926 + in_inode = in.file->f_path.dentry->d_inode; 927 + out_inode = out.file->f_path.dentry->d_inode; 928 + retval = rw_verify_area(WRITE, out.file, &out.file->f_pos, count); 907 929 if (retval < 0) 908 930 goto fput_out; 909 931 count = retval; ··· 927 949 * and the application is arguably buggy if it doesn't expect 928 950 * EAGAIN on a non-blocking file descriptor. 929 951 */ 930 - if (in_file->f_flags & O_NONBLOCK) 952 + if (in.file->f_flags & O_NONBLOCK) 931 953 fl = SPLICE_F_NONBLOCK; 932 954 #endif 933 - retval = do_splice_direct(in_file, ppos, out_file, count, fl); 955 + retval = do_splice_direct(in.file, ppos, out.file, count, fl); 934 956 935 957 if (retval > 0) { 936 958 add_rchar(current, retval); ··· 943 965 retval = -EOVERFLOW; 944 966 945 967 fput_out: 946 - fput_light(out_file, fput_needed_out); 968 + fdput(out); 947 969 fput_in: 948 - fput_light(in_file, fput_needed_in); 970 + fdput(in); 949 971 out: 950 972 return retval; 951 973 }
+16 -20
fs/readdir.c
··· 106 106 struct old_linux_dirent __user *, dirent, unsigned int, count) 107 107 { 108 108 int error; 109 - struct file * file; 109 + struct fd f = fdget(fd); 110 110 struct readdir_callback buf; 111 - int fput_needed; 112 111 113 - file = fget_light(fd, &fput_needed); 114 - if (!file) 112 + if (!f.file) 115 113 return -EBADF; 116 114 117 115 buf.result = 0; 118 116 buf.dirent = dirent; 119 117 120 - error = vfs_readdir(file, fillonedir, &buf); 118 + error = vfs_readdir(f.file, fillonedir, &buf); 121 119 if (buf.result) 122 120 error = buf.result; 123 121 124 - fput_light(file, fput_needed); 122 + fdput(f); 125 123 return error; 126 124 } 127 125 ··· 189 191 SYSCALL_DEFINE3(getdents, unsigned int, fd, 190 192 struct linux_dirent __user *, dirent, unsigned int, count) 191 193 { 192 - struct file * file; 194 + struct fd f; 193 195 struct linux_dirent __user * lastdirent; 194 196 struct getdents_callback buf; 195 - int fput_needed; 196 197 int error; 197 198 198 199 if (!access_ok(VERIFY_WRITE, dirent, count)) 199 200 return -EFAULT; 200 201 201 - file = fget_light(fd, &fput_needed); 202 - if (!file) 202 + f = fdget(fd); 203 + if (!f.file) 203 204 return -EBADF; 204 205 205 206 buf.current_dir = dirent; ··· 206 209 buf.count = count; 207 210 buf.error = 0; 208 211 209 - error = vfs_readdir(file, filldir, &buf); 212 + error = vfs_readdir(f.file, filldir, &buf); 210 213 if (error >= 0) 211 214 error = buf.error; 212 215 lastdirent = buf.previous; 213 216 if (lastdirent) { 214 - if (put_user(file->f_pos, &lastdirent->d_off)) 217 + if (put_user(f.file->f_pos, &lastdirent->d_off)) 215 218 error = -EFAULT; 216 219 else 217 220 error = count - buf.count; 218 221 } 219 - fput_light(file, fput_needed); 222 + fdput(f); 220 223 return error; 221 224 } 222 225 ··· 269 272 SYSCALL_DEFINE3(getdents64, unsigned int, fd, 270 273 struct linux_dirent64 __user *, dirent, unsigned int, count) 271 274 { 272 - struct file * file; 275 + struct fd f; 273 276 struct linux_dirent64 __user * lastdirent; 274 277 struct getdents_callback64 buf; 275 - int fput_needed; 276 278 int error; 277 279 278 280 if (!access_ok(VERIFY_WRITE, dirent, count)) 279 281 return -EFAULT; 280 282 281 - file = fget_light(fd, &fput_needed); 282 - if (!file) 283 + f = fdget(fd); 284 + if (!f.file) 283 285 return -EBADF; 284 286 285 287 buf.current_dir = dirent; ··· 286 290 buf.count = count; 287 291 buf.error = 0; 288 292 289 - error = vfs_readdir(file, filldir64, &buf); 293 + error = vfs_readdir(f.file, filldir64, &buf); 290 294 if (error >= 0) 291 295 error = buf.error; 292 296 lastdirent = buf.previous; 293 297 if (lastdirent) { 294 - typeof(lastdirent->d_off) d_off = file->f_pos; 298 + typeof(lastdirent->d_off) d_off = f.file->f_pos; 295 299 if (__put_user(d_off, &lastdirent->d_off)) 296 300 error = -EFAULT; 297 301 else 298 302 error = count - buf.count; 299 303 } 300 - fput_light(file, fput_needed); 304 + fdput(f); 301 305 return error; 302 306 }
+12 -16
fs/select.c
··· 428 428 for (i = 0; i < n; ++rinp, ++routp, ++rexp) { 429 429 unsigned long in, out, ex, all_bits, bit = 1, mask, j; 430 430 unsigned long res_in = 0, res_out = 0, res_ex = 0; 431 - const struct file_operations *f_op = NULL; 432 - struct file *file = NULL; 433 431 434 432 in = *inp++; out = *outp++; ex = *exp++; 435 433 all_bits = in | out | ex; ··· 437 439 } 438 440 439 441 for (j = 0; j < BITS_PER_LONG; ++j, ++i, bit <<= 1) { 440 - int fput_needed; 442 + struct fd f; 441 443 if (i >= n) 442 444 break; 443 445 if (!(bit & all_bits)) 444 446 continue; 445 - file = fget_light(i, &fput_needed); 446 - if (file) { 447 - f_op = file->f_op; 447 + f = fdget(i); 448 + if (f.file) { 449 + const struct file_operations *f_op; 450 + f_op = f.file->f_op; 448 451 mask = DEFAULT_POLLMASK; 449 452 if (f_op && f_op->poll) { 450 453 wait_key_set(wait, in, out, bit); 451 - mask = (*f_op->poll)(file, wait); 454 + mask = (*f_op->poll)(f.file, wait); 452 455 } 453 - fput_light(file, fput_needed); 456 + fdput(f); 454 457 if ((mask & POLLIN_SET) && (in & bit)) { 455 458 res_in |= bit; 456 459 retval++; ··· 724 725 mask = 0; 725 726 fd = pollfd->fd; 726 727 if (fd >= 0) { 727 - int fput_needed; 728 - struct file * file; 729 - 730 - file = fget_light(fd, &fput_needed); 728 + struct fd f = fdget(fd); 731 729 mask = POLLNVAL; 732 - if (file != NULL) { 730 + if (f.file) { 733 731 mask = DEFAULT_POLLMASK; 734 - if (file->f_op && file->f_op->poll) { 732 + if (f.file->f_op && f.file->f_op->poll) { 735 733 pwait->_key = pollfd->events|POLLERR|POLLHUP; 736 - mask = file->f_op->poll(file, pwait); 734 + mask = f.file->f_op->poll(f.file, pwait); 737 735 } 738 736 /* Mask out unneeded events. */ 739 737 mask &= pollfd->events | POLLERR | POLLHUP; 740 - fput_light(file, fput_needed); 738 + fdput(f); 741 739 } 742 740 } 743 741 pollfd->revents = mask;
+6 -7
fs/signalfd.c
··· 269 269 if (ufd < 0) 270 270 kfree(ctx); 271 271 } else { 272 - int fput_needed; 273 - struct file *file = fget_light(ufd, &fput_needed); 274 - if (!file) 272 + struct fd f = fdget(ufd); 273 + if (!f.file) 275 274 return -EBADF; 276 - ctx = file->private_data; 277 - if (file->f_op != &signalfd_fops) { 278 - fput_light(file, fput_needed); 275 + ctx = f.file->private_data; 276 + if (f.file->f_op != &signalfd_fops) { 277 + fdput(f); 279 278 return -EINVAL; 280 279 } 281 280 spin_lock_irq(&current->sighand->siglock); ··· 282 283 spin_unlock_irq(&current->sighand->siglock); 283 284 284 285 wake_up(&current->sighand->signalfd_wqh); 285 - fput_light(file, fput_needed); 286 + fdput(f); 286 287 } 287 288 288 289 return ufd;
+31 -36
fs/splice.c
··· 1666 1666 SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, iov, 1667 1667 unsigned long, nr_segs, unsigned int, flags) 1668 1668 { 1669 - struct file *file; 1669 + struct fd f; 1670 1670 long error; 1671 - int fput; 1672 1671 1673 1672 if (unlikely(nr_segs > UIO_MAXIOV)) 1674 1673 return -EINVAL; ··· 1675 1676 return 0; 1676 1677 1677 1678 error = -EBADF; 1678 - file = fget_light(fd, &fput); 1679 - if (file) { 1680 - if (file->f_mode & FMODE_WRITE) 1681 - error = vmsplice_to_pipe(file, iov, nr_segs, flags); 1682 - else if (file->f_mode & FMODE_READ) 1683 - error = vmsplice_to_user(file, iov, nr_segs, flags); 1679 + f = fdget(fd); 1680 + if (f.file) { 1681 + if (f.file->f_mode & FMODE_WRITE) 1682 + error = vmsplice_to_pipe(f.file, iov, nr_segs, flags); 1683 + else if (f.file->f_mode & FMODE_READ) 1684 + error = vmsplice_to_user(f.file, iov, nr_segs, flags); 1684 1685 1685 - fput_light(file, fput); 1686 + fdput(f); 1686 1687 } 1687 1688 1688 1689 return error; ··· 1692 1693 int, fd_out, loff_t __user *, off_out, 1693 1694 size_t, len, unsigned int, flags) 1694 1695 { 1696 + struct fd in, out; 1695 1697 long error; 1696 - struct file *in, *out; 1697 - int fput_in, fput_out; 1698 1698 1699 1699 if (unlikely(!len)) 1700 1700 return 0; 1701 1701 1702 1702 error = -EBADF; 1703 - in = fget_light(fd_in, &fput_in); 1704 - if (in) { 1705 - if (in->f_mode & FMODE_READ) { 1706 - out = fget_light(fd_out, &fput_out); 1707 - if (out) { 1708 - if (out->f_mode & FMODE_WRITE) 1709 - error = do_splice(in, off_in, 1710 - out, off_out, 1703 + in = fdget(fd_in); 1704 + if (in.file) { 1705 + if (in.file->f_mode & FMODE_READ) { 1706 + out = fdget(fd_out); 1707 + if (out.file) { 1708 + if (out.file->f_mode & FMODE_WRITE) 1709 + error = do_splice(in.file, off_in, 1710 + out.file, off_out, 1711 1711 len, flags); 1712 - fput_light(out, fput_out); 1712 + fdput(out); 1713 1713 } 1714 1714 } 1715 - 1716 - fput_light(in, fput_in); 1715 + fdput(in); 1717 1716 } 1718 - 1719 1717 return error; 1720 1718 } 1721 1719 ··· 2023 2027 2024 2028 SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags) 2025 2029 { 2026 - struct file *in; 2027 - int error, fput_in; 2030 + struct fd in; 2031 + int error; 2028 2032 2029 2033 if (unlikely(!len)) 2030 2034 return 0; 2031 2035 2032 2036 error = -EBADF; 2033 - in = fget_light(fdin, &fput_in); 2034 - if (in) { 2035 - if (in->f_mode & FMODE_READ) { 2036 - int fput_out; 2037 - struct file *out = fget_light(fdout, &fput_out); 2038 - 2039 - if (out) { 2040 - if (out->f_mode & FMODE_WRITE) 2041 - error = do_tee(in, out, len, flags); 2042 - fput_light(out, fput_out); 2037 + in = fdget(fdin); 2038 + if (in.file) { 2039 + if (in.file->f_mode & FMODE_READ) { 2040 + struct fd out = fdget(fdout); 2041 + if (out.file) { 2042 + if (out.file->f_mode & FMODE_WRITE) 2043 + error = do_tee(in.file, out.file, 2044 + len, flags); 2045 + fdput(out); 2043 2046 } 2044 2047 } 2045 - fput_light(in, fput_in); 2048 + fdput(in); 2046 2049 } 2047 2050 2048 2051 return error;
+5 -5
fs/stat.c
··· 57 57 58 58 int vfs_fstat(unsigned int fd, struct kstat *stat) 59 59 { 60 - int fput_needed; 61 - struct file *f = fget_raw_light(fd, &fput_needed); 60 + struct fd f = fdget_raw(fd); 62 61 int error = -EBADF; 63 62 64 - if (f) { 65 - error = vfs_getattr(f->f_path.mnt, f->f_path.dentry, stat); 66 - fput_light(f, fput_needed); 63 + if (f.file) { 64 + error = vfs_getattr(f.file->f_path.mnt, f.file->f_path.dentry, 65 + stat); 66 + fdput(f); 67 67 } 68 68 return error; 69 69 }
+4 -5
fs/statfs.c
··· 87 87 88 88 int fd_statfs(int fd, struct kstatfs *st) 89 89 { 90 - int fput_needed; 91 - struct file *file = fget_light(fd, &fput_needed); 90 + struct fd f = fdget(fd); 92 91 int error = -EBADF; 93 - if (file) { 94 - error = vfs_statfs(&file->f_path, st); 95 - fput_light(file, fput_needed); 92 + if (f.file) { 93 + error = vfs_statfs(&f.file->f_path, st); 94 + fdput(f); 96 95 } 97 96 return error; 98 97 }
+14 -19
fs/sync.c
··· 148 148 */ 149 149 SYSCALL_DEFINE1(syncfs, int, fd) 150 150 { 151 - struct file *file; 151 + struct fd f = fdget(fd); 152 152 struct super_block *sb; 153 153 int ret; 154 - int fput_needed; 155 154 156 - file = fget_light(fd, &fput_needed); 157 - if (!file) 155 + if (!f.file) 158 156 return -EBADF; 159 - sb = file->f_dentry->d_sb; 157 + sb = f.file->f_dentry->d_sb; 160 158 161 159 down_read(&sb->s_umount); 162 160 ret = sync_filesystem(sb); 163 161 up_read(&sb->s_umount); 164 162 165 - fput_light(file, fput_needed); 163 + fdput(f); 166 164 return ret; 167 165 } 168 166 ··· 199 201 200 202 static int do_fsync(unsigned int fd, int datasync) 201 203 { 202 - struct file *file; 204 + struct fd f = fdget(fd); 203 205 int ret = -EBADF; 204 - int fput_needed; 205 206 206 - file = fget_light(fd, &fput_needed); 207 - if (file) { 208 - ret = vfs_fsync(file, datasync); 209 - fput_light(file, fput_needed); 207 + if (f.file) { 208 + ret = vfs_fsync(f.file, datasync); 209 + fdput(f); 210 210 } 211 211 return ret; 212 212 } ··· 287 291 unsigned int flags) 288 292 { 289 293 int ret; 290 - struct file *file; 294 + struct fd f; 291 295 struct address_space *mapping; 292 296 loff_t endbyte; /* inclusive */ 293 - int fput_needed; 294 297 umode_t i_mode; 295 298 296 299 ret = -EINVAL; ··· 328 333 endbyte--; /* inclusive */ 329 334 330 335 ret = -EBADF; 331 - file = fget_light(fd, &fput_needed); 332 - if (!file) 336 + f = fdget(fd); 337 + if (!f.file) 333 338 goto out; 334 339 335 - i_mode = file->f_path.dentry->d_inode->i_mode; 340 + i_mode = f.file->f_path.dentry->d_inode->i_mode; 336 341 ret = -ESPIPE; 337 342 if (!S_ISREG(i_mode) && !S_ISBLK(i_mode) && !S_ISDIR(i_mode) && 338 343 !S_ISLNK(i_mode)) 339 344 goto out_put; 340 345 341 - mapping = file->f_mapping; 346 + mapping = f.file->f_mapping; 342 347 if (!mapping) { 343 348 ret = -EINVAL; 344 349 goto out_put; ··· 361 366 ret = filemap_fdatawait_range(mapping, offset, endbyte); 362 367 363 368 out_put: 364 - fput_light(file, fput_needed); 369 + fdput(f); 365 370 out: 366 371 return ret; 367 372 }
+22 -26
fs/timerfd.c
··· 234 234 .llseek = noop_llseek, 235 235 }; 236 236 237 - static struct file *timerfd_fget(int fd, int *fput_needed) 237 + static int timerfd_fget(int fd, struct fd *p) 238 238 { 239 - struct file *file; 240 - 241 - file = fget_light(fd, fput_needed); 242 - if (!file) 243 - return ERR_PTR(-EBADF); 244 - if (file->f_op != &timerfd_fops) { 245 - fput_light(file, *fput_needed); 246 - return ERR_PTR(-EINVAL); 239 + struct fd f = fdget(fd); 240 + if (!f.file) 241 + return -EBADF; 242 + if (f.file->f_op != &timerfd_fops) { 243 + fdput(f); 244 + return -EINVAL; 247 245 } 248 - 249 - return file; 246 + *p = f; 247 + return 0; 250 248 } 251 249 252 250 SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) ··· 282 284 const struct itimerspec __user *, utmr, 283 285 struct itimerspec __user *, otmr) 284 286 { 285 - struct file *file; 287 + struct fd f; 286 288 struct timerfd_ctx *ctx; 287 289 struct itimerspec ktmr, kotmr; 288 - int ret, fput_needed; 290 + int ret; 289 291 290 292 if (copy_from_user(&ktmr, utmr, sizeof(ktmr))) 291 293 return -EFAULT; ··· 295 297 !timespec_valid(&ktmr.it_interval)) 296 298 return -EINVAL; 297 299 298 - file = timerfd_fget(ufd, &fput_needed); 299 - if (IS_ERR(file)) 300 - return PTR_ERR(file); 301 - ctx = file->private_data; 300 + ret = timerfd_fget(ufd, &f); 301 + if (ret) 302 + return ret; 303 + ctx = f.file->private_data; 302 304 303 305 timerfd_setup_cancel(ctx, flags); 304 306 ··· 332 334 ret = timerfd_setup(ctx, flags, &ktmr); 333 335 334 336 spin_unlock_irq(&ctx->wqh.lock); 335 - fput_light(file, fput_needed); 337 + fdput(f); 336 338 if (otmr && copy_to_user(otmr, &kotmr, sizeof(kotmr))) 337 339 return -EFAULT; 338 340 ··· 341 343 342 344 SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr) 343 345 { 344 - struct file *file; 346 + struct fd f; 345 347 struct timerfd_ctx *ctx; 346 348 struct itimerspec kotmr; 347 - int fput_needed; 348 - 349 - file = timerfd_fget(ufd, &fput_needed); 350 - if (IS_ERR(file)) 351 - return PTR_ERR(file); 352 - ctx = file->private_data; 349 + int ret = timerfd_fget(ufd, &f); 350 + if (ret) 351 + return ret; 352 + ctx = f.file->private_data; 353 353 354 354 spin_lock_irq(&ctx->wqh.lock); 355 355 if (ctx->expired && ctx->tintv.tv64) { ··· 359 363 kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx)); 360 364 kotmr.it_interval = ktime_to_timespec(ctx->tintv); 361 365 spin_unlock_irq(&ctx->wqh.lock); 362 - fput_light(file, fput_needed); 366 + fdput(f); 363 367 364 368 return copy_to_user(otmr, &kotmr, sizeof(kotmr)) ? -EFAULT: 0; 365 369 }
+5 -6
fs/utimes.c
··· 140 140 goto out; 141 141 142 142 if (filename == NULL && dfd != AT_FDCWD) { 143 - int fput_needed; 144 - struct file *file; 143 + struct fd f; 145 144 146 145 if (flags & AT_SYMLINK_NOFOLLOW) 147 146 goto out; 148 147 149 - file = fget_light(dfd, &fput_needed); 148 + f = fdget(dfd); 150 149 error = -EBADF; 151 - if (!file) 150 + if (!f.file) 152 151 goto out; 153 152 154 - error = utimes_common(&file->f_path, times); 155 - fput_light(file, fput_needed); 153 + error = utimes_common(&f.file->f_path, times); 154 + fdput(f); 156 155 } else { 157 156 struct path path; 158 157 int lookup_flags = 0;
+22 -30
fs/xattr.c
··· 399 399 SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name, 400 400 const void __user *,value, size_t, size, int, flags) 401 401 { 402 - int fput_needed; 403 - struct file *f; 402 + struct fd f = fdget(fd); 404 403 struct dentry *dentry; 405 404 int error = -EBADF; 406 405 407 - f = fget_light(fd, &fput_needed); 408 - if (!f) 406 + if (!f.file) 409 407 return error; 410 - dentry = f->f_path.dentry; 408 + dentry = f.file->f_path.dentry; 411 409 audit_inode(NULL, dentry); 412 - error = mnt_want_write_file(f); 410 + error = mnt_want_write_file(f.file); 413 411 if (!error) { 414 412 error = setxattr(dentry, name, value, size, flags); 415 - mnt_drop_write_file(f); 413 + mnt_drop_write_file(f.file); 416 414 } 417 - fput_light(f, fput_needed); 415 + fdput(f); 418 416 return error; 419 417 } 420 418 ··· 493 495 SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, 494 496 void __user *, value, size_t, size) 495 497 { 496 - int fput_needed; 497 - struct file *f; 498 + struct fd f = fdget(fd); 498 499 ssize_t error = -EBADF; 499 500 500 - f = fget_light(fd, &fput_needed); 501 - if (!f) 501 + if (!f.file) 502 502 return error; 503 - audit_inode(NULL, f->f_path.dentry); 504 - error = getxattr(f->f_path.dentry, name, value, size); 505 - fput_light(f, fput_needed); 503 + audit_inode(NULL, f.file->f_path.dentry); 504 + error = getxattr(f.file->f_path.dentry, name, value, size); 505 + fdput(f); 506 506 return error; 507 507 } 508 508 ··· 572 576 573 577 SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size) 574 578 { 575 - int fput_needed; 576 - struct file *f; 579 + struct fd f = fdget(fd); 577 580 ssize_t error = -EBADF; 578 581 579 - f = fget_light(fd, &fput_needed); 580 - if (!f) 582 + if (!f.file) 581 583 return error; 582 - audit_inode(NULL, f->f_path.dentry); 583 - error = listxattr(f->f_path.dentry, list, size); 584 - fput_light(f, fput_needed); 584 + audit_inode(NULL, f.file->f_path.dentry); 585 + error = listxattr(f.file->f_path.dentry, list, size); 586 + fdput(f); 585 587 return error; 586 588 } 587 589 ··· 639 645 640 646 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) 641 647 { 642 - int fput_needed; 643 - struct file *f; 648 + struct fd f = fdget(fd); 644 649 struct dentry *dentry; 645 650 int error = -EBADF; 646 651 647 - f = fget_light(fd, &fput_needed); 648 - if (!f) 652 + if (!f.file) 649 653 return error; 650 - dentry = f->f_path.dentry; 654 + dentry = f.file->f_path.dentry; 651 655 audit_inode(NULL, dentry); 652 - error = mnt_want_write_file(f); 656 + error = mnt_want_write_file(f.file); 653 657 if (!error) { 654 658 error = removexattr(dentry, name); 655 - mnt_drop_write_file(f); 659 + mnt_drop_write_file(f.file); 656 660 } 657 - fput_light(f, fput_needed); 661 + fdput(f); 658 662 return error; 659 663 } 660 664
+18 -18
fs/xfs/xfs_dfrag.c
··· 48 48 xfs_swapext_t *sxp) 49 49 { 50 50 xfs_inode_t *ip, *tip; 51 - struct file *file, *tmp_file; 52 - int error = 0, fput_needed, fput_needed_tmp; 51 + struct fd f, tmp; 52 + int error = 0; 53 53 54 54 /* Pull information for the target fd */ 55 - file = fget_light((int)sxp->sx_fdtarget, &fput_needed); 56 - if (!file) { 55 + f = fdget((int)sxp->sx_fdtarget); 56 + if (!f.file) { 57 57 error = XFS_ERROR(EINVAL); 58 58 goto out; 59 59 } 60 60 61 - if (!(file->f_mode & FMODE_WRITE) || 62 - !(file->f_mode & FMODE_READ) || 63 - (file->f_flags & O_APPEND)) { 61 + if (!(f.file->f_mode & FMODE_WRITE) || 62 + !(f.file->f_mode & FMODE_READ) || 63 + (f.file->f_flags & O_APPEND)) { 64 64 error = XFS_ERROR(EBADF); 65 65 goto out_put_file; 66 66 } 67 67 68 - tmp_file = fget_light((int)sxp->sx_fdtmp, &fput_needed_tmp); 69 - if (!tmp_file) { 68 + tmp = fdget((int)sxp->sx_fdtmp); 69 + if (!tmp.file) { 70 70 error = XFS_ERROR(EINVAL); 71 71 goto out_put_file; 72 72 } 73 73 74 - if (!(tmp_file->f_mode & FMODE_WRITE) || 75 - !(tmp_file->f_mode & FMODE_READ) || 76 - (tmp_file->f_flags & O_APPEND)) { 74 + if (!(tmp.file->f_mode & FMODE_WRITE) || 75 + !(tmp.file->f_mode & FMODE_READ) || 76 + (tmp.file->f_flags & O_APPEND)) { 77 77 error = XFS_ERROR(EBADF); 78 78 goto out_put_tmp_file; 79 79 } 80 80 81 - if (IS_SWAPFILE(file->f_path.dentry->d_inode) || 82 - IS_SWAPFILE(tmp_file->f_path.dentry->d_inode)) { 81 + if (IS_SWAPFILE(f.file->f_path.dentry->d_inode) || 82 + IS_SWAPFILE(tmp.file->f_path.dentry->d_inode)) { 83 83 error = XFS_ERROR(EINVAL); 84 84 goto out_put_tmp_file; 85 85 } 86 86 87 - ip = XFS_I(file->f_path.dentry->d_inode); 88 - tip = XFS_I(tmp_file->f_path.dentry->d_inode); 87 + ip = XFS_I(f.file->f_path.dentry->d_inode); 88 + tip = XFS_I(tmp.file->f_path.dentry->d_inode); 89 89 90 90 if (ip->i_mount != tip->i_mount) { 91 91 error = XFS_ERROR(EINVAL); ··· 105 105 error = xfs_swap_extents(ip, tip, sxp); 106 106 107 107 out_put_tmp_file: 108 - fput_light(tmp_file, fput_needed_tmp); 108 + fdput(tmp); 109 109 out_put_file: 110 - fput_light(file, fput_needed); 110 + fdput(f); 111 111 out: 112 112 return error; 113 113 }
+6 -6
fs/xfs/xfs_ioctl.c
··· 70 70 int hsize; 71 71 xfs_handle_t handle; 72 72 struct inode *inode; 73 - struct file *file = NULL; 73 + struct fd f; 74 74 struct path path; 75 - int error, fput_needed; 75 + int error; 76 76 struct xfs_inode *ip; 77 77 78 78 if (cmd == XFS_IOC_FD_TO_HANDLE) { 79 - file = fget_light(hreq->fd, &fput_needed); 80 - if (!file) 79 + f = fdget(hreq->fd); 80 + if (!f.file) 81 81 return -EBADF; 82 - inode = file->f_path.dentry->d_inode; 82 + inode = f.file->f_path.dentry->d_inode; 83 83 } else { 84 84 error = user_lpath((const char __user *)hreq->path, &path); 85 85 if (error) ··· 134 134 135 135 out_put: 136 136 if (cmd == XFS_IOC_FD_TO_HANDLE) 137 - fput_light(file, fput_needed); 137 + fdput(f); 138 138 else 139 139 path_put(&path); 140 140 return error;
+3 -2
include/linux/file.h
··· 47 47 return (struct fd){f,b}; 48 48 } 49 49 50 + extern struct file *fget_raw(unsigned int fd); 51 + extern struct file *fget_raw_light(unsigned int fd, int *fput_needed); 52 + 50 53 static inline struct fd fdget_raw(unsigned int fd) 51 54 { 52 55 int b; ··· 57 54 return (struct fd){f,b}; 58 55 } 59 56 60 - extern struct file *fget_raw(unsigned int fd); 61 - extern struct file *fget_raw_light(unsigned int fd, int *fput_needed); 62 57 extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); 63 58 extern int replace_fd(unsigned fd, struct file *file, unsigned flags); 64 59 extern void set_close_on_exec(unsigned int fd, int flag);
+41 -43
ipc/mqueue.c
··· 944 944 size_t, msg_len, unsigned int, msg_prio, 945 945 const struct timespec __user *, u_abs_timeout) 946 946 { 947 - struct file *filp; 947 + struct fd f; 948 948 struct inode *inode; 949 949 struct ext_wait_queue wait; 950 950 struct ext_wait_queue *receiver; ··· 953 953 ktime_t expires, *timeout = NULL; 954 954 struct timespec ts; 955 955 struct posix_msg_tree_node *new_leaf = NULL; 956 - int ret = 0, fput_needed; 956 + int ret = 0; 957 957 958 958 if (u_abs_timeout) { 959 959 int res = prepare_timeout(u_abs_timeout, &expires, &ts); ··· 967 967 968 968 audit_mq_sendrecv(mqdes, msg_len, msg_prio, timeout ? &ts : NULL); 969 969 970 - filp = fget_light(mqdes, &fput_needed); 971 - if (unlikely(!filp)) { 970 + f = fdget(mqdes); 971 + if (unlikely(!f.file)) { 972 972 ret = -EBADF; 973 973 goto out; 974 974 } 975 975 976 - inode = filp->f_path.dentry->d_inode; 977 - if (unlikely(filp->f_op != &mqueue_file_operations)) { 976 + inode = f.file->f_path.dentry->d_inode; 977 + if (unlikely(f.file->f_op != &mqueue_file_operations)) { 978 978 ret = -EBADF; 979 979 goto out_fput; 980 980 } 981 981 info = MQUEUE_I(inode); 982 - audit_inode(NULL, filp->f_path.dentry); 982 + audit_inode(NULL, f.file->f_path.dentry); 983 983 984 - if (unlikely(!(filp->f_mode & FMODE_WRITE))) { 984 + if (unlikely(!(f.file->f_mode & FMODE_WRITE))) { 985 985 ret = -EBADF; 986 986 goto out_fput; 987 987 } ··· 1023 1023 } 1024 1024 1025 1025 if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) { 1026 - if (filp->f_flags & O_NONBLOCK) { 1026 + if (f.file->f_flags & O_NONBLOCK) { 1027 1027 ret = -EAGAIN; 1028 1028 } else { 1029 1029 wait.task = current; ··· 1056 1056 if (ret) 1057 1057 free_msg(msg_ptr); 1058 1058 out_fput: 1059 - fput_light(filp, fput_needed); 1059 + fdput(f); 1060 1060 out: 1061 1061 return ret; 1062 1062 } ··· 1067 1067 { 1068 1068 ssize_t ret; 1069 1069 struct msg_msg *msg_ptr; 1070 - struct file *filp; 1070 + struct fd f; 1071 1071 struct inode *inode; 1072 1072 struct mqueue_inode_info *info; 1073 1073 struct ext_wait_queue wait; 1074 1074 ktime_t expires, *timeout = NULL; 1075 1075 struct timespec ts; 1076 1076 struct posix_msg_tree_node *new_leaf = NULL; 1077 - int fput_needed; 1078 1077 1079 1078 if (u_abs_timeout) { 1080 1079 int res = prepare_timeout(u_abs_timeout, &expires, &ts); ··· 1084 1085 1085 1086 audit_mq_sendrecv(mqdes, msg_len, 0, timeout ? &ts : NULL); 1086 1087 1087 - filp = fget_light(mqdes, &fput_needed); 1088 - if (unlikely(!filp)) { 1088 + f = fdget(mqdes); 1089 + if (unlikely(!f.file)) { 1089 1090 ret = -EBADF; 1090 1091 goto out; 1091 1092 } 1092 1093 1093 - inode = filp->f_path.dentry->d_inode; 1094 - if (unlikely(filp->f_op != &mqueue_file_operations)) { 1094 + inode = f.file->f_path.dentry->d_inode; 1095 + if (unlikely(f.file->f_op != &mqueue_file_operations)) { 1095 1096 ret = -EBADF; 1096 1097 goto out_fput; 1097 1098 } 1098 1099 info = MQUEUE_I(inode); 1099 - audit_inode(NULL, filp->f_path.dentry); 1100 + audit_inode(NULL, f.file->f_path.dentry); 1100 1101 1101 - if (unlikely(!(filp->f_mode & FMODE_READ))) { 1102 + if (unlikely(!(f.file->f_mode & FMODE_READ))) { 1102 1103 ret = -EBADF; 1103 1104 goto out_fput; 1104 1105 } ··· 1130 1131 } 1131 1132 1132 1133 if (info->attr.mq_curmsgs == 0) { 1133 - if (filp->f_flags & O_NONBLOCK) { 1134 + if (f.file->f_flags & O_NONBLOCK) { 1134 1135 spin_unlock(&info->lock); 1135 1136 ret = -EAGAIN; 1136 1137 } else { ··· 1160 1161 free_msg(msg_ptr); 1161 1162 } 1162 1163 out_fput: 1163 - fput_light(filp, fput_needed); 1164 + fdput(f); 1164 1165 out: 1165 1166 return ret; 1166 1167 } ··· 1173 1174 SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes, 1174 1175 const struct sigevent __user *, u_notification) 1175 1176 { 1176 - int ret, fput_needed; 1177 - struct file *filp; 1177 + int ret; 1178 + struct fd f; 1178 1179 struct sock *sock; 1179 1180 struct inode *inode; 1180 1181 struct sigevent notification; ··· 1220 1221 skb_put(nc, NOTIFY_COOKIE_LEN); 1221 1222 /* and attach it to the socket */ 1222 1223 retry: 1223 - filp = fget_light(notification.sigev_signo, &fput_needed); 1224 - if (!filp) { 1224 + f = fdget(notification.sigev_signo); 1225 + if (!f.file) { 1225 1226 ret = -EBADF; 1226 1227 goto out; 1227 1228 } 1228 - sock = netlink_getsockbyfilp(filp); 1229 - fput_light(filp, fput_needed); 1229 + sock = netlink_getsockbyfilp(f.file); 1230 + fdput(f); 1230 1231 if (IS_ERR(sock)) { 1231 1232 ret = PTR_ERR(sock); 1232 1233 sock = NULL; ··· 1245 1246 } 1246 1247 } 1247 1248 1248 - filp = fget_light(mqdes, &fput_needed); 1249 - if (!filp) { 1249 + f = fdget(mqdes); 1250 + if (!f.file) { 1250 1251 ret = -EBADF; 1251 1252 goto out; 1252 1253 } 1253 1254 1254 - inode = filp->f_path.dentry->d_inode; 1255 - if (unlikely(filp->f_op != &mqueue_file_operations)) { 1255 + inode = f.file->f_path.dentry->d_inode; 1256 + if (unlikely(f.file->f_op != &mqueue_file_operations)) { 1256 1257 ret = -EBADF; 1257 1258 goto out_fput; 1258 1259 } ··· 1292 1293 } 1293 1294 spin_unlock(&info->lock); 1294 1295 out_fput: 1295 - fput_light(filp, fput_needed); 1296 + fdput(f); 1296 1297 out: 1297 1298 if (sock) { 1298 1299 netlink_detachskb(sock, nc); ··· 1308 1309 { 1309 1310 int ret; 1310 1311 struct mq_attr mqstat, omqstat; 1311 - int fput_needed; 1312 - struct file *filp; 1312 + struct fd f; 1313 1313 struct inode *inode; 1314 1314 struct mqueue_inode_info *info; 1315 1315 ··· 1319 1321 return -EINVAL; 1320 1322 } 1321 1323 1322 - filp = fget_light(mqdes, &fput_needed); 1323 - if (!filp) { 1324 + f = fdget(mqdes); 1325 + if (!f.file) { 1324 1326 ret = -EBADF; 1325 1327 goto out; 1326 1328 } 1327 1329 1328 - inode = filp->f_path.dentry->d_inode; 1329 - if (unlikely(filp->f_op != &mqueue_file_operations)) { 1330 + inode = f.file->f_path.dentry->d_inode; 1331 + if (unlikely(f.file->f_op != &mqueue_file_operations)) { 1330 1332 ret = -EBADF; 1331 1333 goto out_fput; 1332 1334 } ··· 1335 1337 spin_lock(&info->lock); 1336 1338 1337 1339 omqstat = info->attr; 1338 - omqstat.mq_flags = filp->f_flags & O_NONBLOCK; 1340 + omqstat.mq_flags = f.file->f_flags & O_NONBLOCK; 1339 1341 if (u_mqstat) { 1340 1342 audit_mq_getsetattr(mqdes, &mqstat); 1341 - spin_lock(&filp->f_lock); 1343 + spin_lock(&f.file->f_lock); 1342 1344 if (mqstat.mq_flags & O_NONBLOCK) 1343 - filp->f_flags |= O_NONBLOCK; 1345 + f.file->f_flags |= O_NONBLOCK; 1344 1346 else 1345 - filp->f_flags &= ~O_NONBLOCK; 1346 - spin_unlock(&filp->f_lock); 1347 + f.file->f_flags &= ~O_NONBLOCK; 1348 + spin_unlock(&f.file->f_lock); 1347 1349 1348 1350 inode->i_atime = inode->i_ctime = CURRENT_TIME; 1349 1351 } ··· 1356 1358 ret = -EFAULT; 1357 1359 1358 1360 out_fput: 1359 - fput_light(filp, fput_needed); 1361 + fdput(f); 1360 1362 out: 1361 1363 return ret; 1362 1364 }
+30 -40
kernel/events/core.c
··· 467 467 { 468 468 struct perf_cgroup *cgrp; 469 469 struct cgroup_subsys_state *css; 470 - struct file *file; 471 - int ret = 0, fput_needed; 470 + struct fd f = fdget(fd); 471 + int ret = 0; 472 472 473 - file = fget_light(fd, &fput_needed); 474 - if (!file) 473 + if (!f.file) 475 474 return -EBADF; 476 475 477 - css = cgroup_css_from_dir(file, perf_subsys_id); 476 + css = cgroup_css_from_dir(f.file, perf_subsys_id); 478 477 if (IS_ERR(css)) { 479 478 ret = PTR_ERR(css); 480 479 goto out; ··· 499 500 ret = -EINVAL; 500 501 } 501 502 out: 502 - fput_light(file, fput_needed); 503 + fdput(f); 503 504 return ret; 504 505 } 505 506 ··· 3232 3233 3233 3234 static const struct file_operations perf_fops; 3234 3235 3235 - static struct file *perf_fget_light(int fd, int *fput_needed) 3236 + static inline int perf_fget_light(int fd, struct fd *p) 3236 3237 { 3237 - struct file *file; 3238 + struct fd f = fdget(fd); 3239 + if (!f.file) 3240 + return -EBADF; 3238 3241 3239 - file = fget_light(fd, fput_needed); 3240 - if (!file) 3241 - return ERR_PTR(-EBADF); 3242 - 3243 - if (file->f_op != &perf_fops) { 3244 - fput_light(file, *fput_needed); 3245 - *fput_needed = 0; 3246 - return ERR_PTR(-EBADF); 3242 + if (f.file->f_op != &perf_fops) { 3243 + fdput(f); 3244 + return -EBADF; 3247 3245 } 3248 - 3249 - return file; 3246 + *p = f; 3247 + return 0; 3250 3248 } 3251 3249 3252 3250 static int perf_event_set_output(struct perf_event *event, ··· 3275 3279 3276 3280 case PERF_EVENT_IOC_SET_OUTPUT: 3277 3281 { 3278 - struct file *output_file = NULL; 3279 - struct perf_event *output_event = NULL; 3280 - int fput_needed = 0; 3281 3282 int ret; 3282 - 3283 3283 if (arg != -1) { 3284 - output_file = perf_fget_light(arg, &fput_needed); 3285 - if (IS_ERR(output_file)) 3286 - return PTR_ERR(output_file); 3287 - output_event = output_file->private_data; 3284 + struct perf_event *output_event; 3285 + struct fd output; 3286 + ret = perf_fget_light(arg, &output); 3287 + if (ret) 3288 + return ret; 3289 + output_event = output.file->private_data; 3290 + ret = perf_event_set_output(event, output_event); 3291 + fdput(output); 3292 + } else { 3293 + ret = perf_event_set_output(event, NULL); 3288 3294 } 3289 - 3290 - ret = perf_event_set_output(event, output_event); 3291 - if (output_event) 3292 - fput_light(output_file, fput_needed); 3293 - 3294 3295 return ret; 3295 3296 } 3296 3297 ··· 6222 6229 struct perf_event_attr attr; 6223 6230 struct perf_event_context *ctx; 6224 6231 struct file *event_file = NULL; 6225 - struct file *group_file = NULL; 6232 + struct fd group = {NULL, 0}; 6226 6233 struct task_struct *task = NULL; 6227 6234 struct pmu *pmu; 6228 6235 int event_fd; 6229 6236 int move_group = 0; 6230 - int fput_needed = 0; 6231 6237 int err; 6232 6238 6233 6239 /* for future expandability... */ ··· 6261 6269 return event_fd; 6262 6270 6263 6271 if (group_fd != -1) { 6264 - group_file = perf_fget_light(group_fd, &fput_needed); 6265 - if (IS_ERR(group_file)) { 6266 - err = PTR_ERR(group_file); 6272 + err = perf_fget_light(group_fd, &group); 6273 + if (err) 6267 6274 goto err_fd; 6268 - } 6269 - group_leader = group_file->private_data; 6275 + group_leader = group.file->private_data; 6270 6276 if (flags & PERF_FLAG_FD_OUTPUT) 6271 6277 output_event = group_leader; 6272 6278 if (flags & PERF_FLAG_FD_NO_GROUP) ··· 6440 6450 * of the group leader will find the pointer to itself in 6441 6451 * perf_group_detach(). 6442 6452 */ 6443 - fput_light(group_file, fput_needed); 6453 + fdput(group); 6444 6454 fd_install(event_fd, event_file); 6445 6455 return event_fd; 6446 6456 ··· 6454 6464 if (task) 6455 6465 put_task_struct(task); 6456 6466 err_group_fd: 6457 - fput_light(group_file, fput_needed); 6467 + fdput(group); 6458 6468 err_fd: 6459 6469 put_unused_fd(event_fd); 6460 6470 return err;
+8 -8
kernel/sys.c
··· 1788 1788 #ifdef CONFIG_CHECKPOINT_RESTORE 1789 1789 static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) 1790 1790 { 1791 - struct file *exe_file; 1791 + struct fd exe; 1792 1792 struct dentry *dentry; 1793 - int err, fput_needed; 1793 + int err; 1794 1794 1795 - exe_file = fget_light(fd, &fput_needed); 1796 - if (!exe_file) 1795 + exe = fdget(fd); 1796 + if (!exe.file) 1797 1797 return -EBADF; 1798 1798 1799 - dentry = exe_file->f_path.dentry; 1799 + dentry = exe.file->f_path.dentry; 1800 1800 1801 1801 /* 1802 1802 * Because the original mm->exe_file points to executable file, make ··· 1805 1805 */ 1806 1806 err = -EACCES; 1807 1807 if (!S_ISREG(dentry->d_inode->i_mode) || 1808 - exe_file->f_path.mnt->mnt_flags & MNT_NOEXEC) 1808 + exe.file->f_path.mnt->mnt_flags & MNT_NOEXEC) 1809 1809 goto exit; 1810 1810 1811 1811 err = inode_permission(dentry->d_inode, MAY_EXEC); ··· 1839 1839 goto exit_unlock; 1840 1840 1841 1841 err = 0; 1842 - set_mm_exe_file(mm, exe_file); /* this grabs a reference to exe_file */ 1842 + set_mm_exe_file(mm, exe.file); /* this grabs a reference to exe.file */ 1843 1843 exit_unlock: 1844 1844 up_write(&mm->mmap_sem); 1845 1845 1846 1846 exit: 1847 - fput_light(exe_file, fput_needed); 1847 + fdput(exe); 1848 1848 return err; 1849 1849 } 1850 1850
+5 -6
kernel/taskstats.c
··· 415 415 struct nlattr *na; 416 416 size_t size; 417 417 u32 fd; 418 - struct file *file; 419 - int fput_needed; 418 + struct fd f; 420 419 421 420 na = info->attrs[CGROUPSTATS_CMD_ATTR_FD]; 422 421 if (!na) 423 422 return -EINVAL; 424 423 425 424 fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]); 426 - file = fget_light(fd, &fput_needed); 427 - if (!file) 425 + f = fdget(fd); 426 + if (!f.file) 428 427 return 0; 429 428 430 429 size = nla_total_size(sizeof(struct cgroupstats)); ··· 443 444 stats = nla_data(na); 444 445 memset(stats, 0, sizeof(*stats)); 445 446 446 - rc = cgroupstats_build(stats, file->f_dentry); 447 + rc = cgroupstats_build(stats, f.file->f_dentry); 447 448 if (rc < 0) { 448 449 nlmsg_free(rep_skb); 449 450 goto err; ··· 452 453 rc = send_reply(rep_skb, info); 453 454 454 455 err: 455 - fput_light(file, fput_needed); 456 + fdput(f); 456 457 return rc; 457 458 } 458 459
+17 -18
mm/fadvise.c
··· 26 26 */ 27 27 SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice) 28 28 { 29 - int fput_needed; 30 - struct file *file = fget_light(fd, &fput_needed); 29 + struct fd f = fdget(fd); 31 30 struct address_space *mapping; 32 31 struct backing_dev_info *bdi; 33 32 loff_t endbyte; /* inclusive */ ··· 35 36 unsigned long nrpages; 36 37 int ret = 0; 37 38 38 - if (!file) 39 + if (!f.file) 39 40 return -EBADF; 40 41 41 - if (S_ISFIFO(file->f_path.dentry->d_inode->i_mode)) { 42 + if (S_ISFIFO(f.file->f_path.dentry->d_inode->i_mode)) { 42 43 ret = -ESPIPE; 43 44 goto out; 44 45 } 45 46 46 - mapping = file->f_mapping; 47 + mapping = f.file->f_mapping; 47 48 if (!mapping || len < 0) { 48 49 ret = -EINVAL; 49 50 goto out; ··· 76 77 77 78 switch (advice) { 78 79 case POSIX_FADV_NORMAL: 79 - file->f_ra.ra_pages = bdi->ra_pages; 80 - spin_lock(&file->f_lock); 81 - file->f_mode &= ~FMODE_RANDOM; 82 - spin_unlock(&file->f_lock); 80 + f.file->f_ra.ra_pages = bdi->ra_pages; 81 + spin_lock(&f.file->f_lock); 82 + f.file->f_mode &= ~FMODE_RANDOM; 83 + spin_unlock(&f.file->f_lock); 83 84 break; 84 85 case POSIX_FADV_RANDOM: 85 - spin_lock(&file->f_lock); 86 - file->f_mode |= FMODE_RANDOM; 87 - spin_unlock(&file->f_lock); 86 + spin_lock(&f.file->f_lock); 87 + f.file->f_mode |= FMODE_RANDOM; 88 + spin_unlock(&f.file->f_lock); 88 89 break; 89 90 case POSIX_FADV_SEQUENTIAL: 90 - file->f_ra.ra_pages = bdi->ra_pages * 2; 91 - spin_lock(&file->f_lock); 92 - file->f_mode &= ~FMODE_RANDOM; 93 - spin_unlock(&file->f_lock); 91 + f.file->f_ra.ra_pages = bdi->ra_pages * 2; 92 + spin_lock(&f.file->f_lock); 93 + f.file->f_mode &= ~FMODE_RANDOM; 94 + spin_unlock(&f.file->f_lock); 94 95 break; 95 96 case POSIX_FADV_WILLNEED: 96 97 /* First and last PARTIAL page! */ ··· 106 107 * Ignore return value because fadvise() shall return 107 108 * success even if filesystem can't retrieve a hint, 108 109 */ 109 - force_page_cache_readahead(mapping, file, start_index, 110 + force_page_cache_readahead(mapping, f.file, start_index, 110 111 nrpages); 111 112 break; 112 113 case POSIX_FADV_NOREUSE: ··· 128 129 ret = -EINVAL; 129 130 } 130 131 out: 131 - fput_light(file, fput_needed); 132 + fdput(f); 132 133 return ret; 133 134 } 134 135 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
+7 -8
mm/readahead.c
··· 579 579 SYSCALL_DEFINE(readahead)(int fd, loff_t offset, size_t count) 580 580 { 581 581 ssize_t ret; 582 - struct file *file; 583 - int fput_needed; 582 + struct fd f; 584 583 585 584 ret = -EBADF; 586 - file = fget_light(fd, &fput_needed); 587 - if (file) { 588 - if (file->f_mode & FMODE_READ) { 589 - struct address_space *mapping = file->f_mapping; 585 + f = fdget(fd); 586 + if (f.file) { 587 + if (f.file->f_mode & FMODE_READ) { 588 + struct address_space *mapping = f.file->f_mapping; 590 589 pgoff_t start = offset >> PAGE_CACHE_SHIFT; 591 590 pgoff_t end = (offset + count - 1) >> PAGE_CACHE_SHIFT; 592 591 unsigned long len = end - start + 1; 593 - ret = do_readahead(mapping, file, start, len); 592 + ret = do_readahead(mapping, f.file, start, len); 594 593 } 595 - fput_light(file, fput_needed); 594 + fdput(f); 596 595 } 597 596 return ret; 598 597 }