Skip to content

Commit 51f57da

Browse files
dottspinacfriedt
authored andcommitted
Bluetooth: Host: Fix use of local variable as atomic target
In bt_conn_unref(), a local variable is used as atomic target: atomic_val_t old = atomic_dec(&conn->ref); /* Prevent from accessing connection object */ bool deallocated = (atomic_get(&old) == 1); Using atomic_get() to access a non-shared local variable cannot prevent any data race on that variable, and only causes confusion. Moreover, this call to atomic_get() is incorrect: the API expects an atomic_t* argument (target), not an atomic_val_t* (value). This compiles and /works/ only because Zephyr defines both to be the same integer type, and thus: atomic_get(&old) == old. The equivalent C11 code, where _Atomic(T) and T are different types, wouldn't compile. Signed-off-by: Christophe Dufaza <[email protected]>
1 parent 9354e06 commit 51f57da

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,8 @@ void bt_conn_unref(struct bt_conn *conn)
15111511
conn_handle = conn->handle;
15121512

15131513
old = atomic_dec(&conn->ref);
1514-
/* Prevent from accessing connection object */
1515-
deallocated = (atomic_get(&old) == 1);
1514+
/* Whether we removed the last reference. */
1515+
deallocated = (old == 1);
15161516
IF_ENABLED(CONFIG_BT_CONN_TX,
15171517
(__ASSERT(!(deallocated && k_work_is_pending(&conn->tx_complete_work)),
15181518
"tx_complete_work is pending when conn is deallocated")));

0 commit comments

Comments
 (0)