Skip to content

Commit

Permalink
switch simple cases of fget_light to fdget
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Sep 27, 2012
1 parent a5b470b commit 2903ff0
Show file tree
Hide file tree
Showing 44 changed files with 633 additions and 763 deletions.
15 changes: 6 additions & 9 deletions arch/alpha/kernel/osf_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,25 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
struct osf_dirent __user *, dirent, unsigned int, count,
long __user *, basep)
{
int error, fput_needed;
struct file *file;
int error;
struct fd arg = fdget(fd);
struct osf_dirent_callback buf;

error = -EBADF;
file = fget_light(fd, &fput_needed);
if (!file)
goto out;
if (!arg.file)
return -EBADF;

buf.dirent = dirent;
buf.basep = basep;
buf.count = count;
buf.error = 0;

error = vfs_readdir(file, osf_filldir, &buf);
error = vfs_readdir(arg.file, osf_filldir, &buf);
if (error >= 0)
error = buf.error;
if (count != buf.count)
error = count - buf.count;

fput_light(file, fput_needed);
out:
fdput(arg);
return error;
}

Expand Down
15 changes: 7 additions & 8 deletions arch/ia64/kernel/perfmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -4780,7 +4780,7 @@ pfm_check_task_state(pfm_context_t *ctx, int cmd, unsigned long flags)
asmlinkage long
sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
{
struct file *file = NULL;
struct fd f = {NULL, 0};
pfm_context_t *ctx = NULL;
unsigned long flags = 0UL;
void *args_k = NULL;
Expand All @@ -4789,7 +4789,6 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)
int narg, completed_args = 0, call_made = 0, cmd_flags;
int (*func)(pfm_context_t *ctx, void *arg, int count, struct pt_regs *regs);
int (*getsize)(void *arg, size_t *sz);
int fput_needed;
#define PFM_MAX_ARGSIZE 4096

/*
Expand Down Expand Up @@ -4878,17 +4877,17 @@ sys_perfmonctl (int fd, int cmd, void __user *arg, int count)

ret = -EBADF;

file = fget_light(fd, &fput_needed);
if (unlikely(file == NULL)) {
f = fdget(fd);
if (unlikely(f.file == NULL)) {
DPRINT(("invalid fd %d\n", fd));
goto error_args;
}
if (unlikely(PFM_IS_FILE(file) == 0)) {
if (unlikely(PFM_IS_FILE(f.file) == 0)) {
DPRINT(("fd %d not related to perfmon\n", fd));
goto error_args;
}

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

error_args:
if (file)
fput_light(file, fput_needed);
if (f.file)
fdput(f);

kfree(args_k);

Expand Down
17 changes: 8 additions & 9 deletions arch/parisc/hpux/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,32 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,

int hpux_getdents(unsigned int fd, struct hpux_dirent __user *dirent, unsigned int count)
{
struct file * file;
struct fd arg;
struct hpux_dirent __user * lastdirent;
struct getdents_callback buf;
int error = -EBADF, fput_needed;
int error;

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

buf.current_dir = dirent;
buf.previous = NULL;
buf.count = count;
buf.error = 0;

error = vfs_readdir(file, filldir, &buf);
error = vfs_readdir(arg.file, filldir, &buf);
if (error >= 0)
error = buf.error;
lastdirent = buf.previous;
if (lastdirent) {
if (put_user(file->f_pos, &lastdirent->d_off))
if (put_user(arg.file->f_pos, &lastdirent->d_off))
error = -EFAULT;
else
error = count - buf.count;
}

fput_light(file, fput_needed);
out:
fdput(arg);
return error;
}

Expand Down
21 changes: 9 additions & 12 deletions arch/powerpc/platforms/cell/spu_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,18 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
umode_t, mode, int, neighbor_fd)
{
long ret;
struct file *neighbor;
int fput_needed;
struct spufs_calls *calls;

calls = spufs_calls_get();
if (!calls)
return -ENOSYS;

if (flags & SPU_CREATE_AFFINITY_SPU) {
struct fd neighbor = fdget(neighbor_fd);
ret = -EBADF;
neighbor = fget_light(neighbor_fd, &fput_needed);
if (neighbor) {
ret = calls->create_thread(name, flags, mode, neighbor);
fput_light(neighbor, fput_needed);
if (neighbor.file) {
ret = calls->create_thread(name, flags, mode, neighbor.file);
fdput(neighbor);
}
} else
ret = calls->create_thread(name, flags, mode, NULL);
Expand All @@ -94,19 +92,18 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
{
long ret;
struct file *filp;
int fput_needed;
struct fd arg;
struct spufs_calls *calls;

calls = spufs_calls_get();
if (!calls)
return -ENOSYS;

ret = -EBADF;
filp = fget_light(fd, &fput_needed);
if (filp) {
ret = calls->spu_run(filp, unpc, ustatus);
fput_light(filp, fput_needed);
arg = fdget(fd);
if (arg.file) {
ret = calls->spu_run(arg.file, unpc, ustatus);
fdput(arg);
}

spufs_calls_put(calls);
Expand Down
12 changes: 6 additions & 6 deletions drivers/infiniband/core/ucma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,20 +1184,20 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
struct rdma_ucm_migrate_id cmd;
struct rdma_ucm_migrate_resp resp;
struct ucma_context *ctx;
struct file *filp;
struct fd f;
struct ucma_file *cur_file;
int ret = 0, fput_needed;
int ret = 0;

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

/* Get current fd to protect against it being closed */
filp = fget_light(cmd.fd, &fput_needed);
if (!filp)
f = fdget(cmd.fd);
if (!f.file)
return -ENOENT;

