From 5dcd2bbbde7ae25c6d018a3966d7853d8faece1c Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 9 Jan 2015 00:36:38 +0100 Subject: [PATCH] connection: fix kdbus_conn_lock2() for A==B 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 --- connection.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/connection.h b/connection.h index 413b780..5ef557b 100644 --- a/connection.h +++ b/connection.h @@ -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) -- 2.34.1