Skip to content

Commit e8cc179

Browse files
mtpr-othenrikbrixandersen
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]> (cherry picked from commit 7f82b6a) Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent a025a65 commit e8cc179

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
@@ -1954,12 +1954,15 @@ int ull_disable(void *lll)
19541954
if (!ull_ref_get(hdr)) {
19551955
return -EALREADY;
19561956
}
1957+
cpu_dmb(); /* Ensure synchronized data access */
19571958

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

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

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

0 commit comments

Comments
 (0)