From f3e3a3ac996d40293f933d43ebb0b1a4cd246e9c Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 22 Apr 2021 05:16:41 +0200 Subject: [PATCH] osmo-bts-trx: reduce code nasting in trx_if_send_burst() If the PHY is not powered on and we are not supposed to send any bursts to it, then trx_if_send_burst() should just return early. Change-Id: I578bd5a731ad88ebff283c75bb7eb268d9e7e787 Related: SYS#4895, OS#4941, OS#4006 --- src/osmo-bts-trx/trx_if.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c index 9e2cd751f..18c5011a3 100644 --- a/src/osmo-bts-trx/trx_if.c +++ b/src/osmo-bts-trx/trx_if.c @@ -999,6 +999,13 @@ int trx_if_send_burst(struct trx_l1h *l1h, const struct trx_dl_burst_req *br) uint8_t pdu_ver = l1h->config.trxd_pdu_ver_use; uint8_t *buf = &trx_data_buf[0]; + /* Make sure that the PHY is powered on */ + if (!trx_if_powered(l1h)) { + LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, + "Ignoring Tx data, transceiver is powered off\n"); + return -ENODEV; + } + if ((br->burst_len != GSM_BURST_LEN) && (br->burst_len != EGPRS_BURST_LEN)) { LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Tx burst length %zu invalid\n", br->burst_len); @@ -1027,18 +1034,14 @@ int trx_if_send_burst(struct trx_l1h *l1h, const struct trx_dl_burst_req *br) /* copy ubits {0,1} */ memcpy(buf + 6, br->burst, br->burst_len); - /* we must be sure that TRX is on */ - if (trx_if_powered(l1h)) { - snd_len = send(l1h->trx_ofd_data.fd, trx_data_buf, br->burst_len + 6, 0); - if (snd_len <= 0) { - strerror_r(errno, (char *) trx_data_buf, sizeof(trx_data_buf)); - LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, - "send() failed on TRXD with rc=%zd (%s)\n", - snd_len, trx_data_buf); - return -2; - } - } else - LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Ignoring TX data, transceiver powered off.\n"); + snd_len = send(l1h->trx_ofd_data.fd, trx_data_buf, br->burst_len + 6, 0); + if (snd_len <= 0) { + strerror_r(errno, (char *) trx_data_buf, sizeof(trx_data_buf)); + LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, + "send() failed on TRXD with rc=%zd (%s)\n", + snd_len, trx_data_buf); + return -2; + } return 0; }