From 0780f3caea442f6d6be61750b67122a814ba0001 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 15 Jan 2021 10:59:39 +0100 Subject: [PATCH] pdu_queue must be non-blocking in order to avoid the ue or enb to block in the event of a memory leak and the buffer pool running out of buffers. In that case, the null return shall be handled properly and error logged. This commit restores commit c4c44c33f41c0be8c752261c958b4b03e34d02f5. --- lib/src/mac/pdu_queue.cc | 18 ++++++++++-------- srsenb/src/stack/mac/mac.cc | 6 +++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/src/mac/pdu_queue.cc b/lib/src/mac/pdu_queue.cc index bd8628b0e..fa8b201ca 100644 --- a/lib/src/mac/pdu_queue.cc +++ b/lib/src/mac/pdu_queue.cc @@ -27,19 +27,21 @@ uint8_t* pdu_queue::request(uint32_t len) ERROR("Error request buffer of invalid size %d. Max bytes %d\n", len, MAX_PDU_LEN); return NULL; } - pdu_t* pdu = pool.allocate("pdu_queue::request", true); - if (!pdu) { + // This function must be non-blocking. In case we run out of buffers, it shall handle the error properly + pdu_t* pdu = pool.allocate("pdu_queue::request", false); + if (pdu) { + if ((void*)pdu->ptr != (void*)pdu) { + ERROR("Fatal error in memory alignment in struct pdu_queue::pdu_t\n"); + exit(-1); + } + return pdu->ptr; + } else { if (log_h) { log_h->error("Not enough buffers for MAC PDU\n"); } ERROR("Not enough buffers for MAC PDU\n"); + return nullptr; } - if ((void*)pdu->ptr != (void*)pdu) { - ERROR("Fatal error in memory alignment in struct pdu_queue::pdu_t\n"); - exit(-1); - } - - return pdu->ptr; } void pdu_queue::deallocate(const uint8_t* pdu) diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 84d527614..2b7abc3b4 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -907,7 +907,11 @@ int mac::get_ul_sched(uint32_t tti_tx_ul, ul_sched_list_t& ul_sched_res_list) srslte_softbuffer_rx_reset_tbs(phy_ul_sched_res->pusch[n].softbuffer_rx, sched_result.pusch[i].tbs * 8); } phy_ul_sched_res->pusch[n].data = ue_db[rnti]->request_buffer(sched_result.pusch[i].tbs); - phy_ul_sched_res->nof_grants++; + if (phy_ul_sched_res->pusch[n].data) { + phy_ul_sched_res->nof_grants++; + } else { + Error("Grant for rnti=0x%x could not be allocated due to lack of buffers\n", rnti); + } n++; } else { Warning("Invalid UL scheduling result. User 0x%x does not exist\n", rnti);