make get_file() return its argument
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 27 Aug 2012 18:48:26 +0000 (14:48 -0400)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 16 Sep 2017 20:23:58 +0000 (23:23 +0300)
simplifies a bunch of callers...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
12 files changed:
arch/ia64/kernel/perfmon.c
drivers/tty/tty_io.c
fs/autofs4/waitq.c
fs/fuse/dev.c
fs/nfsd/nfs4state.c
fs/proc/base.c
fs/select.c
include/linux/fs.h
mm/fremap.c
mm/mmap.c
mm/nommu.c
net/compat.c

index 89accc6..0c44766 100644 (file)
@@ -2323,7 +2323,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
         * partially initialize the vma for the sampling buffer
         */
        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_page_prot    = PAGE_READONLY; /* XXX may need to change */
 
@@ -2362,8 +2362,6 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
                goto error;
        }
 
-       get_file(filp);
-
        /*
         * now insert the vma in the vm list for the process, must be
         * done with mmap lock held
index 1f9ee25..4766138 100644 (file)
@@ -1174,10 +1174,8 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
        struct file *p = NULL;
 
        spin_lock(&redirect_lock);
-       if (redirect) {
-               get_file(redirect);
-               p = redirect;
-       }
+       if (redirect)
+               p = get_file(redirect);
        spin_unlock(&redirect_lock);
 
        if (p) {
@@ -2234,8 +2232,7 @@ static int tioccons(struct file *file)
                spin_unlock(&redirect_lock);
                return -EBUSY;
        }
-       get_file(file);
-       redirect = file;
+       redirect = get_file(file);
        spin_unlock(&redirect_lock);
        return 0;
 }
index 409df27..18d73ef 100644 (file)
@@ -174,8 +174,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
                return;
        }
 
-       pipe = sbi->pipe;
-       get_file(pipe);
+       pipe = get_file(sbi->pipe);
 
        mutex_unlock(&sbi->wq_mutex);
 
index 81970d7..8fe69e7 100644 (file)
@@ -148,8 +148,7 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc,
                if (ff->reserved_req) {
                        req = ff->reserved_req;
                        ff->reserved_req = NULL;
-                       get_file(file);
-                       req->stolen_file = file;
+                       req->stolen_file = get_file(file);
                }
                spin_unlock(&fc->lock);
        } while (!req);
index d455ea0..d7f4965 100644 (file)
@@ -2825,8 +2825,7 @@ static int nfs4_setlease(struct nfs4_delegation *dp, int flag)
                return -ENOMEM;
        }
        fp->fi_lease = fl;
-       fp->fi_deleg_file = fl->fl_file;
-       get_file(fp->fi_deleg_file);
+       fp->fi_deleg_file = get_file(fl->fl_file);
        atomic_set(&fp->fi_delegees, 1);
        spin_lock(&recall_lock);
        hash_delegation_locked(dp, fp);
index 5559ee9..97a5e64 100644 (file)
@@ -2377,8 +2377,7 @@ proc_map_files_readdir(struct file *filp, void *dirent, filldir_t filldir)
                                if (++pos <= filp->f_pos)
                                        continue;
 
-                               get_file(vma->vm_file);
-                               info.file = vma->vm_file;
+                               info.file = get_file(vma->vm_file);
                                info.len = snprintf(info.name,
                                                sizeof(info.name), "%lx-%lx",
                                                vma->vm_start, vma->vm_end);
index d33418f..aac299b 100644 (file)
@@ -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);
        if (!entry)
                return;
-       get_file(filp);
-       entry->filp = filp;
+       entry->filp = get_file(filp);
        entry->wait_address = wait_address;
        entry->key = p->key;
        init_waitqueue_func_entry(&entry->wait, pollwake);
index 8c63ec5..b2ccd1e 100644 (file)
@@ -1032,7 +1032,11 @@ struct file_handle {
        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 file_count(x)  atomic_long_read(&(x)->f_count)
 
index 9ed4fd4..048659c 100644 (file)
@@ -195,10 +195,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
                 */
                if (mapping_cap_account_dirty(mapping)) {
                        unsigned long addr;
-                       struct file *file = vma->vm_file;
+                       struct file *file = get_file(vma->vm_file);
 
                        flags &= MAP_NONBLOCK;
-                       get_file(file);
                        addr = mmap_region(file, start, size,
                                        flags, vma->vm_flags, pgoff);
                        fput(file);
index c7cbb40..56a644f 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1281,8 +1281,7 @@ munmap_back:
                                goto free_vma;
                        correct_wcount = 1;
                }
-               vma->vm_file = file;
-               get_file(file);
+               vma->vm_file = get_file(file);
                error = file->f_op->mmap(file, vma);
                if (error)
                        goto unmap_and_free_vma;
index d0cb11f..1fcf634 100644 (file)
@@ -1283,10 +1283,8 @@ unsigned long do_mmap_pgoff(struct file *file,
        vma->vm_pgoff = pgoff;
 
        if (file) {
-               region->vm_file = file;
-               get_file(file);
-               vma->vm_file = file;
-               get_file(file);
+               region->vm_file = get_file(file);
+               vma->vm_file = get_file(file);
                if (vm_flags & VM_EXECUTABLE) {
                        added_exe_file_vma(current->mm);
                        vma->vm_mm = current->mm;
index f06994d..7c9b896 100644 (file)
@@ -310,8 +310,7 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
                        break;
                }
                /* Bump the usage count and install the file. */
-               get_file(fp[i]);
-               fd_install(new_fd, fp[i]);
+               fd_install(new_fd, get_file(fp[i]));
        }
 
        if (i > 0) {