Skip to content

Commit 2903ff0

Browse files
author
Al Viro
committed
switch simple cases of fget_light to fdget
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a5b470b commit 2903ff0

44 files changed

Lines changed: 633 additions & 763 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,25 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
144144
struct osf_dirent __user *, dirent, unsigned int, count,
145145
long __user *, basep)
146146
{
147-
int error, fput_needed;
148-
struct file *file;
147+
int error;
148+
struct fd arg = fdget(fd);
149149
struct osf_dirent_callback buf;
150150

151-
error = -EBADF;
152-
file = fget_light(fd, &fput_needed);
153-
if (!file)
154-
goto out;
151+
if (!arg.file)
152+
return -EBADF;
155153

156154
buf.dirent = dirent;
157155
buf.basep = basep;
158156
buf.count = count;
159157
buf.error = 0;
160158

161-
error = vfs_readdir(file, osf_filldir, &buf);
159+
error = vfs_readdir(arg.file, osf_filldir, &buf);
162160
if (error >= 0)
163161
error = buf.error;
164162
if (count != buf.count)
165163
error = count - buf.count;
166164

167-
fput_light(file, fput_needed);
168-
out:
165+
fdput(arg);
169166
return error;
170167
}
171168

‎arch/ia64/kernel/perfmon.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,7 +4780,7 @@ pfm_check_task_state(pfm_context_t *ctx, int cmd, unsigned long flags)
47804780
asmlinkage long
47814781
sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
47824782
{
4783-
struct file *file = NULL;
4783+
struct fd f = {NULL, 0};
47844784
pfm_context_t *ctx = NULL;
47854785
unsigned long flags = 0UL;
47864786
void *args_k = NULL;
@@ -4789,7 +4789,6 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
47894789
int narg, completed_args = 0, call_made = 0, cmd_flags;
47904790
int (*func)(pfm_context_t *ctx, void *arg, int count, struct pt_regs *regs);
47914791
int (*getsize)(void *arg, size_t *sz);
4792-
int fput_needed;
47934792
#define PFM_MAX_ARGSIZE 4096
47944793

47954794
/*
@@ -4878,17 +4877,17 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
48784877

48794878
ret = -EBADF;
48804879

4881-
file = fget_light(fd, &fput_needed);
4882-
if (unlikely(file == NULL)) {
4880+
f = fdget(fd);
4881+
if (unlikely(f.file == NULL)) {
48834882
DPRINT(("invalid fd %d\n", fd));
48844883
goto error_args;
48854884
}
4886-
if (unlikely(PFM_IS_FILE(file) == 0)) {
4885+
if (unlikely(PFM_IS_FILE(f.file) == 0)) {
48874886
DPRINT(("fd %d not related to perfmon\n", fd));
48884887
goto error_args;
48894888
}
48904889

4891-
ctx = file->private_data;
4890+
ctx = f.file->private_data;
48924891
if (unlikely(ctx == NULL)) {
48934892
DPRINT(("no context for fd %d\n", fd));
48944893
goto error_args;
@@ -4918,8 +4917,8 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
49184917
if (call_made && PFM_CMD_RW_ARG(cmd) && copy_to_user(arg, args_k, base_sz*count)) ret = -EFAULT;
49194918

49204919
error_args:
4921-
if (file)
4922-
fput_light(file, fput_needed);
4920+
if (f.file)
4921+
fdput(f);
49234922

49244923
kfree(args_k);
49254924

‎arch/parisc/hpux/fs.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,32 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
109109

110110
int hpux_getdents(unsigned int fd, struct hpux_dirent __user *dirent, unsigned int count)
111111
{
112-
struct file * file;
112+
struct fd arg;
113113
struct hpux_dirent __user * lastdirent;
114114
struct getdents_callback buf;
115-
int error = -EBADF, fput_needed;
115+
int error;
116116

117-
file = fget_light(fd, &fput_needed);
118-
if (!file)
119-
goto out;
117+
arg = fdget(fd);
118+
if (!arg.file)
119+
return -EBADF;
120120

121121
buf.current_dir = dirent;
122122
buf.previous = NULL;
123123
buf.count = count;
124124
buf.error = 0;
125125

126-
error = vfs_readdir(file, filldir, &buf);
126+
error = vfs_readdir(arg.file, filldir, &buf);
127127
if (error >= 0)
128128
error = buf.error;
129129
lastdirent = buf.previous;
130130
if (lastdirent) {
131-
if (put_user(file->f_pos, &lastdirent->d_off))
131+
if (put_user(arg.file->f_pos, &lastdirent->d_off))
132132
error = -EFAULT;
133133
else
134134
error = count - buf.count;
135135
}
136136

137-
fput_light(file, fput_needed);
138-
out:
137+
fdput(arg);
139138
return error;
140139
}
141140

‎arch/powerpc/platforms/cell/spu_syscalls.c‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,18 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
6969
umode_t, mode, int, neighbor_fd)
7070
{
7171
long ret;
72-
struct file *neighbor;
73-
int fput_needed;
7472
struct spufs_calls *calls;
7573

7674
calls = spufs_calls_get();
7775
if (!calls)
7876
return -ENOSYS;
7977

8078
if (flags & SPU_CREATE_AFFINITY_SPU) {
79+
struct fd neighbor = fdget(neighbor_fd);
8180
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);
8684
}
8785
} else
8886
ret = calls->create_thread(name, flags, mode, NULL);
@@ -94,19 +92,18 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
9492
asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
9593
{
9694
long ret;
97-
struct file *filp;
98-
int fput_needed;
95+
struct fd arg;
9996
struct spufs_calls *calls;
10097

10198
calls = spufs_calls_get();
10299
if (!calls)
103100
return -ENOSYS;
104101

105102
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);
110107
}
111108

112109
spufs_calls_put(calls);

‎drivers/infiniband/core/ucma.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,20 +1184,20 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
11841184
struct rdma_ucm_migrate_id cmd;
11851185
struct rdma_ucm_migrate_resp resp;
11861186
struct ucma_context *ctx;
1187-
struct file *filp;
1187+
struct fd f;
11881188
struct ucma_file *cur_file;
1189-
int ret = 0, fput_needed;
1189+
int ret = 0;
11901190

11911191
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
11921192
return -EFAULT;
11931193

11941194
/* 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)
11971197
return -ENOENT;
11981198

11991199
/* 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);
12011201
if (IS_ERR(ctx)) {
12021202
ret = PTR_ERR(ctx);
12031203
goto file_put;
@@ -1231,7 +1231,7 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
12311231

12321232
ucma_put_ctx(ctx);
12331233
file_put:
1234-
fput_light(filp, fput_needed);
1234+
fdput(f);
12351235
return ret;
12361236
}
12371237

‎drivers/infiniband/core/uverbs_cmd.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,9 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
705705
struct ib_udata udata;
706706
struct ib_uxrcd_object *obj;
707707
struct ib_xrcd *xrcd = NULL;
708-
struct file *f = NULL;
708+
struct fd f = {NULL, 0};
709709
struct inode *inode = NULL;
710-
int ret = 0, fput_needed;
710+
int ret = 0;
711711
int new_xrcd = 0;
712712

713713
if (out_len < sizeof resp)
@@ -724,13 +724,13 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
724724

725725
if (cmd.fd != -1) {
726726
/* search for file descriptor */
727-
f = fget_light(cmd.fd, &fput_needed);
728-
if (!f) {
727+
f = fdget(cmd.fd);
728+
if (!f.file) {
729729
ret = -EBADF;
730730
goto err_tree_mutex_unlock;
731731
}
732732

733-
inode = f->f_dentry->d_inode;
733+
inode = f.file->f_path.dentry->d_inode;
734734
xrcd = find_xrcd(file->device, inode);
735735
if (!xrcd && !(cmd.oflags & O_CREAT)) {
736736
/* no file descriptor. Need CREATE flag */
@@ -795,8 +795,8 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
795795
goto err_copy;
796796
}
797797

798-
if (f)
799-
fput_light(f, fput_needed);
798+
if (f.file)
799+
fdput(f);
800800

801801
mutex_lock(&file->mutex);
802802
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,
825825
put_uobj_write(&obj->uobject);
826826

827827
err_tree_mutex_unlock:
828-
if (f)
829-
fput_light(f, fput_needed);
828+
if (f.file)
829+
fdput(f);
830830

831831
mutex_unlock(&file->device->xrcd_tree_mutex);
832832

‎drivers/infiniband/core/uverbs_main.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,17 +541,15 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
541541
struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd)
542542
{
543543
struct ib_uverbs_event_file *ev_file = NULL;
544-
struct file *filp;
545-
int fput_needed;
544+
struct fd f = fdget(fd);
546545

547-
filp = fget_light(fd, &fput_needed);
548-
if (!filp)
546+
if (!f.file)
549547
return NULL;
550548

551-
if (filp->f_op != &uverbs_event_fops)
549+
if (f.file->f_op != &uverbs_event_fops)
552550
goto out;
553551

554-
ev_file = filp->private_data;
552+
ev_file = f.file->private_data;
555553
if (ev_file->is_async) {
556554
ev_file = NULL;
557555
goto out;
@@ -560,7 +558,7 @@ struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd)
560558
kref_get(&ev_file->ref);
561559

562560
out:
563-
fput_light(filp, fput_needed);
561+
fdput(f);
564562
return ev_file;
565563
}
566564

‎drivers/vfio/vfio.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,25 +1014,25 @@ static void vfio_group_try_dissolve_container(struct vfio_group *group)
10141014

10151015
static int vfio_group_set_container(struct vfio_group *group, int container_fd)
10161016
{
1017-
struct file *filep;
1017+
struct fd f;
10181018
struct vfio_container *container;
10191019
struct vfio_iommu_driver *driver;
1020-
int ret = 0, fput_needed;
1020+
int ret = 0;
10211021

10221022
if (atomic_read(&group->container_users))
10231023
return -EINVAL;
10241024

1025-
filep = fget_light(container_fd, &fput_needed);
1026-
if (!filep)
1025+
f = fdget(container_fd);
1026+
if (!f.file)
10271027
return -EBADF;
10281028

10291029
/* 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);
10321032
return -EINVAL;
10331033
}
10341034

1035-
container = filep->private_data;
1035+
container = f.file->private_data;
10361036
WARN_ON(!container); /* fget ensures we don't race vfio_release */
10371037

10381038
mutex_lock(&container->group_lock);
@@ -1054,8 +1054,7 @@ static int vfio_group_set_container(struct vfio_group *group, int container_fd)
10541054

10551055
unlock_out:
10561056
mutex_unlock(&container->group_lock);
1057-
fput_light(filep, fput_needed);
1058-
1057+
fdput(f);
10591058
return ret;
10601059
}
10611060

‎drivers/video/msm/mdp.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,17 @@ int get_img(struct mdp_img *img, struct fb_info *info,
257257
unsigned long *start, unsigned long *len,
258258
struct file **filep)
259259
{
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)
265263
return -1;
266264

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) {
268266
*start = info->fix.smem_start;
269267
*len = info->fix.smem_len;
270268
} else
271269
ret = -1;
272-
fput_light(file, put_needed);
270+
fdput(f);
273271

274272
return ret;
275273
}

0 commit comments

Comments
 (0)