You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
0 commit comments