From 6c1f52dff719becf9cee8e52e0e8a4357186c34b Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Wed, 15 Jan 2020 13:09:27 +0100 Subject: [PATCH] Bluetooth: host: Set conn state before sending HCI command Handle a possible race condition in the host connection state. Set the conn state of the connection object before command is sent. This is in case the calling function is not scheduled again before the connection complete event arrives. In this case find_pending_conn will not find the connection object. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/conn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 2820f5768dc..d0d08e5df12 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -2248,6 +2248,8 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer, return conn; } #endif + bt_conn_set_state(conn, BT_CONN_CONNECT); + if (bt_le_direct_conn(conn)) { bt_conn_set_state(conn, BT_CONN_DISCONNECTED); bt_conn_unref(conn); @@ -2256,8 +2258,6 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer, return NULL; } - bt_conn_set_state(conn, BT_CONN_CONNECT); - return conn; }