Change in osmo-bts[master]: scheduler_trx.c: avoid division by zero when calculating BER

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Wed Nov 20 13:35:02 UTC 2019


fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bts/+/16067 )

Change subject: scheduler_trx.c: avoid division by zero when calculating BER
......................................................................

scheduler_trx.c: avoid division by zero when calculating BER

There is theoretical risk that when calculating the BER that a division
by zero occurrs. Lets add a check to avoid n_errors / n_bits_total when
n_bits_total is zero.

Change-Id: I1c0731b9a60be4b8c0c84b85b4403168120ceacd
Fixes: CID#205696
---
M src/osmo-bts-trx/loops.c
M src/osmo-bts-trx/loops.h
M src/osmo-bts-trx/scheduler_trx.c
3 files changed, 13 insertions(+), 4 deletions(-)

Approvals:
  fixeria: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/osmo-bts-trx/loops.c b/src/osmo-bts-trx/loops.c
index e73d842..47e9cf3 100644
--- a/src/osmo-bts-trx/loops.c
+++ b/src/osmo-bts-trx/loops.c
@@ -268,11 +268,19 @@
 }
 
 void trx_loop_amr_input(struct l1sched_trx *l1t, uint8_t chan_nr,
-	struct l1sched_chan_state *chan_state, float ber)
+	struct l1sched_chan_state *chan_state,
+	int n_errors, int n_bits_total)
 {
 	struct gsm_bts_trx *trx = l1t->trx;
 	struct gsm_lchan *lchan = &trx->ts[L1SAP_CHAN2TS(chan_nr)]
 					.lchan[l1sap_chan2ss(chan_nr)];
+	float ber;
+
+	/* calculate BER (Bit Error Ratio) */
+	if (n_bits_total == 0)
+		ber = 1.0; /* 100% BER */
+	else
+		ber = (float) n_errors / (float) n_bits_total;
 
 	/* check if loop is enabled */
 	if (!chan_state->amr_loop)
diff --git a/src/osmo-bts-trx/loops.h b/src/osmo-bts-trx/loops.h
index 7869903..978cb7e 100644
--- a/src/osmo-bts-trx/loops.h
+++ b/src/osmo-bts-trx/loops.h
@@ -22,7 +22,8 @@
         struct l1sched_chan_state *chan_state);
 
 void trx_loop_amr_input(struct l1sched_trx *l1t, uint8_t chan_nr,
-        struct l1sched_chan_state *chan_state, float ber);
+	struct l1sched_chan_state *chan_state,
+	int n_errors, int n_bits_total);
 
 void trx_loop_amr_set(struct l1sched_chan_state *chan_state, int loop);
 
diff --git a/src/osmo-bts-trx/scheduler_trx.c b/src/osmo-bts-trx/scheduler_trx.c
index 9945b2c..b54c35b 100644
--- a/src/osmo-bts-trx/scheduler_trx.c
+++ b/src/osmo-bts-trx/scheduler_trx.c
@@ -1215,7 +1215,7 @@
 		if (rc)
 			trx_loop_amr_input(l1t,
 				trx_chan_desc[chan].chan_nr | bi->tn, chan_state,
-				(float)n_errors/(float)n_bits_total);
+				n_errors, n_bits_total);
 		amr = 2; /* we store tch_data + 2 header bytes */
 		/* only good speech frames get rtp header */
 		if (rc != GSM_MACBLOCK_LEN && rc >= 4) {
@@ -1427,7 +1427,7 @@
 		if (rc)
 			trx_loop_amr_input(l1t,
 				trx_chan_desc[chan].chan_nr | bi->tn, chan_state,
-				(float)n_errors/(float)n_bits_total);
+				n_errors, n_bits_total);
 		amr = 2; /* we store tch_data + 2 two */
 		/* only good speech frames get rtp header */
 		if (rc != GSM_MACBLOCK_LEN && rc >= 4) {

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/16067
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I1c0731b9a60be4b8c0c84b85b4403168120ceacd
Gerrit-Change-Number: 16067
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191120/ccd3bd43/attachment.htm>


More information about the gerrit-log mailing list