Change in osmocom-bb[master]: trxcon/l1ctl_link.c: refactor l1ctl_link_init()

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/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Thu Jan 17 12:48:47 UTC 2019


Vadim Yanitskiy has submitted this change and it was merged. ( https://gerrit.osmocom.org/12583 )

Change subject: trxcon/l1ctl_link.c: refactor l1ctl_link_init()
......................................................................

trxcon/l1ctl_link.c: refactor l1ctl_link_init()

The main changes are:

  - return pointer to the allocated l1ctl_link or NULL,
  - accept the talloc context as 'tall_ctx' argument.

Change-Id: I7fe1bc306494ac692c182dcfd2a2d9412929194b
---
M src/host/trxcon/l1ctl_link.c
M src/host/trxcon/l1ctl_link.h
M src/host/trxcon/trxcon.c
3 files changed, 20 insertions(+), 22 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/src/host/trxcon/l1ctl_link.c b/src/host/trxcon/l1ctl_link.c
index 1350c3c..b7ea262 100644
--- a/src/host/trxcon/l1ctl_link.c
+++ b/src/host/trxcon/l1ctl_link.c
@@ -229,59 +229,57 @@
 	return 0;
 }
 
-int l1ctl_link_init(struct l1ctl_link **l1l, const char *sock_path)
+struct l1ctl_link *l1ctl_link_init(void *tall_ctx, const char *sock_path)
 {
-	struct l1ctl_link *l1l_new;
+	struct l1ctl_link *l1l;
 	struct osmo_fd *bfd;
 	int rc;
 
 	LOGP(DL1C, LOGL_NOTICE, "Init L1CTL link (%s)\n", sock_path);
 
-	l1l_new = talloc_zero(tall_trx_ctx, struct l1ctl_link);
-	if (!l1l_new) {
+	l1l = talloc_zero(tall_ctx, struct l1ctl_link);
+	if (!l1l) {
 		LOGP(DL1C, LOGL_ERROR, "Failed to allocate memory\n");
-		return -ENOMEM;
+		return NULL;
 	}
 
 	/* Allocate a new dedicated state machine */
-	l1l_new->fsm = osmo_fsm_inst_alloc(&l1ctl_fsm, l1l_new,
+	l1l->fsm = osmo_fsm_inst_alloc(&l1ctl_fsm, l1l,
 		NULL, LOGL_DEBUG, "l1ctl_link");
-	if (l1l_new->fsm == NULL) {
+	if (l1l->fsm == NULL) {
 		LOGP(DTRX, LOGL_ERROR, "Failed to allocate an instance "
 			"of FSM '%s'\n", l1ctl_fsm.name);
-		talloc_free(l1l_new);
-		return -ENOMEM;
+		talloc_free(l1l);
+		return NULL;
 	}
 
 	/* Create a socket and bind handlers */
-	bfd = &l1l_new->listen_bfd;
+	bfd = &l1l->listen_bfd;
 	rc = osmo_sock_unix_init_ofd(bfd, SOCK_STREAM, 0, sock_path,
 		OSMO_SOCK_F_BIND);
 	if (rc < 0) {
 		LOGP(DL1C, LOGL_ERROR, "Could not create UNIX socket: %s\n",
 			strerror(errno));
-		osmo_fsm_inst_free(l1l_new->fsm);
-		talloc_free(l1l_new);
-		return rc;
+		osmo_fsm_inst_free(l1l->fsm);
+		talloc_free(l1l);
+		return NULL;
 	}
 
 	/* Bind shutdown handler */
-	l1l_new->shutdown_cb = l1ctl_shutdown_cb;
+	l1l->shutdown_cb = l1ctl_shutdown_cb;
 
 	/* Bind connection handler */
 	bfd->cb = l1ctl_link_accept;
 	bfd->when = BSC_FD_READ;
-	bfd->data = l1l_new;
+	bfd->data = l1l;
 
 	/**
 	 * To be able to accept first connection and
 	 * drop others, it should be set to -1
 	 */
-	l1l_new->wq.bfd.fd = -1;
+	l1l->wq.bfd.fd = -1;
 
-	*l1l = l1l_new;
-
-	return 0;
+	return l1l;
 }
 
 void l1ctl_link_shutdown(struct l1ctl_link *l1l)
diff --git a/src/host/trxcon/l1ctl_link.h b/src/host/trxcon/l1ctl_link.h
index 01103dc..da64419 100644
--- a/src/host/trxcon/l1ctl_link.h
+++ b/src/host/trxcon/l1ctl_link.h
@@ -41,7 +41,7 @@
 	void (*shutdown_cb)(struct l1ctl_link *l1l);
 };
 
-int l1ctl_link_init(struct l1ctl_link **l1l, const char *sock_path);
+struct l1ctl_link *l1ctl_link_init(void *tall_ctx, const char *sock_path);
 void l1ctl_link_shutdown(struct l1ctl_link *l1l);
 
 int l1ctl_link_send(struct l1ctl_link *l1l, struct msgb *msg);
diff --git a/src/host/trxcon/trxcon.c b/src/host/trxcon/trxcon.c
index 501d0c7..777138f 100644
--- a/src/host/trxcon/trxcon.c
+++ b/src/host/trxcon/trxcon.c
@@ -279,8 +279,8 @@
 		NULL, LOGL_DEBUG, "main");
 
 	/* Init L1CTL server */
-	rc = l1ctl_link_init(&app_data.l1l, app_data.bind_socket);
-	if (rc)
+	app_data.l1l = l1ctl_link_init(tall_trx_ctx, app_data.bind_socket);
+	if (app_data.l1l == NULL)
 		goto exit;
 
 	/* Init transceiver interface */

-- 
To view, visit https://gerrit.osmocom.org/12583
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7fe1bc306494ac692c182dcfd2a2d9412929194b
Gerrit-Change-Number: 12583
Gerrit-PatchSet: 2
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190117/cfcd8464/attachment.htm>


More information about the gerrit-log mailing list