Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

switch simple cases of fget_light to fdget

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information...
commit 2903ff019b346ab8d36ebbf54853c3aaf6590608 1 parent a5b470b
authored August 28, 2012

Showing 44 changed files with 633 additions and 763 deletions. Show diff stats Hide diff stats

  1. 15  arch/alpha/kernel/osf_sys.c
  2. 15  arch/ia64/kernel/perfmon.c
  3. 17  arch/parisc/hpux/fs.c
  4. 21  arch/powerpc/platforms/cell/spu_syscalls.c
  5. 12  drivers/infiniband/core/ucma.c
  6. 18  drivers/infiniband/core/uverbs_cmd.c
  7. 12  drivers/infiniband/core/uverbs_main.c
  8. 17  drivers/vfio/vfio.c
  9. 12  drivers/video/msm/mdp.c
  10. 26  fs/btrfs/ioctl.c
  11. 14  fs/coda/inode.c
  12. 90  fs/compat.c
  13. 27  fs/compat_ioctl.c
  14. 25  fs/eventpoll.c
  15. 14  fs/ext4/ioctl.c
  16. 32  fs/fcntl.c
  17. 17  fs/fhandle.c
  18. 25  fs/ioctl.c
  19. 20  fs/locks.c
  20. 39  fs/namei.c
  21. 28  fs/notify/fanotify/fanotify_user.c
  22. 28  fs/notify/inotify/inotify_user.c
  23. 39  fs/ocfs2/cluster/heartbeat.c
  24. 64  fs/open.c
  25. 176  fs/read_write.c
  26. 36  fs/readdir.c
  27. 28  fs/select.c
  28. 13  fs/signalfd.c
  29. 69  fs/splice.c
  30. 10  fs/stat.c
  31. 9  fs/statfs.c
  32. 33  fs/sync.c
  33. 48  fs/timerfd.c
  34. 11  fs/utimes.c
  35. 52  fs/xattr.c
  36. 36  fs/xfs/xfs_dfrag.c
  37. 12  fs/xfs/xfs_ioctl.c
  38. 5  include/linux/file.h
  39. 84  ipc/mqueue.c
  40. 70  kernel/events/core.c
  41. 16  kernel/sys.c
  42. 11  kernel/taskstats.c
  43. 35  mm/fadvise.c
  44. 15  mm/readahead.c
15  arch/alpha/kernel/osf_sys.c
@@ -144,28 +144,25 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
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
 
