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 <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-01-15 13:09:27 +01:00 committed by Johan Hedberg
commit 6c1f52dff7

View file

@ -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;
}