Skip to content

Commit 7f82b6a

Browse files
mtpr-otcarlescufi
authored andcommitted
Bluetooth: controller: Prevent invalid compiler code reordering
In ull_disable, it is imperative that the callback is set up before a second reference counter check, otherwise it may happen that an LLL done event has already passed when the disable callback and semaphore is assigned. This causes the HCI thread to wait until timeout and assert after ull_ticker_stop_with_mark. For certain compilers, due to compiler optimizations, it can be seen from the assembler code that the callback is assigned after the second reference counter check. By adding memory barriers, the code correctly reorders code to the expected sequence. Signed-off-by: Morten Priess <[email protected]>
1 parent d397aae commit 7f82b6a

File tree

1 file changed

+3
-0
lines changed
  • subsys/bluetooth/controller/ll_sw

1 file changed

+3
-0
lines changed

subsys/bluetooth/controller/ll_sw/ull.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,12 +1953,15 @@ int ull_disable(void *lll)
19531953
if (!ull_ref_get(hdr)) {
19541954
return -EALREADY;
19551955
}
1956+
cpu_dmb(); /* Ensure synchronized data access */
19561957

19571958
k_sem_init(&sem, 0, 1);
19581959

19591960
hdr->disabled_param = &sem;
19601961
hdr->disabled_cb = disabled_cb;
19611962

1963+
cpu_dmb(); /* Ensure synchronized data access */
1964+
19621965
/* ULL_HIGH can run after we have call `ull_ref_get` and it can
19631966
* decrement the ref count. Hence, handle this race condition by
19641967
* ensuring that `disabled_cb` has been set while the ref count is still

0 commit comments

Comments
 (0)