15  arch/ia64/kernel/perfmon.c
@@ -4780,7 +4780,7 @@ pfm_check_task_state(pfm_context_t *ctx, int cmd, unsigned long flags)
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,7 +4789,6 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
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
 	/*
@@ -4878,17 +4877,17 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
4878 4877
 
4879 4878
 	ret = -EBADF;
4880 4879
 
4881  
-	file = fget_light(fd, &fput_needed);
4882  
-	if (unlikely(file == NULL)) {
  4880
+	f = fdget(fd);
  4881
+	if (unlikely(f.file == NULL)) {
4883 4882
 		DPRINT(("invalid fd %d\n", fd));
4884 4883
 		goto error_args;
4885 4884
 	}
4886  
-	if (unlikely(PFM_IS_FILE(file) == 0)) {
  4885
+	if (unlikely(PFM_IS_FILE(f.file) == 0)) {
4887 4886
 		DPRINT(("fd %d not related to perfmon\n", fd));
4888 4887
 		goto error_args;
4889 4888
 	}
4890 4889
 
4891  
-	ctx = file->private_data;
  4890
+	ctx = f.file->private_data;
4892 4891
 	if (unlikely(ctx == NULL)) {
4893 4892
 		DPRINT(("no context for fd %d\n", fd));
4894 4893
 		goto error_args;
@@ -4918,8 +4917,8 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
4918 4917
 	if (call_made && PFM_CMD_RW_ARG(cmd) && copy_to_user(arg, args_k, base_sz*count)) ret = -EFAULT;
4919 4918
 
4920 4919
 error_args:
4921  
-	if (file)
4922  
-		fput_light(file, fput_needed);
  4920
+	if (f.file)
  4921
+		fdput(f);
4923 4922
 
4924 4923
 	kfree(args_k);
4925 4924
 
17  arch/parisc/hpux/fs.c
@@ -109,33 +109,32 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
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
 
21  arch/powerpc/platforms/cell/spu_syscalls.c
@@ -69,8 +69,6 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
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();
@@ -78,11 +76,11 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
78 76
 		return -ENOSYS;
79 77
 
80 78
 	if (flags & SPU_CREATE_AFFINITY_SPU) {
  79
+		struct fd neighbor = fdget(neighbor_fd);
81 80
 		ret = -EBADF;
82  
-		neighbor = fget_light(neighbor_fd, &fput_needed);
83  
-		if (neighbor) {
84  
-			ret = calls->create_thread(name, flags, mode, neighbor);
85  
-			fput_light(neighbor, fput_needed);
  81
+		if (neighbor.file) {
  82
+			ret = calls->create_thread(name, flags, mode, neighbor.file);
  83
+			fdput(neighbor);
86 84
 		}
87 85
 	} else
88 86
 		ret = calls->create_thread(name, flags, mode, NULL);
@@ -94,8 +92,7 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
94 92
 asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
95 93
 {
96 94
 	long ret;
97  
-	struct file *filp;
98  
-	int fput_needed;
  95
+	struct fd arg;
99 96
 	struct spufs_calls *calls;
100 97
 
101 98
 	calls = spufs_calls_get();
@@ -103,10 +100,10 @@ asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
103 100
 		return -ENOSYS;
104 101
 
105 102
 	ret = -EBADF;
106  
-	filp = fget_light(fd, &fput_needed);
107  
-	if (filp) {
108  
-		ret = calls->spu_run(filp, unpc, ustatus);
109  
-		fput_light(filp, fput_needed);
  103
+	arg = fdget(fd);
  104
+	if (arg.file) {
  105
+		ret = calls->spu_run(arg.file, unpc, ustatus);
  106
+		fdput(arg);
110 107
 	}
111 108
 
112 109
 	spufs_calls_put(calls);
12  drivers/infiniband/core/ucma.c
@@ -1184,20 +1184,20 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
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,7 +1231,7 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
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
 
18  drivers/infiniband/core/uverbs_cmd.c
@@ -705,9 +705,9 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
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,13 +724,13 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
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,8 +795,8 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
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,8 +825,8 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
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
 
12  drivers/infiniband/core/uverbs_main.c
@@ -541,17 +541,15 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
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;
@@ -560,7 +558,7 @@ struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd)
560 558
 	kref_get(&ev_file->ref);
561 559
 
562 560
 out:
563  
-	fput_light(filp, fput_needed);
  561
+	fdput(f);
564 562
 	return ev_file;
565 563
 }
566 564
 
17  drivers/vfio/vfio.c
@@ -1014,25 +1014,25 @@ static void vfio_group_try_dissolve_container(struct vfio_group *group)
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,8 +1054,7 @@ static int vfio_group_set_container(struct vfio_group *group, int container_fd)
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
 
12  drivers/video/msm/mdp.c
@@ -257,19 +257,17 @@ int get_img(struct mdp_img *img, struct fb_info *info,
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
 }
26  fs/btrfs/ioctl.c
@@ -1397,7 +1397,6 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file,
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
 
@@ -1421,15 +1420,14 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file,
1421 1420
 		ret = btrfs_mksubvol(&file->f_path, name, namelen,
1422 1421
 				     NULL, transid, readonly, inherit);
1423 1422
 	} else {
  1423
+		struct fd src = fdget(fd);
1424 1424
 		struct inode *src_inode;
1425  
-		int fput_needed;
1426  
-		src_file = fget_light(fd, &fput_needed);
1427  
-		if (!src_file) {
  1425
+		if (!src.file) {
1428 1426
 			ret = -EINVAL;
1429 1427
 			goto out_drop_write;
1430 1428
 		}
1431 1429
 
1432  
-		src_inode = src_file->f_path.dentry->d_inode;
  1430
+		src_inode = src.file->f_path.dentry->d_inode;
1433 1431
 		if (src_inode->i_sb != file->f_path.dentry->d_inode->i_sb) {
1434 1432
 			printk(KERN_INFO "btrfs: Snapshot src from "
1435 1433
 			       "another FS\n");
@@ -1439,7 +1437,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file,
1439 1437
 					     BTRFS_I(src_inode)->root,
1440 1438
 					     transid, readonly, inherit);
1441 1439
 		}
1442  
-		fput_light(src_file, fput_needed);
  1440
+		fdput(src);
1443 1441
 	}
1444 1442
 out_drop_write:
1445 1443
 	mnt_drop_write_file(file);
@@ -2341,7 +2339,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2341 2339
 {
2342 2340
 	struct inode *inode = fdentry(file)->d_inode;
2343 2341
 	struct btrfs_root *root = BTRFS_I(inode)->root;
2344  
-	struct file *src_file;
  2342
+	struct fd src_file;
2345 2343
 	struct inode *src;
2346 2344
 	struct btrfs_trans_handle *trans;
2347 2345
 	struct btrfs_path *path;
@@ -2350,7 +2348,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2350 2348
 	struct btrfs_key key;
2351 2349
 	u32 nritems;
2352 2350
 	int slot;
2353  
-	int ret, fput_needed;
  2351
+	int ret;
2354 2352
 	u64 len = olen;
2355 2353
 	u64 bs = root->fs_info->sb->s_blocksize;
2356 2354
 	u64 hint_byte;
@@ -2376,24 +2374,24 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2376 2374
 	if (ret)
2377 2375
 		return ret;
2378 2376
 
2379  
-	src_file = fget_light(srcfd, &fput_needed);
2380  
-	if (!src_file) {
  2377
+	src_file = fdget(srcfd);
  2378
+	if (!src_file.file) {
2381 2379
 		ret = -EBADF;
2382 2380
 		goto out_drop_write;
2383 2381
 	}
2384 2382
 
2385 2383
 	ret = -EXDEV;
2386  
-	if (src_file->f_path.mnt != file->f_path.mnt)
  2384
+	if (src_file.file->f_path.mnt != file->f_path.mnt)
2387 2385
 		goto out_fput;
2388 2386
 
2389  
-	src = src_file->f_dentry->d_inode;
  2387
+	src = src_file.file->f_dentry->d_inode;
2390 2388
 
2391 2389
 	ret = -EINVAL;
2392 2390
 	if (src == inode)
2393 2391
 		goto out_fput;
2394 2392
 
2395 2393
 	/* the src must be open for reading */
