sched/wait: Make the __wait_event*() interface more friendly
authorPeter Zijlstra <peterz@infradead.org>
Wed, 2 Oct 2013 09:22:33 +0000 (11:22 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 4 Oct 2013 08:16:25 +0000 (10:16 +0200)
Change all __wait_event*() implementations to match the corresponding
wait_event*() signature for convenience.

In particular this does away with the weird 'ret' logic. Since there
are __wait_event*() users this requires we update them too.

Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20131002092529.042563462@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/mips/kernel/rtlx.c
include/linux/tty.h
include/linux/wait.h
net/irda/af_irda.c
net/netfilter/ipvs/ip_vs_sync.c

index d763f11e35e2e9812a87c58e67f81759bb3dfd17..2c12ea1668d13df21b8908abc7fbc4f80d60678c 100644 (file)
@@ -172,8 +172,9 @@ int rtlx_open(int index, int can_sleep)
        if (rtlx == NULL) {
                if( (p = vpe_get_shared(tclimit)) == NULL) {
                    if (can_sleep) {
-                       __wait_event_interruptible(channel_wqs[index].lx_queue,
-                               (p = vpe_get_shared(tclimit)), ret);
+                       ret = __wait_event_interruptible(
+                                       channel_wqs[index].lx_queue,
+                                       (p = vpe_get_shared(tclimit)));
                        if (ret)
                                goto out_fail;
                    } else {
@@ -263,11 +264,10 @@ unsigned int rtlx_read_poll(int index, int can_sleep)
        /* data available to read? */
        if (chan->lx_read == chan->lx_write) {
                if (can_sleep) {
-                       int ret = 0;
-
-                       __wait_event_interruptible(channel_wqs[index].lx_queue,
+                       int ret = __wait_event_interruptible(
+                               channel_wqs[index].lx_queue,
                                (chan->lx_read != chan->lx_write) ||
-                               sp_stopping, ret);
+                               sp_stopping);
                        if (ret)
                                return ret;
 
@@ -440,14 +440,13 @@ static ssize_t file_write(struct file *file, const char __user * buffer,
 
        /* any space left... */
        if (!rtlx_write_poll(minor)) {
-               int ret = 0;
+               int ret;
 
                if (file->f_flags & O_NONBLOCK)
                        return -EAGAIN;
 
-               __wait_event_interruptible(channel_wqs[minor].rt_queue,
-                                          rtlx_write_poll(minor),
-                                          ret);
+               ret = __wait_event_interruptible(channel_wqs[minor].rt_queue,
+                                          rtlx_write_poll(minor));
                if (ret)
                        return ret;
        }
index 6e803291028fc4ad804a6f896b2a249e53b7b4ad..633cac77f9f97b56155bf5a005aa2899591425ac 100644 (file)
@@ -672,14 +672,14 @@ static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
 #define wait_event_interruptible_tty(tty, wq, condition)               \
 ({                                                                     \
        int __ret = 0;                                                  \
-       if (!(condition)) {                                             \
-               __wait_event_interruptible_tty(tty, wq, condition, __ret);      \
-       }                                                               \
+       if (!(condition))                                               \
+               __ret = __wait_event_interruptible_tty(tty, wq,         \
+                                                      condition);      \
        __ret;                                                          \
 })
 
-#define __wait_event_interruptible_tty(tty, wq, condition, ret)                \
-       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,        \
+#define __wait_event_interruptible_tty(tty, wq, condition)             \
+       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0,          \
                        tty_unlock(tty);                                \
                        schedule();                                     \
                        tty_lock(tty))
index c065e8af9749cf000df24d9a6a6d012b7309734d..bd4bd7b479b62d42cf3ffae8e31bde3a98a5ea54 100644 (file)
@@ -179,24 +179,23 @@ wait_queue_head_t *bit_waitqueue(void *, int);
 #define wake_up_interruptible_sync_poll(x, m)                          \
        __wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
 
-#define ___wait_cond_timeout(condition, ret)                           \
+#define ___wait_cond_timeout(condition)                                        \
 ({                                                                     \
        bool __cond = (condition);                                      \
-       if (__cond && !ret)                                             \
-               ret = 1;                                                \
-       __cond || !ret;                                                 \
+       if (__cond && !__ret)                                           \
+               __ret = 1;                                              \
+       __cond || !__ret;                                               \
 })
 
 #define ___wait_signal_pending(state)                                  \
        ((state == TASK_INTERRUPTIBLE && signal_pending(current)) ||    \
         (state == TASK_KILLABLE && fatal_signal_pending(current)))
 
-#define ___wait_nop_ret                int ret __always_unused
-
 #define ___wait_event(wq, condition, state, exclusive, ret, cmd)       \
-do {                                                                   \
+({                                                                     \
        __label__ __out;                                                \
        DEFINE_WAIT(__wait);                                            \
+       long __ret = ret;                                               \
                                                                        \
        for (;;) {                                                      \
                if (exclusive)                                          \
@@ -208,7 +207,7 @@ do {                                                                        \
                        break;                                          \
                                                                        \
                if (___wait_signal_pending(state)) {                    \
-                       ret = -ERESTARTSYS;                             \
+                       __ret = -ERESTARTSYS;                           \
                        if (exclusive) {                                \
                                abort_exclusive_wait(&wq, &__wait,      \
                                                     state, NULL);      \
@@ -220,12 +219,12 @@ do {                                                                      \
                cmd;                                                    \
        }                                                               \
        finish_wait(&wq, &__wait);                                      \
-__out: ;                                                               \
-} while (0)
+__out: __ret;                                                          \
+})
 
 #define __wait_event(wq, condition)                                    \
-       ___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0,           \
-                     ___wait_nop_ret, schedule())
+       (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0,  \
+                           schedule())
 
 /**
  * wait_event - sleep until a condition gets true
@@ -246,10 +245,10 @@ do {                                                                      \
        __wait_event(wq, condition);                                    \
 } while (0)
 
-#define __wait_event_timeout(wq, condition, ret)                       \
-       ___wait_event(wq, ___wait_cond_timeout(condition, ret),         \
-                     TASK_UNINTERRUPTIBLE, 0, ret,                     \
-                     ret = schedule_timeout(ret))
+#define __wait_event_timeout(wq, condition, timeout)                   \
+       ___wait_event(wq, ___wait_cond_timeout(condition),              \
+                     TASK_UNINTERRUPTIBLE, 0, timeout,                 \
+                     __ret = schedule_timeout(__ret))
 
 /**
  * wait_event_timeout - sleep until a condition gets true or a timeout elapses
@@ -272,12 +271,12 @@ do {                                                                      \
 ({                                                                     \
        long __ret = timeout;                                           \
        if (!(condition))                                               \
-               __wait_event_timeout(wq, condition, __ret);             \
+               __ret = __wait_event_timeout(wq, condition, timeout);   \
        __ret;                                                          \
 })
 
-#define __wait_event_interruptible(wq, condition, ret)                 \
-       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,        \
+#define __wait_event_interruptible(wq, condition)                      \
+       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0,          \
                      schedule())
 
 /**
@@ -299,14 +298,14 @@ do {                                                                      \
 ({                                                                     \
        int __ret = 0;                                                  \
        if (!(condition))                                               \
-               __wait_event_interruptible(wq, condition, __ret);       \
+               __ret = __wait_event_interruptible(wq, condition);      \
        __ret;                                                          \
 })
 
-#define __wait_event_interruptible_timeout(wq, condition, ret)         \
-       ___wait_event(wq, ___wait_cond_timeout(condition, ret),         \
-                     TASK_INTERRUPTIBLE, 0, ret,                       \
-                     ret = schedule_timeout(ret))
+#define __wait_event_interruptible_timeout(wq, condition, timeout)     \
+       ___wait_event(wq, ___wait_cond_timeout(condition),              \
+                     TASK_INTERRUPTIBLE, 0, timeout,                   \
+                     __ret = schedule_timeout(__ret))
 
 /**
  * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
@@ -330,7 +329,8 @@ do {                                                                        \
 ({                                                                     \
        long __ret = timeout;                                           \
        if (!(condition))                                               \
-               __wait_event_interruptible_timeout(wq, condition, __ret); \
+               __ret = __wait_event_interruptible_timeout(wq,          \
+                                               condition, timeout);    \
        __ret;                                                          \
 })
 
@@ -347,7 +347,7 @@ do {                                                                        \
                                       current->timer_slack_ns,         \
                                       HRTIMER_MODE_REL);               \
                                                                        \
-       ___wait_event(wq, condition, state, 0, __ret,                   \
+       __ret = ___wait_event(wq, condition, state, 0, 0,               \
                if (!__t.task) {                                        \
                        __ret = -ETIME;                                 \
                        break;                                          \
@@ -409,15 +409,15 @@ do {                                                                      \
        __ret;                                                          \
 })
 
-#define __wait_event_interruptible_exclusive(wq, condition, ret)       \
-       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, ret,        \
+#define __wait_event_interruptible_exclusive(wq, condition)            \
+       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0,          \
                      schedule())
 
 #define wait_event_interruptible_exclusive(wq, condition)              \
 ({                                                                     \
        int __ret = 0;                                                  \
        if (!(condition))                                               \
-               __wait_event_interruptible_exclusive(wq, condition, __ret);\
+               __ret = __wait_event_interruptible_exclusive(wq, condition);\
        __ret;                                                          \
 })
 
@@ -570,8 +570,8 @@ do {                                                                        \
 
 
 
-#define __wait_event_killable(wq, condition, ret)                      \
-       ___wait_event(wq, condition, TASK_KILLABLE, 0, ret, schedule())
+#define __wait_event_killable(wq, condition)                           \
+       ___wait_event(wq, condition, TASK_KILLABLE, 0, 0, schedule())
 
 /**
  * wait_event_killable - sleep until a condition gets true
@@ -592,18 +592,17 @@ do {                                                                      \
 ({                                                                     \
        int __ret = 0;                                                  \
        if (!(condition))                                               \
-               __wait_event_killable(wq, condition, __ret);            \
+               __ret = __wait_event_killable(wq, condition);           \
        __ret;                                                          \
 })
 
 
 #define __wait_event_lock_irq(wq, condition, lock, cmd)                        \
-       ___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0,           \
-                     ___wait_nop_ret,                                  \
-                     spin_unlock_irq(&lock);                           \
-                     cmd;                                              \
-                     schedule();                                       \
-                     spin_lock_irq(&lock))
+       (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0,  \
+                           spin_unlock_irq(&lock);                     \
+                           cmd;                                        \
+                           schedule();                                 \
+                           spin_lock_irq(&lock))
 
 /**
  * wait_event_lock_irq_cmd - sleep until a condition gets true. The
@@ -663,11 +662,11 @@ do {                                                                      \
 } while (0)
 
 
-#define __wait_event_interruptible_lock_irq(wq, condition, lock, ret, cmd) \
-       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,           \
-                     spin_unlock_irq(&lock);                              \
-                     cmd;                                                 \
-                     schedule();                                          \
+#define __wait_event_interruptible_lock_irq(wq, condition, lock, cmd)  \
+       ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0,          \
+                     spin_unlock_irq(&lock);                           \
+                     cmd;                                              \
+                     schedule();                                       \
                      spin_lock_irq(&lock))
 
 /**
@@ -698,10 +697,9 @@ do {                                                                       \
 #define wait_event_interruptible_lock_irq_cmd(wq, condition, lock, cmd)        \
 ({                                                                     \
        int __ret = 0;                                                  \
-                                                                       \
        if (!(condition))                                               \
-               __wait_event_interruptible_lock_irq(wq, condition,      \
-                                                   lock, __ret, cmd);  \
+               __ret = __wait_event_interruptible_lock_irq(wq,         \
+                                               condition, lock, cmd);  \
        __ret;                                                          \
 })
 
@@ -730,18 +728,18 @@ do {                                                                      \
 #define wait_event_interruptible_lock_irq(wq, condition, lock)         \
 ({                                                                     \
        int __ret = 0;                                                  \
-                                                                       \
        if (!(condition))                                               \
-               __wait_event_interruptible_lock_irq(wq, condition,      \
-                                                   lock, __ret, );     \
+               __ret = __wait_event_interruptible_lock_irq(wq,         \
+                                               condition, lock,)       \
        __ret;                                                          \
 })
 
-#define __wait_event_interruptible_lock_irq_timeout(wq, condition, lock, ret) \
-       ___wait_event(wq, ___wait_cond_timeout(condition, ret),               \
-                     TASK_INTERRUPTIBLE, 0, ret,                             \
-                     spin_unlock_irq(&lock);                                 \
-                     ret = schedule_timeout(ret);                            \
+#define __wait_event_interruptible_lock_irq_timeout(wq, condition,     \
+                                                   lock, timeout)      \
+       ___wait_event(wq, ___wait_cond_timeout(condition),              \
+                     TASK_INTERRUPTIBLE, 0, ret,                       \
+                     spin_unlock_irq(&lock);                           \
+                     __ret = schedule_timeout(__ret);                  \
                      spin_lock_irq(&lock));
 
 /**
@@ -771,11 +769,10 @@ do {                                                                      \
 #define wait_event_interruptible_lock_irq_timeout(wq, condition, lock, \
                                                  timeout)              \
 ({                                                                     \
-       int __ret = timeout;                                            \
-                                                                       \
+       long __ret = timeout;                                           \
        if (!(condition))                                               \
-               __wait_event_interruptible_lock_irq_timeout(            \
-                                       wq, condition, lock, __ret);    \
+               __ret = __wait_event_interruptible_lock_irq_timeout(    \
+                                       wq, condition, lock, timeout);  \
        __ret;                                                          \
 })
 
index 0578d4fa00a9cf1c274b2adb42d8277801dbdeb3..0f676908d15b6108225817108d1cdddf0e31dc16 100644 (file)
@@ -2563,9 +2563,8 @@ bed:
                                  jiffies + msecs_to_jiffies(val));
 
                        /* Wait for IR-LMP to call us back */
-                       __wait_event_interruptible(self->query_wait,
-                             (self->cachedaddr != 0 || self->errno == -ETIME),
-                                                  err);
+                       err = __wait_event_interruptible(self->query_wait,
+                             (self->cachedaddr != 0 || self->errno == -ETIME));
 
                        /* If watchdog is still activated, kill it! */
                        del_timer(&(self->watchdog));
index f4484719f3e638cc2c6cf10e4d0fa5535990ad6a..f63c2388f38d80f470d2ef0e5b38a7a20741696f 100644 (file)
@@ -1637,12 +1637,9 @@ static int sync_thread_master(void *data)
                        continue;
                }
                while (ip_vs_send_sync_msg(tinfo->sock, sb->mesg) < 0) {
-                       int ret = 0;
-
-                       __wait_event_interruptible(*sk_sleep(sk),
+                       int ret = __wait_event_interruptible(*sk_sleep(sk),
                                                   sock_writeable(sk) ||
-                                                  kthread_should_stop(),
-                                                  ret);
+                                                  kthread_should_stop());
                        if (unlikely(kthread_should_stop()))
                                goto done;
                }