|
@@ -207,36 +207,27 @@ int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *w
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(eventfd_ctx_remove_wait_queue);
|
|
|
|
|
|
-/**
|
|
|
- * eventfd_ctx_read - Reads the eventfd counter or wait if it is zero.
|
|
|
- * @ctx: [in] Pointer to eventfd context.
|
|
|
- * @no_wait: [in] Different from zero if the operation should not block.
|
|
|
- * @cnt: [out] Pointer to the 64-bit counter value.
|
|
|
- *
|
|
|
- * Returns %0 if successful, or the following error codes:
|
|
|
- *
|
|
|
- * - -EAGAIN : The operation would have blocked but @no_wait was non-zero.
|
|
|
- * - -ERESTARTSYS : A signal interrupted the wait operation.
|
|
|
- *
|
|
|
- * If @no_wait is zero, the function might sleep until the eventfd internal
|
|
|
- * counter becomes greater than zero.
|
|
|
- */
|
|
|
-ssize_t eventfd_ctx_read(struct eventfd_ctx *ctx, int no_wait, __u64 *cnt)
|
|
|
+static ssize_t eventfd_read(struct file *file, char __user *buf, size_t count,
|
|
|
+ loff_t *ppos)
|
|
|
{
|
|
|
+ struct eventfd_ctx *ctx = file->private_data;
|
|
|
ssize_t res;
|
|
|
+ __u64 ucnt = 0;
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
+ if (count < sizeof(ucnt))
|
|
|
+ return -EINVAL;
|
|
|
+
|
|
|
spin_lock_irq(&ctx->wqh.lock);
|
|
|
- *cnt = 0;
|
|
|
res = -EAGAIN;
|
|
|
if (ctx->count > 0)
|
|
|
- res = 0;
|
|
|
- else if (!no_wait) {
|
|
|
+ res = sizeof(ucnt);
|
|
|
+ else if (!(file->f_flags & O_NONBLOCK)) {
|
|
|
__add_wait_queue(&ctx->wqh, &wait);
|
|
|
for (;;) {
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
if (ctx->count > 0) {
|
|
|
- res = 0;
|
|
|
+ res = sizeof(ucnt);
|
|
|
break;
|
|
|
}
|
|
|
if (signal_pending(current)) {
|
|
@@ -250,31 +241,17 @@ ssize_t eventfd_ctx_read(struct eventfd_ctx *ctx, int no_wait, __u64 *cnt)
|
|
|
__remove_wait_queue(&ctx->wqh, &wait);
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
}
|
|
|
- if (likely(res == 0)) {
|
|
|
- eventfd_ctx_do_read(ctx, cnt);
|
|
|
+ if (likely(res > 0)) {
|
|
|
+ eventfd_ctx_do_read(ctx, &ucnt);
|
|
|
if (waitqueue_active(&ctx->wqh))
|
|
|
wake_up_locked_poll(&ctx->wqh, POLLOUT);
|
|
|
}
|
|
|
spin_unlock_irq(&ctx->wqh.lock);
|
|
|
|
|
|
- return res;
|
|
|
-}
|
|
|
-EXPORT_SYMBOL_GPL(eventfd_ctx_read);
|
|
|
-
|
|
|
-static ssize_t eventfd_read(struct file *file, char __user *buf, size_t count,
|
|
|
- loff_t *ppos)
|
|
|
-{
|
|
|
- struct eventfd_ctx *ctx = file->private_data;
|
|
|
- ssize_t res;
|
|
|
- __u64 cnt;
|
|
|
-
|
|
|
- if (count < sizeof(cnt))
|
|
|
- return -EINVAL;
|
|
|
- res = eventfd_ctx_read(ctx, file->f_flags & O_NONBLOCK, &cnt);
|
|
|
- if (res < 0)
|
|
|
- return res;
|
|
|
+ if (res > 0 && put_user(ucnt, (__u64 __user *)buf))
|
|
|
+ return -EFAULT;
|
|
|
|
|
|
- return put_user(cnt, (__u64 __user *) buf) ? -EFAULT : sizeof(cnt);
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t count,
|