kdbus_conn_move_messages: Use kdbus_conn_queue_remove()
authorDaniel Mack <zonque@gmail.com>
Sat, 22 Mar 2014 11:56:17 +0000 (12:56 +0100)
committerDaniel Mack <zonque@gmail.com>
Sat, 22 Mar 2014 12:08:34 +0000 (13:08 +0100)
Cleanup the original connection's queue properly by calling
kdbus_conn_queue_remove().

connection.c

index b0ee7f9206d32b2114de4cd9c9c049a06b9fc30b..41ffabc28360f10d47c7c7b7ff085b5f7d95f87c 100644 (file)
@@ -1628,14 +1628,14 @@ struct kdbus_conn *kdbus_conn_unref(struct kdbus_conn *conn)
 }
 
 /**
- * kdbus_conn_move_messages() - move a message from one connection to another
+ * kdbus_conn_move_messages() - move messages from one connection to another
  * @conn_dst:          Connection to copy to
  * @conn_src:          Connection to copy from
  * @name_id:           Filter for the sequence number of the registered
  *                     name, 0 means no filtering.
  *
  * Move all messages from one connection to another. This is used when
- * an ordinary connection is taking over a well-known name from a
+ * an implementor connection is taking over a well-known name from an
  * activator connection.
  *
  * Return: 0 on success, negative errno on failure.
@@ -1654,10 +1654,13 @@ int kdbus_conn_move_messages(struct kdbus_conn *conn_dst,
 
        /* remove all messages from the source */
        mutex_lock(&conn_src->lock);
-       list_splice_init(&conn_src->msg_list, &msg_list);
        list_splice_init(&conn_src->reply_list, &reply_list);
-       conn_src->msg_prio_queue = RB_ROOT;
-       conn_src->msg_count = 0;
+
+       list_for_each_entry_safe(q, q_tmp, &conn_src->msg_list, entry) {
+               kdbus_conn_queue_remove(conn_src, q);
+               list_add_tail(&q->entry, &msg_list);
+       }
+
        mutex_unlock(&conn_src->lock);
 
        /* insert messages into destination */
@@ -1671,7 +1674,7 @@ int kdbus_conn_move_messages(struct kdbus_conn *conn_dst,
 
                ret = kdbus_pool_move(conn_dst->pool, conn_src->pool,
                                      &q->off, q->size);
-               if (ret < 0)
+               if (WARN_ON(ret < 0))
                        kdbus_conn_queue_cleanup(q);
                else
                        kdbus_conn_queue_add(conn_dst, q);