summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-09-03 01:06:14 +0700
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-09-03 01:06:38 +0700
commit4244519cac088e0748ee159382e503b6c8db198f (patch)
treea47b36e217d2250f407e994f994c902fc8ea11f4
parentfc9d70790042db1887bf6d5ca26a720e4632b34f (diff)
trxcon: trx_if_open(): avoid using talloc_reparent()
For consistency with trxcon_inst_alloc(): * first allocate an instance of trx_fsm as a child of trxcon->fi, * then allocate a trx_instance as a child of the trx_fsm. Change-Id: Iafc486347c6ca7a80da88be73c772397fa2deb7d
-rw-r--r--src/host/trxcon/src/trx_if.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/host/trxcon/src/trx_if.c b/src/host/trxcon/src/trx_if.c
index 5e4e6967..7b1ca99c 100644
--- a/src/host/trxcon/src/trx_if.c
+++ b/src/host/trxcon/src/trx_if.c
@@ -703,24 +703,24 @@ struct trx_instance *trx_if_open(struct trxcon_inst *trxcon,
{
const unsigned int offset = trxcon->id * 2;
struct trx_instance *trx;
+ struct osmo_fsm_inst *fi;
int rc;
LOGPFSML(trxcon->fi, LOGL_NOTICE, "Init transceiver interface "
"(%s:%u/%u)\n", remote_host, base_port, trxcon->id);
- /* Try to allocate memory */
- trx = talloc_zero(trxcon, struct trx_instance);
- if (!trx) {
- LOGPFSML(trxcon->fi, LOGL_ERROR, "Failed to allocate memory\n");
- return NULL;
- }
-
/* Allocate a new dedicated state machine */
- trx->fi = osmo_fsm_inst_alloc_child(&trx_fsm, trxcon->fi, TRXCON_EV_PHYIF_FAILURE);
- if (trx->fi == NULL) {
+ fi = osmo_fsm_inst_alloc_child(&trx_fsm, trxcon->fi, TRXCON_EV_PHYIF_FAILURE);
+ if (fi == NULL) {
LOGPFSML(trxcon->fi, LOGL_ERROR, "Failed to allocate an instance "
"of FSM '%s'\n", trx_fsm.name);
- talloc_free(trx);
+ return NULL;
+ }
+
+ trx = talloc_zero(fi, struct trx_instance);
+ if (!trx) {
+ LOGPFSML(trxcon->fi, LOGL_ERROR, "Failed to allocate memory\n");
+ osmo_fsm_inst_free(fi);
return NULL;
}
@@ -742,18 +742,15 @@ struct trx_instance *trx_if_open(struct trxcon_inst *trxcon,
if (rc < 0)
goto udp_error;
- /* Reparent trx_instance from trxcon to trx->fi */
- talloc_reparent(trxcon, trx->fi, trx);
-
trx->trxcon = trxcon;
- trx->fi->priv = trx;
+ fi->priv = trx;
+ trx->fi = fi;
return trx;
udp_error:
LOGPFSML(trx->fi, LOGL_ERROR, "Couldn't establish UDP connection\n");
osmo_fsm_inst_free(trx->fi);
- talloc_free(trx);
return NULL;
}