From 4a977463122e5fb25b034bcffd3dfdab6925638a Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 14 May 2024 14:54:04 +0200 Subject: [PATCH] Bluetooth: Host: Guard set state in conn_destroy If bt_conn_set_state(conn, BT_CONN_DISCONNECTED) is called while the connection is already disconnected, this triggers a warning. This is likely to happen when bt_conn_cleanup_all is called as part of bt_disable. Added the state check to avoid unnecessary warnings in the log. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/conn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 8caebcc4c3c..01832996969 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -852,7 +852,9 @@ static void conn_destroy(struct bt_conn *conn, void *data) bt_conn_set_state(conn, BT_CONN_DISCONNECT_COMPLETE); } - bt_conn_set_state(conn, BT_CONN_DISCONNECTED); + if (conn->state != BT_CONN_DISCONNECTED) { + bt_conn_set_state(conn, BT_CONN_DISCONNECTED); + } } void bt_conn_cleanup_all(void)