Commit cb0942b8 authored by Al Viro's avatar Al Viro

make get_file() return its argument

simplifies a bunch of callers...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent cecb46f1
...@@ -2306,7 +2306,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t ...@@ -2306,7 +2306,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
* partially initialize the vma for the sampling buffer * partially initialize the vma for the sampling buffer
*/ */
vma->vm_mm = mm; vma->vm_mm = mm;
vma->vm_file = filp; vma->vm_file = get_file(filp);
vma->vm_flags = VM_READ| VM_MAYREAD |VM_RESERVED; vma->vm_flags = VM_READ| VM_MAYREAD |VM_RESERVED;
vma->vm_page_prot = PAGE_READONLY; /* XXX may need to change */ vma->vm_page_prot = PAGE_READONLY; /* XXX may need to change */
...@@ -2345,8 +2345,6 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t ...@@ -2345,8 +2345,6 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
goto error; goto error;
} }
get_file(filp);
/* /*
* now insert the vma in the vm list for the process, must be * now insert the vma in the vm list for the process, must be
* done with mmap lock held * done with mmap lock held
......
...@@ -460,8 +460,7 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, ...@@ -460,8 +460,7 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
if (vma->vm_file) if (vma->vm_file)
fput(vma->vm_file); fput(vma->vm_file);
vma->vm_file = dmabuf->file; vma->vm_file = get_file(dmabuf->file);
get_file(vma->vm_file);
vma->vm_pgoff = pgoff; vma->vm_pgoff = pgoff;
......
...@@ -566,9 +566,8 @@ int omap_gem_mmap_obj(struct drm_gem_object *obj, ...@@ -566,9 +566,8 @@ int omap_gem_mmap_obj(struct drm_gem_object *obj,
* in particular in the case of mmap'd dmabufs) * in particular in the case of mmap'd dmabufs)
*/ */
fput(vma->vm_file); fput(vma->vm_file);
get_file(obj->filp);
vma->vm_pgoff = 0; vma->vm_pgoff = 0;
vma->vm_file = obj->filp; vma->vm_file = get_file(obj->filp);
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
} }
......
...@@ -1163,10 +1163,8 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf, ...@@ -1163,10 +1163,8 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
struct file *p = NULL; struct file *p = NULL;
spin_lock(&redirect_lock); spin_lock(&redirect_lock);
if (redirect) { if (redirect)
get_file(redirect); p = get_file(redirect);
p = redirect;
}
spin_unlock(&redirect_lock); spin_unlock(&redirect_lock);
if (p) { if (p) {
...@@ -2246,8 +2244,7 @@ static int tioccons(struct file *file) ...@@ -2246,8 +2244,7 @@ static int tioccons(struct file *file)
spin_unlock(&redirect_lock); spin_unlock(&redirect_lock);
return -EBUSY; return -EBUSY;
} }
get_file(file); redirect = get_file(file);
redirect = file;
spin_unlock(&redirect_lock); spin_unlock(&redirect_lock);
return 0; return 0;
} }
......
...@@ -175,8 +175,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi, ...@@ -175,8 +175,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
return; return;
} }
pipe = sbi->pipe; pipe = get_file(sbi->pipe);
get_file(pipe);
mutex_unlock(&sbi->wq_mutex); mutex_unlock(&sbi->wq_mutex);
......
...@@ -148,8 +148,7 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc, ...@@ -148,8 +148,7 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc,
if (ff->reserved_req) { if (ff->reserved_req) {
req = ff->reserved_req; req = ff->reserved_req;
ff->reserved_req = NULL; ff->reserved_req = NULL;
get_file(file); req->stolen_file = get_file(file);
req->stolen_file = file;
} }
spin_unlock(&fc->lock); spin_unlock(&fc->lock);
} while (!req); } while (!req);
......
...@@ -2837,8 +2837,7 @@ static int nfs4_setlease(struct nfs4_delegation *dp, int flag) ...@@ -2837,8 +2837,7 @@ static int nfs4_setlease(struct nfs4_delegation *dp, int flag)
return -ENOMEM; return -ENOMEM;
} }
fp->fi_lease = fl; fp->fi_lease = fl;
fp->fi_deleg_file = fl->fl_file; fp->fi_deleg_file = get_file(fl->fl_file);
get_file(fp->fi_deleg_file);
atomic_set(&fp->fi_delegees, 1); atomic_set(&fp->fi_delegees, 1);
list_add(&dp->dl_perfile, &fp->fi_delegations); list_add(&dp->dl_perfile, &fp->fi_delegations);
return 0; return 0;
......
...@@ -1979,8 +1979,7 @@ proc_map_files_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -1979,8 +1979,7 @@ proc_map_files_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (++pos <= filp->f_pos) if (++pos <= filp->f_pos)
continue; continue;
get_file(vma->vm_file); info.file = get_file(vma->vm_file);
info.file = vma->vm_file;
info.len = snprintf(info.name, info.len = snprintf(info.name,
sizeof(info.name), "%lx-%lx", sizeof(info.name), "%lx-%lx",
vma->vm_start, vma->vm_end); vma->vm_start, vma->vm_end);
......
...@@ -220,8 +220,7 @@ static void __pollwait(struct file *filp, wait_queue_head_t *wait_address, ...@@ -220,8 +220,7 @@ static void __pollwait(struct file *filp, wait_queue_head_t *wait_address,
struct poll_table_entry *entry = poll_get_entry(pwq); struct poll_table_entry *entry = poll_get_entry(pwq);
if (!entry) if (!entry)
return; return;
get_file(filp); entry->filp = get_file(filp);
entry->filp = filp;
entry->wait_address = wait_address; entry->wait_address = wait_address;
entry->key = p->_key; entry->key = p->_key;
init_waitqueue_func_entry(&entry->wait, pollwake); init_waitqueue_func_entry(&entry->wait, pollwake);
......
...@@ -1074,7 +1074,11 @@ struct file_handle { ...@@ -1074,7 +1074,11 @@ struct file_handle {
unsigned char f_handle[0]; unsigned char f_handle[0];
}; };
#define get_file(x) atomic_long_inc(&(x)->f_count) static inline struct file *get_file(struct file *f)
{
atomic_long_inc(&f->f_count);
return f;
}
#define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1) #define fput_atomic(x) atomic_long_add_unless(&(x)->f_count, -1, 1)
#define file_count(x) atomic_long_read(&(x)->f_count) #define file_count(x) atomic_long_read(&(x)->f_count)
......
...@@ -195,10 +195,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, ...@@ -195,10 +195,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
*/ */
if (mapping_cap_account_dirty(mapping)) { if (mapping_cap_account_dirty(mapping)) {
unsigned long addr; unsigned long addr;
struct file *file = vma->vm_file; struct file *file = get_file(vma->vm_file);
flags &= MAP_NONBLOCK; flags &= MAP_NONBLOCK;
get_file(file);
addr = mmap_region(file, start, size, addr = mmap_region(file, start, size,
flags, vma->vm_flags, pgoff); flags, vma->vm_flags, pgoff);
fput(file); fput(file);
......
...@@ -1301,8 +1301,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, ...@@ -1301,8 +1301,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
goto free_vma; goto free_vma;
correct_wcount = 1; correct_wcount = 1;
} }
vma->vm_file = file; vma->vm_file = get_file(file);
get_file(file);
error = file->f_op->mmap(file, vma); error = file->f_op->mmap(file, vma);
if (error) if (error)
goto unmap_and_free_vma; goto unmap_and_free_vma;
......
...@@ -1282,10 +1282,8 @@ unsigned long do_mmap_pgoff(struct file *file, ...@@ -1282,10 +1282,8 @@ unsigned long do_mmap_pgoff(struct file *file,
vma->vm_pgoff = pgoff; vma->vm_pgoff = pgoff;
if (file) { if (file) {
region->vm_file = file; region->vm_file = get_file(file);
get_file(file); vma->vm_file = get_file(file);
vma->vm_file = file;
get_file(file);
if (vm_flags & VM_EXECUTABLE) { if (vm_flags & VM_EXECUTABLE) {
added_exe_file_vma(current->mm); added_exe_file_vma(current->mm);
vma->vm_mm = current->mm; vma->vm_mm = current->mm;
......
...@@ -301,8 +301,7 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm) ...@@ -301,8 +301,7 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
break; break;
} }
/* Bump the usage count and install the file. */ /* Bump the usage count and install the file. */
get_file(fp[i]); fd_install(new_fd, get_file(fp[i]));
fd_install(new_fd, fp[i]);
} }
if (i > 0) { if (i > 0) {
......
...@@ -281,11 +281,10 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm) ...@@ -281,11 +281,10 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
break; break;
} }
/* Bump the usage count and install the file. */ /* Bump the usage count and install the file. */
get_file(fp[i]);
sock = sock_from_file(fp[i], &err); sock = sock_from_file(fp[i], &err);
if (sock) if (sock)
sock_update_netprioidx(sock->sk, current); sock_update_netprioidx(sock->sk, current);
fd_install(new_fd, fp[i]); fd_install(new_fd, get_file(fp[i]));
} }
if (i > 0) if (i > 0)
......
...@@ -2135,8 +2135,7 @@ static inline void flush_unauthorized_files(const struct cred *cred, ...@@ -2135,8 +2135,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
if (!IS_ERR(devnull)) { if (!IS_ERR(devnull)) {
/* replace all the matching ones with this */ /* replace all the matching ones with this */
do { do {
get_file(devnull); replace_fd(n - 1, get_file(devnull), 0);
replace_fd(n - 1, devnull, 0);
} while ((n = iterate_fd(files, n, match_file, cred)) != 0); } while ((n = iterate_fd(files, n, match_file, cred)) != 0);
fput(devnull); fput(devnull);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment