Commit 7e3fb584 authored by Al Viro's avatar Al Viro

switch epoll_ctl() to fdget

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent a2e0578b
...@@ -1792,7 +1792,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -1792,7 +1792,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
{ {
int error; int error;
int did_lock_epmutex = 0; int did_lock_epmutex = 0;
struct file *file, *tfile; struct fd f, tf;
struct eventpoll *ep; struct eventpoll *ep;
struct epitem *epi; struct epitem *epi;
struct epoll_event epds; struct epoll_event epds;
...@@ -1802,20 +1802,19 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -1802,20 +1802,19 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
copy_from_user(&epds, event, sizeof(struct epoll_event))) copy_from_user(&epds, event, sizeof(struct epoll_event)))
goto error_return; goto error_return;
/* Get the "struct file *" for the eventpoll file */
error = -EBADF; error = -EBADF;
file = fget(epfd); f = fdget(epfd);
if (!file) if (!f.file)
goto error_return; goto error_return;
/* Get the "struct file *" for the target file */ /* Get the "struct file *" for the target file */
tfile = fget(fd); tf = fdget(fd);
if (!tfile) if (!tf.file)
goto error_fput; goto error_fput;
/* The target file descriptor must support poll */ /* The target file descriptor must support poll */
error = -EPERM; error = -EPERM;
if (!tfile->f_op || !tfile->f_op->poll) if (!tf.file->f_op || !tf.file->f_op->poll)
goto error_tgt_fput; goto error_tgt_fput;
/* Check if EPOLLWAKEUP is allowed */ /* Check if EPOLLWAKEUP is allowed */
...@@ -1828,14 +1827,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -1828,14 +1827,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
* adding an epoll file descriptor inside itself. * adding an epoll file descriptor inside itself.
*/ */
error = -EINVAL; error = -EINVAL;
if (file == tfile || !is_file_epoll(file)) if (f.file == tf.file || !is_file_epoll(f.file))
goto error_tgt_fput; goto error_tgt_fput;
/* /*
* At this point it is safe to assume that the "private_data" contains * At this point it is safe to assume that the "private_data" contains
* our own data structure. * our own data structure.
*/ */
ep = file->private_data; ep = f.file->private_data;
/* /*
* When we insert an epoll file descriptor, inside another epoll file * When we insert an epoll file descriptor, inside another epoll file
...@@ -1854,14 +1853,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -1854,14 +1853,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
did_lock_epmutex = 1; did_lock_epmutex = 1;
} }
if (op == EPOLL_CTL_ADD) { if (op == EPOLL_CTL_ADD) {
if (is_file_epoll(tfile)) { if (is_file_epoll(tf.file)) {
error = -ELOOP; error = -ELOOP;
if (ep_loop_check(ep, tfile) != 0) { if (ep_loop_check(ep, tf.file) != 0) {
clear_tfile_check_list(); clear_tfile_check_list();
goto error_tgt_fput; goto error_tgt_fput;
} }
} else } else
list_add(&tfile->f_tfile_llink, &tfile_check_list); list_add(&tf.file->f_tfile_llink, &tfile_check_list);
} }
mutex_lock_nested(&ep->mtx, 0); mutex_lock_nested(&ep->mtx, 0);
...@@ -1871,14 +1870,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -1871,14 +1870,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
* above, we can be sure to be able to use the item looked up by * above, we can be sure to be able to use the item looked up by
* ep_find() till we release the mutex. * ep_find() till we release the mutex.
*/ */
epi = ep_find(ep, tfile, fd); epi = ep_find(ep, tf.file, fd);
error = -EINVAL; error = -EINVAL;
switch (op) { switch (op) {
case EPOLL_CTL_ADD: case EPOLL_CTL_ADD:
if (!epi) { if (!epi) {
epds.events |= POLLERR | POLLHUP; epds.events |= POLLERR | POLLHUP;
error = ep_insert(ep, &epds, tfile, fd); error = ep_insert(ep, &epds, tf.file, fd);
} else } else
error = -EEXIST; error = -EEXIST;
clear_tfile_check_list(); clear_tfile_check_list();
...@@ -1903,9 +1902,9 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -1903,9 +1902,9 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
if (did_lock_epmutex) if (did_lock_epmutex)
mutex_unlock(&epmutex); mutex_unlock(&epmutex);
fput(tfile); fdput(tf);
error_fput: error_fput:
fput(file); fdput(f);
error_return: error_return:
return error; return error;
......
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