/* Validate current fd and prevent destruction of id. */
ctx = ucma_get_ctx(filp->private_data, cmd.id);
ctx = ucma_get_ctx(f.file->private_data, cmd.id);
if (IS_ERR(ctx)) {
ret = PTR_ERR(ctx);
goto file_put;
Expand Down Expand Up @@ -1231,7 +1231,7 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,

ucma_put_ctx(ctx);
file_put:
fput_light(filp, fput_needed);
fdput(f);
return ret;
}

Expand Down
18 changes: 9 additions & 9 deletions drivers/infiniband/core/uverbs_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
struct ib_udata udata;
struct ib_uxrcd_object *obj;
struct ib_xrcd *xrcd = NULL;
struct file *f = NULL;
struct fd f = {NULL, 0};
struct inode *inode = NULL;
int ret = 0, fput_needed;
int ret = 0;
int new_xrcd = 0;

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

if (cmd.fd != -1) {
/* search for file descriptor */
f = fget_light(cmd.fd, &fput_needed);
if (!f) {
f = fdget(cmd.fd);
if (!f.file) {
ret = -EBADF;
goto err_tree_mutex_unlock;
}

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

if (f)
fput_light(f, fput_needed);
if (f.file)
fdput(f);

mutex_lock(&file->mutex);
list_add_tail(&obj->uobject.list, &file->ucontext->xrcd_list);
Expand Down Expand Up @@ -825,8 +825,8 @@ ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
put_uobj_write(&obj->uobject);

err_tree_mutex_unlock:
if (f)
fput_light(f, fput_needed);
if (f.file)
fdput(f);

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

Expand Down
12 changes: 5 additions & 7 deletions drivers/infiniband/core/uverbs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,17 +541,15 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd)
{
struct ib_uverbs_event_file *ev_file = NULL;
struct file *filp;
int fput_needed;
struct fd f = fdget(fd);

filp = fget_light(fd, &fput_needed);
if (!filp)
if (!f.file)
return NULL;

if (filp->f_op != &uverbs_event_fops)
if (f.file->f_op != &uverbs_event_fops)
goto out;

ev_file = filp->private_data;
ev_file = f.file->private_data;
if (ev_file->is_async) {
ev_file = NULL;
goto out;
Expand All @@ -560,7 +558,7 @@ struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd)
kref_get(&ev_file->ref);

out:
fput_light(filp, fput_needed);
fdput(f);
return ev_file;
}

Expand Down
17 changes: 8 additions & 9 deletions drivers/vfio/vfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,25 +1014,25 @@ static void vfio_group_try_dissolve_container(struct vfio_group *group)

static int vfio_group_set_container(struct vfio_group *group, int container_fd)
{
struct file *filep;
struct fd f;
struct vfio_container *container;
struct vfio_iommu_driver *driver;
int ret = 0, fput_needed;
int ret = 0;

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

filep = fget_light(container_fd, &fput_needed);
if (!filep)
f = fdget(container_fd);
if (!f.file)
return -EBADF;

/* Sanity check, is this really our fd? */
if (filep->f_op != &vfio_fops) {
fput_light(filep, fput_needed);
if (f.file->f_op != &vfio_fops) {
fdput(f);
return -EINVAL;
}

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

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

unlock_out:
mutex_unlock(&container->group_lock);
fput_light(filep, fput_needed);

fdput(f);
return ret;
}

Expand Down
12 changes: 5 additions & 7 deletions drivers/video/msm/mdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,17 @@ int get_img(struct mdp_img *img, struct fb_info *info,
unsigned long *start, unsigned long *len,
struct file **filep)
{
int put_needed, ret = 0;
struct file *file;

file = fget_light(img->memory_id, &put_needed);
if (file == NULL)
int ret = 0;
struct fd f = fdget(img->memory_id);
if (f.file == NULL)
return -1;

if (MAJOR(file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
if (MAJOR(f.file->f_dentry->d_inode->i_rdev) == FB_MAJOR) {
*start = info->fix.smem_start;
*len = info->fix.smem_len;
} else
ret = -1;
fput_light(file, put_needed);
fdput(f);

return ret;
}
Expand Down
Loading

0 comments on commit 2903ff0

Please sign in to comment.