From 00b82bc77241b55ef2fda285cbf9e491499c80e5 Mon Sep 17 00:00:00 2001 From: joaquim-SRS Date: Wed, 27 Oct 2021 11:50:27 +0200 Subject: [PATCH] Fix more issues in PHY lib Fix variable shadowing issues in chest_test Fix mutex unlock position in dft_fftw.c CID 371598 Out of bounds access, in ssb_decode_test.c --- lib/src/phy/ch_estimation/test/chest_test_dl.c | 6 +++--- lib/src/phy/ch_estimation/test/chest_test_ul.c | 2 +- lib/src/phy/dft/dft_fftw.c | 4 ++-- lib/src/phy/sync/test/ssb_decode_test.c | 10 +++++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/src/phy/ch_estimation/test/chest_test_dl.c b/lib/src/phy/ch_estimation/test/chest_test_dl.c index 79e358ff4..fffc626e0 100644 --- a/lib/src/phy/ch_estimation/test/chest_test_dl.c +++ b/lib/src/phy/ch_estimation/test/chest_test_dl.c @@ -163,7 +163,7 @@ int main(int argc, char** argv) struct timeval t[3]; gettimeofday(&t[1], NULL); - for (int j = 0; j < 100; j++) { + for (int k = 0; k < 100; k++) { srsran_chest_dl_estimate(&est, &sf_cfg, input_m, &res); } gettimeofday(&t[2], NULL); @@ -171,7 +171,7 @@ int main(int argc, char** argv) printf("CHEST: %f us\n", (float)t[0].tv_usec / 100); gettimeofday(&t[1], NULL); - for (int j = 0; j < 100; j++) { + for (int k = 0; k < 100; k++) { srsran_predecoding_single(input, ce, output, NULL, num_re, 1.0f, 0); } gettimeofday(&t[2], NULL); @@ -186,7 +186,7 @@ int main(int argc, char** argv) printf("MSE: %f\n", mse); gettimeofday(&t[1], NULL); - for (int j = 0; j < 100; j++) { + for (int k = 0; k < 100; k++) { srsran_predecoding_single(input, ce, output, NULL, num_re, 1.0f, res.noise_estimate); } gettimeofday(&t[2], NULL); diff --git a/lib/src/phy/ch_estimation/test/chest_test_ul.c b/lib/src/phy/ch_estimation/test/chest_test_ul.c index 2d729b2f5..d4526212e 100644 --- a/lib/src/phy/ch_estimation/test/chest_test_ul.c +++ b/lib/src/phy/ch_estimation/test/chest_test_ul.c @@ -158,7 +158,7 @@ int main(int argc, char** argv) // Loop through subframe idx and cyclic shifts - for (int sf_idx = 0; sf_idx < 10; sf_idx += 3) { + for (sf_idx = 0; sf_idx < 10; sf_idx += 3) { for (int cshift_dmrs = 0; cshift_dmrs < SRSRAN_NOF_CSHIFT; cshift_dmrs += 5) { if (SRSRAN_VERBOSE_ISINFO()) { printf("nof_prb: %d, ", nof_prb); diff --git a/lib/src/phy/dft/dft_fftw.c b/lib/src/phy/dft/dft_fftw.c index b3f83a8d4..77243f08e 100644 --- a/lib/src/phy/dft/dft_fftw.c +++ b/lib/src/phy/dft/dft_fftw.c @@ -208,11 +208,11 @@ int srsran_dft_plan_guru_c(srsran_dft_plan_t* plan, pthread_mutex_lock(&fft_mutex); plan->p = fftwf_plan_guru_dft(1, &iodim, 1, &howmany_dims, in_buffer, out_buffer, sign, FFTW_TYPE); + pthread_mutex_unlock(&fft_mutex); + if (!plan->p) { - pthread_mutex_unlock(&fft_mutex); return -1; } - pthread_mutex_unlock(&fft_mutex); plan->size = dft_points; plan->init_size = plan->size; diff --git a/lib/src/phy/sync/test/ssb_decode_test.c b/lib/src/phy/sync/test/ssb_decode_test.c index c59982551..9cebbd0a4 100644 --- a/lib/src/phy/sync/test/ssb_decode_test.c +++ b/lib/src/phy/sync/test/ssb_decode_test.c @@ -20,6 +20,14 @@ #include #include +/** + * @brief NR PBCH payload buffer size for the SSB decode test. + * + * @note This needs to be a multiple of 32, since the PBCH message payload is + * generated with srs_random_bit_vector. + */ +#define SRSRAN_PBCH_TEST_MSG_NR_SZ 32 + // NR parameters static uint32_t carrier_nof_prb = 52; static srsran_subcarrier_spacing_t carrier_scs = srsran_subcarrier_spacing_15kHz; @@ -113,7 +121,7 @@ static void gen_pbch_msg(srsran_pbch_msg_nr_t* pbch_msg, uint32_t ssb_idx) SRSRAN_MEM_ZERO(pbch_msg, srsran_pbch_msg_nr_t, 1); // Generate payload - srsran_random_bit_vector(random_gen, pbch_msg->payload, SRSRAN_PBCH_MSG_NR_SZ); + srsran_random_bit_vector(random_gen, pbch_msg->payload, SRSRAN_PBCH_TEST_MSG_NR_SZ); pbch_msg->ssb_idx = ssb_idx; pbch_msg->crc = true;