From 960dd993cdc16d9e268f83f5c7ca294a96a5048f Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 24 Nov 2016 12:42:25 +0100 Subject: TRX: prevent segfault upon phy init Previously if multiply phy instances were configured but not used osmo-bts-trx would segfault. Terminate with clear error message instead so user can correct configuration. Example configuration which caused problem: ... phy 0 instance 0 instance 1 ... trx 0 phy 0 instance 0 Note the 2nd instance of phy 0 which is not used in trx later on. Change-Id: Id979506731ea92401458f1060e87aeb690901539 --- src/common/scheduler.c | 3 +++ src/osmo-bts-trx/l1_if.c | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/common/scheduler.c b/src/common/scheduler.c index db1f9770..fd5c5840 100644 --- a/src/common/scheduler.c +++ b/src/common/scheduler.c @@ -166,6 +166,9 @@ int trx_sched_init(struct l1sched_trx *l1t, struct gsm_bts_trx *trx) uint8_t tn; unsigned int i; + if (!trx) + return -EINVAL; + l1t->trx = trx; LOGP(DL1C, LOGL_NOTICE, "Init scheduler for trx=%u\n", l1t->trx->nr); diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c index 3d5f52e9..6304c1f5 100644 --- a/src/osmo-bts-trx/l1_if.c +++ b/src/osmo-bts-trx/l1_if.c @@ -71,19 +71,22 @@ struct trx_l1h *l1if_open(struct phy_instance *pinst) return NULL; l1h->phy_inst = pinst; - trx_sched_init(&l1h->l1s, pinst->trx); + rc = trx_sched_init(&l1h->l1s, pinst->trx); + if (rc < 0) { + LOGP(DL1C, LOGL_FATAL, "Cannot initialize scheduler for phy " + "instance %d\n", pinst->num); + return NULL; + } rc = trx_if_open(l1h); if (rc < 0) { - LOGP(DL1C, LOGL_FATAL, "Cannot initialize scheduler\n"); - goto err; + LOGP(DL1C, LOGL_FATAL, "Cannot open TRX interface for phy " + "instance %d\n", pinst->num); + l1if_close(l1h); + return NULL; } return l1h; - -err: - l1if_close(l1h); - return NULL; } void l1if_close(struct trx_l1h *l1h) -- cgit v1.2.3