kcmp: In get_file_raw_ptr use task_lookup_fd_rcu
[sfrench/cifs-2.6.git] / kernel / kcmp.c
index b3ff9288c6cc91360db86fe25407204d5ab6ebd1..36e58eb5a11dd8c995fa1f6cb85c01d5708f91ca 100644 (file)
@@ -61,16 +61,11 @@ static int kcmp_ptr(void *v1, void *v2, enum kcmp_type type)
 static struct file *
 get_file_raw_ptr(struct task_struct *task, unsigned int idx)
 {
-       struct file *file = NULL;
+       struct file *file;
 
-       task_lock(task);
        rcu_read_lock();
-
-       if (task->files)
-               file = fcheck_files(task->files, idx);
-
+       file = task_lookup_fd_rcu(task, idx);
        rcu_read_unlock();
-       task_unlock(task);
 
        return file;
 }
@@ -107,7 +102,6 @@ static int kcmp_epoll_target(struct task_struct *task1,
 {
        struct file *filp, *filp_epoll, *filp_tgt;
        struct kcmp_epoll_slot slot;
-       struct files_struct *files;
 
        if (copy_from_user(&slot, uslot, sizeof(slot)))
                return -EFAULT;
@@ -116,23 +110,12 @@ static int kcmp_epoll_target(struct task_struct *task1,
        if (!filp)
                return -EBADF;
 
-       files = get_files_struct(task2);
-       if (!files)
+       filp_epoll = fget_task(task2, slot.efd);
+       if (!filp_epoll)
                return -EBADF;
 
-       spin_lock(&files->file_lock);
-       filp_epoll = fcheck_files(files, slot.efd);
-       if (filp_epoll)
-               get_file(filp_epoll);
-       else
-               filp_tgt = ERR_PTR(-EBADF);
-       spin_unlock(&files->file_lock);
-       put_files_struct(files);
-
-       if (filp_epoll) {
-               filp_tgt = get_epoll_tfile_raw_ptr(filp_epoll, slot.tfd, slot.toff);
-               fput(filp_epoll);
-       }
+       filp_tgt = get_epoll_tfile_raw_ptr(filp_epoll, slot.tfd, slot.toff);
+       fput(filp_epoll);
 
        if (IS_ERR(filp_tgt))
                return PTR_ERR(filp_tgt);