2396  
-	if (!(src_file->f_mode & FMODE_READ))
  2394
+	if (!(src_file.file->f_mode & FMODE_READ))
2397 2395
 		goto out_fput;
2398 2396
 
2399 2397
 	/* don't make the dst file partly checksummed */
@@ -2724,7 +2722,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2724 2722
 	vfree(buf);
2725 2723
 	btrfs_free_path(path);
2726 2724
 out_fput:
2727  
-	fput_light(src_file, fput_needed);
  2725
+	fdput(src_file);
2728 2726
 out_drop_write:
2729 2727
 	mnt_drop_write_file(file);
2730 2728
 	return ret;
14  fs/coda/inode.c
@@ -107,9 +107,9 @@ static const struct super_operations coda_super_operations =
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,17 +121,17 @@ static int get_device_index(struct coda_mount_data *data)
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");
90  fs/compat.c
@@ -870,22 +870,20 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
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
 
@@ -949,17 +947,16 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
949 947
 asmlinkage long compat_sys_getdents(unsigned int fd,
950 948
 		struct compat_linux_dirent __user *dirent, unsigned int count)
951 949
 {
952  
-	struct file * file;
  950
+	struct fd f;
953 951
 	struct compat_linux_dirent __user * lastdirent;
954 952
 	struct compat_getdents_callback buf;
955  
-	int fput_needed;
956 953
 	int error;
957 954
 
958 955
 	if (!access_ok(VERIFY_WRITE, dirent, count))
959 956
 		return -EFAULT;
960 957
 
961  
-	file = fget_light(fd, &fput_needed);
962  
-	if (!file)
  958
+	f = fdget(fd);
  959
+	if (!f.file)
963 960
 		return -EBADF;
964 961
 
965 962
 	buf.current_dir = dirent;
@@ -967,17 +964,17 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
967 964
 	buf.count = count;
968 965
 	buf.error = 0;
969 966
 
970  
-	error = vfs_readdir(file, compat_filldir, &buf);
  967
+	error = vfs_readdir(f.file, compat_filldir, &buf);
971 968
 	if (error >= 0)
972 969
 		error = buf.error;
973 970
 	lastdirent = buf.previous;
974 971
 	if (lastdirent) {
975  
-		if (put_user(file->f_pos, &lastdirent->d_off))
  972
+		if (put_user(f.file->f_pos, &lastdirent->d_off))
976 973
 			error = -EFAULT;
977 974
 		else
978 975
 			error = count - buf.count;
979 976
 	}
980  
-	fput_light(file, fput_needed);
  977
+	fdput(f);
981 978
 	return error;
982 979
 }
