diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync.c b/subsys/bluetooth/controller/ll_sw/ull_sync.c index 9023cfa812ead..71993520497d7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync.c @@ -197,19 +197,19 @@ uint8_t ll_sync_create_cancel(void **rx) } } - sync = scan->per_scan.sync; - scan->per_scan.sync = NULL; - if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) { - scan_coded->per_scan.sync = NULL; - } - /* Check for race condition where in sync is established when sync * context was set to NULL. */ + sync = scan->per_scan.sync; if (!sync || sync->timeout_reload) { return BT_HCI_ERR_CMD_DISALLOWED; } + scan->per_scan.sync = NULL; + if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) { + scan_coded->per_scan.sync = NULL; + } + node_rx = (void *)scan->per_scan.node_rx_estab; link_sync_estab = node_rx->hdr.link; link_sync_lost = sync->node_rx_lost.hdr.link;