Skip to content

Commit 4b600fc

Browse files
ppryga-nordicnashif
authored andcommitted
Bluetooth: controller: Remove assert in functions that get latest adv. PDU
Remove LL_ASSERT from functions that return latest advertising PDU. The LL_ASSERT was raised in situation that there is no memory to store unused PDUs memory in a pdu_free queue or extra_data_free queue Those functions return NULL in such sitation. The returned value is verified by callers by LL_ASSERT. That gives better context if lack of memory issue issue occurs. Besides that there was removed a LL_ASSERT from lll_adv_pdu_and_extra_- data_alloc. The reasons is the same as above, to give better context when the lack of memory issue occurs. This function is used in ULL context (ll_adv_sync_ad_data_set). If it returns NULL the caller will return BT_HCI_ERR_MEM_CAPACITY_- EXCEEDED to Host. Signed-off-by: Piotr Pryga <[email protected]>
1 parent cf47d53 commit 4b600fc

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ struct pdu_adv *lll_adv_pdu_latest_get(struct lll_adv_pdu *pdu,
295295
void *p;
296296

297297
if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &free_idx)) {
298-
LL_ASSERT(false);
299-
300298
return NULL;
301299
}
302300

@@ -405,8 +403,6 @@ struct pdu_adv *lll_adv_pdu_and_extra_data_alloc(struct lll_adv_pdu *pdu,
405403
*extra_data = adv_extra_data_allocate(pdu, last);
406404
} else {
407405
if (adv_extra_data_free(pdu, last)) {
408-
LL_ASSERT(false);
409-
410406
/* There is no release of memory allocated by
411407
* adv_pdu_allocate because there is no memory leak.
412408
* If caller can recover from this error and subsequent
@@ -436,8 +432,6 @@ struct pdu_adv *lll_adv_pdu_and_extra_data_latest_get(struct lll_adv_pdu *pdu,
436432
void *p;
437433

438434
if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &pdu_free_idx)) {
439-
LL_ASSERT(false);
440-
441435
return NULL;
442436
}
443437

@@ -446,7 +440,6 @@ struct pdu_adv *lll_adv_pdu_and_extra_data_latest_get(struct lll_adv_pdu *pdu,
446440

447441
if (ed && (!MFIFO_ENQUEUE_IDX_GET(extra_data_free,
448442
&ed_free_idx))) {
449-
LL_ASSERT(false);
450443
/* No pdu_free_idx clean up is required, sobsequent
451444
* calls to MFIFO_ENQUEUE_IDX_GET return ther same
452445
* index to memory that is in limbo state.
@@ -646,6 +639,10 @@ static struct pdu_adv *adv_pdu_allocate(struct lll_adv_pdu *pdu, uint8_t last)
646639

647640
p = MFIFO_DEQUEUE(pdu_free);
648641
LL_ASSERT(p);
642+
/* If !p then check initial value of sem_pdu_free. It must be the same
643+
* as number of elements in pdu_free store. This may not happen in
644+
* runtime.
645+
*/
649646

650647
pdu->pdu[last] = (void *)p;
651648

@@ -701,7 +698,6 @@ static int adv_extra_data_free(struct lll_adv_pdu *pdu, uint8_t last)
701698

702699
if (ed) {
703700
if (!MFIFO_ENQUEUE_IDX_GET(extra_data_free, &ed_free_idx)) {
704-
LL_ASSERT(false);
705701
/* ToDo what if enqueue fails and assert does not fire?
706702
* pdu_free_idx should be released before return.
707703
*/
@@ -1212,6 +1208,7 @@ static struct pdu_adv *chan_prepare(struct lll_adv *lll)
12121208
/* FIXME: get latest only when primary PDU without Aux PDUs */
12131209
upd = 0U;
12141210
pdu = lll_adv_data_latest_get(lll, &upd);
1211+
LL_ASSERT(pdu);
12151212

12161213
radio_pkt_tx_set(pdu);
12171214

@@ -1221,6 +1218,7 @@ static struct pdu_adv *chan_prepare(struct lll_adv *lll)
12211218
struct pdu_adv *scan_pdu;
12221219

12231220
scan_pdu = lll_adv_scan_rsp_latest_get(lll, &upd);
1221+
LL_ASSERT(scan_pdu);
12241222

12251223
#if defined(CONFIG_BT_CTLR_PRIVACY)
12261224
if (upd) {

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static int prepare_cb(struct lll_prepare_param *p)
200200

201201
/* FIXME: get latest only when primary PDU without Aux PDUs */
202202
sec_pdu = lll_adv_aux_data_latest_get(lll, &upd);
203+
LL_ASSERT(sec_pdu);
203204

204205
/* Get reference to primary PDU */
205206
lll_adv = lll->adv;
@@ -270,6 +271,7 @@ static int prepare_cb(struct lll_prepare_param *p)
270271
struct pdu_adv *scan_pdu;
271272

272273
scan_pdu = lll_adv_scan_rsp_latest_get(lll_adv, &upd);
274+
LL_ASSERT(scan_pdu);
273275

274276
#if defined(CONFIG_BT_CTLR_PRIVACY)
275277
if (upd) {
@@ -504,6 +506,7 @@ static inline int isr_rx_pdu(struct lll_adv_aux *lll_aux,
504506
pdu_rx = (void *)radio_pkt_scratch_get();
505507
pdu_adv = lll_adv_data_curr_get(lll);
506508
pdu_aux = lll_adv_aux_data_latest_get(lll_aux, &upd);
509+
LL_ASSERT(pdu_aux);
507510

508511
hdr = &pdu_aux->adv_ext_ind.ext_hdr;
509512

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static int prepare_cb(struct lll_prepare_param *p)
154154
lll_chan_set(data_chan_use);
155155

156156
pdu = lll_adv_sync_data_latest_get(lll, &extra_data, &upd);
157+
LL_ASSERT(pdu);
158+
157159
#if IS_ENABLED(CONFIG_BT_CTLR_DF_ADV_CTE_TX)
158160
if (extra_data) {
159161
df_cfg = (struct lll_df_adv_cfg *)extra_data;

subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ struct pdu_adv *lll_adv_pdu_latest_get(struct lll_adv_pdu *pdu,
274274
void *p;
275275

276276
if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &free_idx)) {
277-
LL_ASSERT(false);
278-
279277
return NULL;
280278
}
281279

@@ -790,7 +788,9 @@ static void chan_prepare(struct lll_adv *lll)
790788
uint8_t upd = 0U;
791789

792790
pdu = lll_adv_data_latest_get(lll, &upd);
791+
LL_ASSERT(pdu);
793792
scan_pdu = lll_adv_scan_rsp_latest_get(lll, &upd);
793+
LL_ASSERT(scan_pdu);
794794

795795
#if defined(CONFIG_BT_CTLR_PRIVACY)
796796
if (upd) {

subsys/bluetooth/controller/ll_sw/ull_adv_sync.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ uint8_t ll_adv_sync_ad_data_set(uint8_t handle, uint8_t op, uint8_t len,
195195

196196
/* Get reference to new tertiary PDU data buffer */
197197
ter_pdu = lll_adv_sync_data_alloc(lll_sync, NULL, &ter_idx);
198+
if (!ter_pdu) {
199+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
200+
}
198201
ter_pdu->type = ter_pdu_prev->type;
199202
ter_pdu->rfu = 0U;
200203
ter_pdu->chan_sel = 0U;

0 commit comments

Comments
 (0)