983 980
 
@@ -1035,17 +1032,16 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
1035 1032
 asmlinkage long compat_sys_getdents64(unsigned int fd,
1036 1033
 		struct linux_dirent64 __user * dirent, unsigned int count)
1037 1034
 {
1038  
-	struct file * file;
  1035
+	struct fd f;
1039 1036
 	struct linux_dirent64 __user * lastdirent;
1040 1037
 	struct compat_getdents_callback64 buf;
1041  
-	int fput_needed;
1042 1038
 	int error;
1043 1039
 
1044 1040
 	if (!access_ok(VERIFY_WRITE, dirent, count))
1045 1041
 		return -EFAULT;
1046 1042
 
1047  
-	file = fget_light(fd, &fput_needed);
1048  
-	if (!file)
  1043
+	f = fdget(fd);
  1044
+	if (!f.file)
1049 1045
 		return -EBADF;
1050 1046
 
1051 1047
 	buf.current_dir = dirent;
@@ -1053,18 +1049,18 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
1053 1049
 	buf.count = count;
1054 1050
 	buf.error = 0;
1055 1051
 
1056  
-	error = vfs_readdir(file, compat_filldir64, &buf);
  1052
+	error = vfs_readdir(f.file, compat_filldir64, &buf);
1057 1053
 	if (error >= 0)
1058 1054
 		error = buf.error;
1059 1055
 	lastdirent = buf.previous;
1060 1056
 	if (lastdirent) {
1061  
-		typeof(lastdirent->d_off) d_off = file->f_pos;
  1057
+		typeof(lastdirent->d_off) d_off = f.file->f_pos;
1062 1058
 		if (__put_user_unaligned(d_off, &lastdirent->d_off))
1063 1059
 			error = -EFAULT;
1064 1060
 		else
1065 1061
 			error = count - buf.count;
1066 1062
 	}
1067  
-	fput_light(file, fput_needed);
  1063
+	fdput(f);
1068 1064
 	return error;
1069 1065
 }
1070 1066
 #endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
@@ -1152,18 +1148,16 @@ asmlinkage ssize_t
1152 1148
 compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
1153 1149
 		 unsigned long vlen)
1154 1150
 {
1155  
-	struct file *file;
1156  
-	int fput_needed;
  1151
+	struct fd f = fdget(fd);
1157 1152
 	ssize_t ret;
1158 1153
 	loff_t pos;
1159 1154
 
1160  
-	file = fget_light(fd, &fput_needed);
1161  
-	if (!file)
  1155
+	if (!f.file)
1162 1156
 		return -EBADF;
1163  
-	pos = file->f_pos;
1164  
-	ret = compat_readv(file, vec, vlen, &pos);
1165  
-	file->f_pos = pos;
1166  
-	fput_light(file, fput_needed);
  1157
+	pos = f.file->f_pos;
  1158
+	ret = compat_readv(f.file, vec, vlen, &pos);
  1159
+	f.file->f_pos = pos;
  1160
+	fdput(f);
1167 1161
 	return ret;
1168 1162
 }
1169 1163
 
