connection.h: make kdbus_conn_{un,}lock2() NULL pointer resistant
authorDaniel Mack <daniel@zonque.org>
Thu, 8 Jan 2015 13:12:36 +0000 (14:12 +0100)
committerDaniel Mack <daniel@zonque.org>
Thu, 8 Jan 2015 13:12:36 +0000 (14:12 +0100)
Allow NULL pointers in both arguments to kdbus_conn_lock2() and
kdbus_conn_unlock2().

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

index 86a25d2cf5240c0b6f4efade964cbedcea595151..5b5a27a0b98aa79fb9055b8857c4c94c29b3164a 100644 (file)
@@ -219,11 +219,15 @@ 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) {
-               mutex_lock(&a->lock);
-               mutex_lock_nested(&b->lock, 1);
+               if (a)
+                       mutex_lock(&a->lock);
+               if (b)
+                       mutex_lock_nested(&b->lock, 1);
        } else {
-               mutex_lock(&b->lock);
-               mutex_lock_nested(&a->lock, 1);
+               if (b)
+                       mutex_lock(&b->lock);
+               if (a)
+                       mutex_lock_nested(&a->lock, 1);
        }
 }
 
@@ -237,8 +241,10 @@ 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)
 {
-       mutex_unlock(&a->lock);
-       mutex_unlock(&b->lock);
+       if (a)
+               mutex_unlock(&a->lock);
+       if (b)
+               mutex_unlock(&b->lock);
 }
 
 #endif