connection: simplify kdbus_conn_lock2()
authorDavid Herrmann <dh.herrmann@gmail.com>
Fri, 9 Jan 2015 00:21:37 +0000 (01:21 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Fri, 9 Jan 2015 00:21:37 +0000 (01:21 +0100)
Drop 6 lines again and move the conditions directly before the lock
invokations.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
connection.h

index 5ef557b56384aec381eb314374515f0094b4c0f3..e535ab83eb8b18fad202a9ce4d19a9e066e310f7 100644 (file)
@@ -210,46 +210,40 @@ static inline int kdbus_conn_is_monitor(const struct kdbus_conn *conn)
 
 /**
  * kdbus_conn_lock2() - Lock two connections
- * @a:         connection A to lock
- * @b:         connection B to lock
+ * @a:         connection A to lock or NULL
+ * @b:         connection B to lock or NULL
  *
  * Lock two connections at once. As we need to have a stable locking order, we
  * always lock the connection with lower memory address first.
  */
 static inline void kdbus_conn_lock2(struct kdbus_conn *a, struct kdbus_conn *b)
 {
-       if (a == b)
-               b = NULL;
-
        if (a < b) {
                if (a)
                        mutex_lock(&a->lock);
-               if (b)
+               if (b && b != a)
                        mutex_lock_nested(&b->lock, !!a);
        } else {
                if (b)
                        mutex_lock(&b->lock);
-               if (a)
+               if (a && a != b)
                        mutex_lock_nested(&a->lock, !!b);
        }
 }
 
 /**
  * kdbus_conn_unlock2() - Unlock two connections
- * @a:         connection A to unlock
- * @b:         connection B to unlock
+ * @a:         connection A to unlock or NULL
+ * @b:         connection B to unlock or NULL
  *
  * Unlock two connections at once. See kdbus_conn_lock2().
  */
 static inline void kdbus_conn_unlock2(struct kdbus_conn *a,
                                      struct kdbus_conn *b)
 {
-       if (a == b)
-               b = NULL;
-
        if (a)
                mutex_unlock(&a->lock);
-       if (b)
+       if (b && b != a)
                mutex_unlock(&b->lock);
 }