@@ -1171,19 +1165,18 @@ asmlinkage ssize_t
1171 1165
 compat_sys_preadv64(unsigned long fd, const struct compat_iovec __user *vec,
1172 1166
 		    unsigned long vlen, loff_t pos)
1173 1167
 {
1174  
-	struct file *file;
1175  
-	int fput_needed;
  1168
+	struct fd f;
1176 1169
 	ssize_t ret;
1177 1170
 
1178 1171
 	if (pos < 0)
1179 1172
 		return -EINVAL;
1180  
-	file = fget_light(fd, &fput_needed);
1181  
-	if (!file)
  1173
+	f = fdget(fd);
  1174
+	if (!f.file)
1182 1175
 		return -EBADF;
1183 1176
 	ret = -ESPIPE;
1184  
-	if (file->f_mode & FMODE_PREAD)
1185  
-		ret = compat_readv(file, vec, vlen, &pos);
1186  
-	fput_light(file, fput_needed);
  1177
+	if (f.file->f_mode & FMODE_PREAD)
  1178
+		ret = compat_readv(f.file, vec, vlen, &pos);
  1179
+	fdput(f);
1187 1180
 	return ret;
1188 1181
 }
1189 1182
 
@@ -1221,18 +1214,16 @@ asmlinkage ssize_t
1221 1214
 compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
1222 1215
 		  unsigned long vlen)
1223 1216
 {
1224  
-	struct file *file;
1225  
-	int fput_needed;
  1217
+	struct fd f = fdget(fd);
1226 1218
 	ssize_t ret;
1227 1219
 	loff_t pos;
1228 1220
 
1229  
-	file = fget_light(fd, &fput_needed);
1230  
-	if (!file)
  1221
+	if (!f.file)
1231 1222
 		return -EBADF;
1232  
-	pos = file->f_pos;
1233  
-	ret = compat_writev(file, vec, vlen, &pos);
1234  
-	file->f_pos = pos;
1235  
-	fput_light(file, fput_needed);
  1223
+	pos = f.file->f_pos;
  1224
+	ret = compat_writev(f.file, vec, vlen, &pos);
  1225
+	f.file->f_pos = pos;
  1226
+	fdput(f);
1236 1227
 	return ret;
1237 1228
 }
1238 1229
 
@@ -1240,19 +1231,18 @@ asmlinkage ssize_t
1240 1231
 compat_sys_pwritev64(unsigned long fd, const struct compat_iovec __user *vec,
1241 1232
 		     unsigned long vlen, loff_t pos)
1242 1233
 {
1243  
-	struct file *file;
1244  
-	int fput_needed;
  1234
+	struct fd f;
1245 1235
 	ssize_t ret;
1246 1236
 
1247 1237
 	if (pos < 0)
1248 1238
 		return -EINVAL;
1249  
-	file = fget_light(fd, &fput_needed);
1250  
-	if (!file)
  1239
+	f = fdget(fd);
  1240
+	if (!f.file)
1251 1241
 		return -EBADF;
1252 1242
 	ret = -ESPIPE;
1253  
-	if (file->f_mode & FMODE_PWRITE)
1254  
-		ret = compat_writev(file, vec, vlen, &pos);
1255  
-	fput_light(file, fput_needed);
  1243
+	if (f.file->f_mode & FMODE_PWRITE)
  1244
+		ret = compat_writev(f.file, vec, vlen, &pos);
  1245
+	fdput(f);
1256 1246
 	return ret;
1257 1247
 }
1258 1248
 
27  fs/compat_ioctl.c
@@ -1531,16 +1531,13 @@ static int compat_ioctl_check_table(unsigned int xcmd)
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
 
@@ -1560,30 +1557,30 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
1560 1557
 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
1561 1558
 	case FS_IOC_RESVSP_32:
1562 1559
 	case FS_IOC_RESVSP64_32:
1563  
-		error = compat_ioctl_preallocate(filp, compat_ptr(arg));
  1560
+		error = compat_ioctl_preallocate(f.file, compat_ptr(arg));
1564 1561
 		goto out_fput;
1565 1562
 #else
1566 1563
 	case FS_IOC_RESVSP:
1567 1564
 	case FS_IOC_RESVSP64:
1568  
-		error = ioctl_preallocate(filp, compat_ptr(arg));
  1565
+		error = ioctl_preallocate(f.file, compat_ptr(arg));
1569 1566
 		goto out_fput;
1570 1567
 #endif
1571 1568
 
1572 1569
 	case FIBMAP:
1573 1570
 	case FIGETBSZ:
1574 1571
 	case FIONREAD:
1575  
-		if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
  1572
+		if (S_ISREG(f.file->f_path.dentry->d_inode->i_mode))
1576 1573
 			break;
1577 1574
 		/*FALL THROUGH*/
1578 1575
 
1579 1576
 	default:
1580  
-		if (filp->f_op && filp->f_op->compat_ioctl) {
1581  
-			error = filp->f_op->compat_ioctl(filp, cmd, arg);
  1577
+		if (f.file->f_op && f.file->f_op->compat_ioctl) {
  1578
+			error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
1582 1579
 			if (error != -ENOIOCTLCMD)
1583 1580
 				goto out_fput;
1584 1581
 		}
1585 1582
 
1586  
-		if (!filp->f_op || !filp->f_op->unlocked_ioctl)
  1583
+		if (!f.file->f_op || !f.file->f_op->unlocked_ioctl)
1587 1584
 			goto do_ioctl;
1588 1585
 		break;
1589 1586
 	}
@@ -1591,7 +1588,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
1591 1588
 	if (compat_ioctl_check_table(XFORM(cmd)))
1592 1589
 		goto found_handler;
1593 1590
 
1594  
-	error = do_ioctl_trans(fd, cmd, arg, filp);
  1591
+	error = do_ioctl_trans(fd, cmd, arg, f.file);
1595 1592
 	if (error == -ENOIOCTLCMD)
1596 1593
 		error = -ENOTTY;
1597 1594
 
@@ -1600,9 +1597,9 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
1600 1597
  found_handler:
1601 1598
 	arg = (unsigned long)compat_ptr(arg);
1602 1599
  do_ioctl:
1603  
-	error = do_vfs_ioctl(filp, fd, cmd, arg);
  1600
+	error = do_vfs_ioctl(f.file, fd, cmd, arg);
1604 1601
  out_fput:
1605  
-	fput_light(filp, fput_needed);
  1602
+	fdput(f);
1606 1603
  out:
1607 1604
 	return error;
1608 1605
 }
25  fs/eventpoll.c
@@ -1809,8 +1809,8 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
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,38 +1818,33 @@ SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events,
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
 
14  fs/ext4/ioctl.c
@@ -233,8 +233,8 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
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,11 +245,11 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
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,7 +266,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
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,7 +274,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
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
 
32  fs/fcntl.c
@@ -348,25 +348,23 @@ static int check_fcntl_cmd(unsigned cmd)
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
 }
@@ -375,38 +373,36 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
375 373
 SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
376 374
 		unsigned long, arg)
377 375
 {	
378  
-	struct file * filp;
  376
+	struct fd f = fdget_raw(fd);
379 377
 	long err = -EBADF;
380  
-	int fput_needed;
381 378
 
382  
-	filp = fget_raw_light(fd, &fput_needed);
383  
-	if (!filp)
  379
+	if (!f.file)
384 380
 		goto out;
385 381
 
386  
-	if (unlikely(filp->f_mode & FMODE_PATH)) {
  382
+	if (unlikely(f.file->f_mode & FMODE_PATH)) {
387 383
 		if (!check_fcntl_cmd(cmd))
388 384
 			goto out1;
389 385
 	}
390 386
 
391  
-	err = security_file_fcntl(filp, cmd, arg);
  387
+	err = security_file_fcntl(f.file, cmd, arg);
392 388
 	if (err)
393 389
 		goto out1;
394 390
 	
395 391
 	switch (cmd) {
396 392
 		case F_GETLK64:
397  
-			err = fcntl_getlk64(filp, (struct flock64 __user *) arg);
  393
+			err = fcntl_getlk64(f.file, (struct flock64 __user *) arg);
398 394
 			break;
399 395
 		case F_SETLK64:
400 396
 		case F_SETLKW64:
401  
-			err = fcntl_setlk64(fd, filp, cmd,
  397
+			err = fcntl_setlk64(fd, f.file, cmd,
402 398
 					(struct flock64 __user *) arg);
403 399
 			break;
404 400
 		default:
405  
-			err = do_fcntl(fd, cmd, arg, filp);
  401
+			err = do_fcntl(fd, cmd, arg, f.file);
406 402
 			break;
407 403
 	}
408 404
 out1:
409  
-	fput_light(filp, fput_needed);
  405
+	fdput(f);
410 406
 out:
411 407
 	return err;
412 408
 }
17  fs/fhandle.c
@@ -113,24 +113,21 @@ SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name,
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)
25  fs/ioctl.c
@@ -603,21 +603,14 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
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;
609  
-
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:
  606
+	int error;
  607
+	struct fd f = fdget(fd);
  608
+
  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
 }
