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 <piotr.pryga@nordicsemi.no>
This commit is contained in:
Piotr Pryga 2021-02-05 04:23:12 -08:00 committed by Anas Nashif
commit 4b600fcf9a
5 changed files with 16 additions and 10 deletions

View file

@ -295,8 +295,6 @@ struct pdu_adv *lll_adv_pdu_latest_get(struct lll_adv_pdu *pdu,
void *p;
if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &free_idx)) {
LL_ASSERT(false);
return NULL;
}
@ -405,8 +403,6 @@ struct pdu_adv *lll_adv_pdu_and_extra_data_alloc(struct lll_adv_pdu *pdu,
*extra_data = adv_extra_data_allocate(pdu, last);
} else {
if (adv_extra_data_free(pdu, last)) {
LL_ASSERT(false);
/* There is no release of memory allocated by
* adv_pdu_allocate because there is no memory leak.
* 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,
void *p;
if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &pdu_free_idx)) {
LL_ASSERT(false);
return NULL;
}
@ -446,7 +440,6 @@ struct pdu_adv *lll_adv_pdu_and_extra_data_latest_get(struct lll_adv_pdu *pdu,
if (ed && (!MFIFO_ENQUEUE_IDX_GET(extra_data_free,
&ed_free_idx))) {
LL_ASSERT(false);
/* No pdu_free_idx clean up is required, sobsequent
* calls to MFIFO_ENQUEUE_IDX_GET return ther same
* 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)
p = MFIFO_DEQUEUE(pdu_free);
LL_ASSERT(p);
/* If !p then check initial value of sem_pdu_free. It must be the same
* as number of elements in pdu_free store. This may not happen in
* runtime.
*/
pdu->pdu[last] = (void *)p;
@ -701,7 +698,6 @@ static int adv_extra_data_free(struct lll_adv_pdu *pdu, uint8_t last)
if (ed) {
if (!MFIFO_ENQUEUE_IDX_GET(extra_data_free, &ed_free_idx)) {
LL_ASSERT(false);
/* ToDo what if enqueue fails and assert does not fire?
* pdu_free_idx should be released before return.
*/
@ -1212,6 +1208,7 @@ static struct pdu_adv *chan_prepare(struct lll_adv *lll)
/* FIXME: get latest only when primary PDU without Aux PDUs */
upd = 0U;
pdu = lll_adv_data_latest_get(lll, &upd);
LL_ASSERT(pdu);
radio_pkt_tx_set(pdu);
@ -1221,6 +1218,7 @@ static struct pdu_adv *chan_prepare(struct lll_adv *lll)
struct pdu_adv *scan_pdu;
scan_pdu = lll_adv_scan_rsp_latest_get(lll, &upd);
LL_ASSERT(scan_pdu);
#if defined(CONFIG_BT_CTLR_PRIVACY)
if (upd) {

View file

@ -200,6 +200,7 @@ static int prepare_cb(struct lll_prepare_param *p)
/* FIXME: get latest only when primary PDU without Aux PDUs */
sec_pdu = lll_adv_aux_data_latest_get(lll, &upd);
LL_ASSERT(sec_pdu);
/* Get reference to primary PDU */
lll_adv = lll->adv;
@ -270,6 +271,7 @@ static int prepare_cb(struct lll_prepare_param *p)
struct pdu_adv *scan_pdu;
scan_pdu = lll_adv_scan_rsp_latest_get(lll_adv, &upd);
LL_ASSERT(scan_pdu);
#if defined(CONFIG_BT_CTLR_PRIVACY)
if (upd) {
@ -504,6 +506,7 @@ static inline int isr_rx_pdu(struct lll_adv_aux *lll_aux,
pdu_rx = (void *)radio_pkt_scratch_get();
pdu_adv = lll_adv_data_curr_get(lll);
pdu_aux = lll_adv_aux_data_latest_get(lll_aux, &upd);
LL_ASSERT(pdu_aux);
hdr = &pdu_aux->adv_ext_ind.ext_hdr;

View file

@ -154,6 +154,8 @@ static int prepare_cb(struct lll_prepare_param *p)
lll_chan_set(data_chan_use);
pdu = lll_adv_sync_data_latest_get(lll, &extra_data, &upd);
LL_ASSERT(pdu);
#if IS_ENABLED(CONFIG_BT_CTLR_DF_ADV_CTE_TX)
if (extra_data) {
df_cfg = (struct lll_df_adv_cfg *)extra_data;

View file

@ -274,8 +274,6 @@ struct pdu_adv *lll_adv_pdu_latest_get(struct lll_adv_pdu *pdu,
void *p;
if (!MFIFO_ENQUEUE_IDX_GET(pdu_free, &free_idx)) {
LL_ASSERT(false);
return NULL;
}
@ -790,7 +788,9 @@ static void chan_prepare(struct lll_adv *lll)
uint8_t upd = 0U;
pdu = lll_adv_data_latest_get(lll, &upd);
LL_ASSERT(pdu);
scan_pdu = lll_adv_scan_rsp_latest_get(lll, &upd);
LL_ASSERT(scan_pdu);
#if defined(CONFIG_BT_CTLR_PRIVACY)
if (upd) {

View file

@ -195,6 +195,9 @@ uint8_t ll_adv_sync_ad_data_set(uint8_t handle, uint8_t op, uint8_t len,
/* Get reference to new tertiary PDU data buffer */
ter_pdu = lll_adv_sync_data_alloc(lll_sync, NULL, &ter_idx);
if (!ter_pdu) {
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
}
ter_pdu->type = ter_pdu_prev->type;
ter_pdu->rfu = 0U;
ter_pdu->chan_sel = 0U;