connection: return -ETIMEDOUT immediately if msg->timeout_ns <= now
authorDaniel Mack <daniel@zonque.org>
Wed, 17 Dec 2014 16:29:38 +0000 (17:29 +0100)
committerDaniel Mack <daniel@zonque.org>
Wed, 17 Dec 2014 16:34:02 +0000 (17:34 +0100)
If the timeout of a message has already exceeded at the time of
sending a message, there's no point in going to sleep. Return
-ETIMEDOUT immediately in such cases.

While at it, move the !reply_wait check to kdbus_conn_wait_reply().

Signed-off-by: Daniel Mack <daniel@zonque.org>
connection.c

index 4336fc86cd4006ee4e8f7a9a90f9c156fbb1ccd7..509a4e3be3880c0be27ef7d0af255263287c7b9b 100644 (file)
@@ -671,6 +671,9 @@ static int kdbus_conn_wait_reply(struct kdbus_conn *conn_src,
        struct kdbus_queue_entry *entry;
        int r, ret;
 
+       if (WARN_ON(!reply_wait))
+               return -EIO;
+
        /*
         * Block until the reply arrives. reply_wait is left untouched
         * by the timeout scans that might be conducted for other,
@@ -939,23 +942,17 @@ wait_sync:
 
        if (sync) {
                struct timespec64 ts;
-               u64 now, timeout;
-
-               if (WARN_ON(!reply_wait)) {
-                       ret = -EIO;
-                       goto exit_unref;
-               }
+               u64 now;
 
                ktime_get_ts64(&ts);
                now = timespec64_to_ns(&ts);
 
-               if (unlikely(msg->timeout_ns <= now))
-                       timeout = 0;
+               if (likely(msg->timeout_ns > now))
+                       ret = kdbus_conn_wait_reply(conn_src, conn_dst,
+                                                   cmd_send, reply_wait,
+                                                   msg->timeout_ns - now);
                else
-                       timeout = msg->timeout_ns - now;
-
-               ret = kdbus_conn_wait_reply(conn_src, conn_dst, cmd_send,
-                                           reply_wait, timeout);
+                       ret = -ETIMEDOUT;
        }
 
 exit_unref: