From fe21b2717ceb21aca6f33a07a6b92303e5921077 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Sun, 18 Oct 2020 00:50:29 -0600 Subject: [PATCH] Fix "Comparison is always true because ret >= 0" LGTM warnings ... and refactor out some other dead code in the vacinity of these warnings --- lib/src/phy/ue/ue_cell_search.c | 2 +- lib/src/phy/ue/ue_mib.c | 47 +++++++++++++++++---------------- lib/src/phy/ue/ue_mib_nbiot.c | 46 +++++++++++++++++--------------- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/lib/src/phy/ue/ue_cell_search.c b/lib/src/phy/ue/ue_cell_search.c index 17f0eb45e..e9ea93808 100644 --- a/lib/src/phy/ue/ue_cell_search.c +++ b/lib/src/phy/ue/ue_cell_search.c @@ -265,7 +265,7 @@ int srslte_ue_cellsearch_scan(srslte_ue_cellsearch_t* q, float max_peak_value = -1.0; uint32_t nof_detected_cells = 0; - for (uint32_t N_id_2 = 0; N_id_2 < 3 && ret >= 0; N_id_2++) { + for (uint32_t N_id_2 = 0; N_id_2 < 3; N_id_2++) { INFO("CELL SEARCH: Starting scan for N_id_2=%d\n", N_id_2); ret = srslte_ue_cellsearch_scan_N_id_2(q, N_id_2, &found_cells[N_id_2]); if (ret < 0) { diff --git a/lib/src/phy/ue/ue_mib.c b/lib/src/phy/ue/ue_mib.c index 922ea819e..2b29b280a 100644 --- a/lib/src/phy/ue/ue_mib.c +++ b/lib/src/phy/ue/ue_mib.c @@ -245,29 +245,30 @@ int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t* q, uint32_t nof_frames = 0; int mib_ret = SRSLTE_UE_MIB_NOTFOUND; - if (q != NULL) { - srslte_ue_mib_sync_reset(q); - - ret = SRSLTE_SUCCESS; - do { - mib_ret = SRSLTE_UE_MIB_NOTFOUND; - ret = srslte_ue_sync_zerocopy(&q->ue_sync, q->sf_buffer, MIB_BUFFER_MAX_SAMPLES); - if (ret < 0) { - ERROR("Error calling srslte_ue_sync_work()\n"); - return -1; - } else if (srslte_ue_sync_get_sfidx(&q->ue_sync) == 0) { - if (ret == 1) { - mib_ret = srslte_ue_mib_decode(&q->ue_mib, bch_payload, nof_tx_ports, sfn_offset); - } else { - DEBUG("Resetting PBCH decoder after %d frames\n", q->ue_mib.frame_cnt); - srslte_ue_mib_reset(&q->ue_mib); - } - nof_frames++; - } - } while (mib_ret == SRSLTE_UE_MIB_NOTFOUND && ret >= 0 && nof_frames < max_frames_timeout); - if (mib_ret < 0) { - ret = mib_ret; - } + if (q == NULL) { + return ret; } + + srslte_ue_mib_sync_reset(q); + + do { + mib_ret = SRSLTE_UE_MIB_NOTFOUND; + ret = srslte_ue_sync_zerocopy(&q->ue_sync, q->sf_buffer, MIB_BUFFER_MAX_SAMPLES); + if (ret < 0) { + ERROR("Error calling srslte_ue_sync_work()\n"); + return -1; + } + + if (srslte_ue_sync_get_sfidx(&q->ue_sync) == 0) { + if (ret == 1) { + mib_ret = srslte_ue_mib_decode(&q->ue_mib, bch_payload, nof_tx_ports, sfn_offset); + } else { + DEBUG("Resetting PBCH decoder after %d frames\n", q->ue_mib.frame_cnt); + srslte_ue_mib_reset(&q->ue_mib); + } + nof_frames++; + } + } while (mib_ret == SRSLTE_UE_MIB_NOTFOUND && nof_frames < max_frames_timeout); + return mib_ret; } diff --git a/lib/src/phy/ue/ue_mib_nbiot.c b/lib/src/phy/ue/ue_mib_nbiot.c index 92b967cef..442c90178 100644 --- a/lib/src/phy/ue/ue_mib_nbiot.c +++ b/lib/src/phy/ue/ue_mib_nbiot.c @@ -244,29 +244,31 @@ int srslte_ue_mib_sync_nbiot_decode(srslte_ue_mib_sync_nbiot_t* q, uint32_t* nof_tx_ports, int* sfn_offset) { - int mib_ret = SRSLTE_UE_MIB_NBIOT_NOTFOUND; + int ret = SRSLTE_ERROR_INVALID_INPUTS; + uint32_t nof_frames = 0; + int mib_ret = SRSLTE_UE_MIB_NBIOT_NOTFOUND; - if (q != NULL) { - int ret = SRSLTE_SUCCESS; - uint32_t nof_frames = 0; - do { - mib_ret = SRSLTE_UE_MIB_NBIOT_NOTFOUND; - ret = srslte_ue_sync_nbiot_zerocopy_multi(&q->ue_sync, q->sf_buffer); - if (ret < 0) { - fprintf(stderr, "Error calling srslte_ue_sync_nbiot_zerocopy_multi()\n"); - break; - } else if (srslte_ue_sync_nbiot_get_sfidx(&q->ue_sync) == 0) { - mib_ret = srslte_ue_mib_nbiot_decode(&q->ue_mib, NULL, bch_payload, nof_tx_ports, sfn_offset); - if (mib_ret < 0) { - DEBUG("Resetting NPBCH decoder after %d frames\n", q->ue_mib.frame_cnt); - srslte_ue_mib_nbiot_reset(&q->ue_mib); - } - nof_frames++; - } - } while (mib_ret == SRSLTE_UE_MIB_NBIOT_NOTFOUND && ret >= 0 && nof_frames < max_frames_timeout); - if (mib_ret < 0) { - ret = mib_ret; - } + if (q == NULL) { + return ret; } + + do { + mib_ret = SRSLTE_UE_MIB_NBIOT_NOTFOUND; + ret = srslte_ue_sync_nbiot_zerocopy_multi(&q->ue_sync, q->sf_buffer); + if (ret < 0) { + fprintf(stderr, "Error calling srslte_ue_sync_nbiot_zerocopy_multi()\n"); + break; + } + + if (srslte_ue_sync_nbiot_get_sfidx(&q->ue_sync) == 0) { + mib_ret = srslte_ue_mib_nbiot_decode(&q->ue_mib, NULL, bch_payload, nof_tx_ports, sfn_offset); + if (mib_ret < 0) { + DEBUG("Resetting NPBCH decoder after %d frames\n", q->ue_mib.frame_cnt); + srslte_ue_mib_nbiot_reset(&q->ue_mib); + } + nof_frames++; + } + } while (mib_ret == SRSLTE_UE_MIB_NBIOT_NOTFOUND && nof_frames < max_frames_timeout); + return mib_ret; }