connection: fix kdbus_conn_lock2() for A==B
authorDavid Herrmann <dh.herrmann@gmail.com>
Thu, 8 Jan 2015 23:36:38 +0000 (00:36 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Thu, 8 Jan 2015 23:36:38 +0000 (00:36 +0100)
In odd cases (eg., sending a message to yourself), you might call
kdbus_conn_lock2() with A==B. Make sure we lock the connection only once
to not dead-lock.

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

index 413b780a83890f0ad16bbad5bf03aa7ce7a06773..5ef557b56384aec381eb314374515f0094b4c0f3 100644 (file)
@@ -218,6 +218,9 @@ static inline int kdbus_conn_is_monitor(const struct kdbus_conn *conn)
  */
 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);
@@ -241,6 +244,9 @@ static inline void kdbus_conn_lock2(struct kdbus_conn *a, struct kdbus_conn *b)
 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)