20  fs/locks.c
@@ -1625,15 +1625,13 @@ EXPORT_SYMBOL(flock_lock_file_wait);
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);
@@ -1641,31 +1639,31 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
1641 1639
 	unlock = (cmd == LOCK_UN);
1642 1640
 
1643 1641
 	if (!unlock && !(cmd & LOCK_MAND) &&
1644  
-	    !(filp->f_mode & (FMODE_READ|FMODE_WRITE)))
  1642
+	    !(f.file->f_mode & (FMODE_READ|FMODE_WRITE)))
1645 1643
 		goto out_putf;
1646 1644
 
1647  
-	error = flock_make_lock(filp, &lock, cmd);
  1645
+	error = flock_make_lock(f.file, &lock, cmd);
1648 1646
 	if (error)
1649 1647
 		goto out_putf;
1650 1648
 	if (can_sleep)
1651 1649
 		lock->fl_flags |= FL_SLEEP;
1652 1650
 
1653  
-	error = security_file_lock(filp, lock->fl_type);
  1651
+	error = security_file_lock(f.file, lock->fl_type);
1654 1652
 	if (error)
1655 1653
 		goto out_free;
1656 1654
 
1657  
-	if (filp->f_op && filp->f_op->flock)
1658  
-		error = filp->f_op->flock(filp,
  1655
+	if (f.file->f_op && f.file->f_op->flock)
  1656
+		error = f.file->f_op->flock(f.file,
1659 1657
 					  (can_sleep) ? F_SETLKW : F_SETLK,
1660 1658
 					  lock);
1661 1659
 	else
1662  
-		error = flock_lock_file_wait(filp, lock);
  1660
+		error = flock_lock_file_wait(f.file, lock);
1663 1661
 
1664 1662
  out_free:
1665 1663
 	locks_free_lock(lock);
1666 1664
 
1667 1665
  out_putf:
1668  
-	fput_light(filp, fput_needed);
  1666
+	fdput(f);
1669 1667
  out:
1670 1668
 	return error;
1671 1669
 }
39  fs/namei.c
@@ -1797,8 +1797,6 @@ static int path_init(int dfd, const char *name, unsigned int flags,
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;
@@ -1850,44 +1848,41 @@ static int path_init(int dfd, const char *name, unsigned int flags,
1850 1848
 			get_fs_pwd(current->fs, &nd->path);
1851 1849
 		}
1852 1850
 	} else {
  1851
+		struct fd f = fdget_raw(dfd);
1853 1852
 		struct dentry *dentry;
1854 1853
 
1855  
-		file = fget_raw_light(dfd, &fput_needed);
1856  
-		retval = -EBADF;
1857  
-		if (!file)
1858  
-			goto out_fail;
  1854
+		if (!f.file)
  1855
+			return -EBADF;
1859 1856
 
1860  
-		dentry = file->f_path.dentry;
  1857
+		dentry = f.file->f_path.dentry;
1861 1858
 
1862 1859
 		if (*name) {
1863  
-			retval = -ENOTDIR;
1864  
-			if (!S_ISDIR(dentry->d_inode->i_mode))
1865  
-				goto fput_fail;
  1860
+			if (!S_ISDIR(dentry->d_inode->i_mode)) {
  1861
+				fdput(f);