Skip to content

Commit af4d909

Browse files
mtpr-otcfriedt
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 62ad640 commit af4d909

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
@@ -1667,12 +1667,15 @@ int ull_disable(void *lll)
16671667
if (!hdr || !ull_ref_get(hdr)) {
16681668
return 0;
16691669
}
1670+
cpu_dmb(); /* Ensure synchronized data access */
16701671

16711672
k_sem_init(&sem, 0, 1);
16721673

16731674
hdr->disabled_param = &sem;
16741675
hdr->disabled_cb = disabled_cb;
16751676

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

0 commit comments

Comments
 (0)