[PATCH] osmocom-bb[master]: host/mobile: use osmocom_ms as talloc context

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
Wed Nov 8 11:47:12 UTC 2017


Review at  https://gerrit.osmocom.org/4731

host/mobile: use osmocom_ms as talloc context

As we use talloc, it's absurdly not to use the main feature of
the library - hierarchical memory management. This change sets
talloc context of all sub-allocated objects to related osmocom_ms
instance. So, as soon as osmocom_ms instance is destroyed, all
sub-allocated chunks are getting destroyed too.

Change-Id: I6e3467ff739f3e6dc8dd60cc6d1fcd3f8e490ce9
---
M src/host/layer23/include/osmocom/bb/mobile/mncc_sock.h
M src/host/layer23/src/common/sim.c
M src/host/layer23/src/mobile/app_mobile.c
M src/host/layer23/src/mobile/gsm322.c
M src/host/layer23/src/mobile/gsm48_cc.c
M src/host/layer23/src/mobile/mncc_sock.c
M src/host/layer23/src/mobile/mnccms.c
M src/host/layer23/src/mobile/subscriber.c
M src/host/layer23/src/mobile/transaction.c
M src/host/layer23/src/mobile/vty_interface.c
10 files changed, 23 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/31/4731/1

diff --git a/src/host/layer23/include/osmocom/bb/mobile/mncc_sock.h b/src/host/layer23/include/osmocom/bb/mobile/mncc_sock.h
index b38c5bc..9116ea3 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/mncc_sock.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/mncc_sock.h
@@ -10,7 +10,7 @@
 
 int mncc_sock_from_cc(struct mncc_sock_state *state, struct msgb *msg);
 void mncc_sock_write_pending(struct mncc_sock_state *state);
-struct mncc_sock_state *mncc_sock_init(void *inst, const char *name, void *tall_ctx);
+struct mncc_sock_state *mncc_sock_init(void *inst, const char *name);
 void mncc_sock_exit(struct mncc_sock_state *state);
 
 #endif /* _MNCC_SOCK_H */
diff --git a/src/host/layer23/src/common/sim.c b/src/host/layer23/src/common/sim.c
index 9aad966..c2d6033 100644
--- a/src/host/layer23/src/common/sim.c
+++ b/src/host/layer23/src/common/sim.c
@@ -29,7 +29,6 @@
 #include <osmocom/bb/common/osmocom_data.h>
 #include <osmocom/bb/common/l1ctl.h>
 
-extern void *l23_ctx;
 static int sim_process_job(struct osmocom_ms *ms);
 
 /*
@@ -1181,7 +1180,7 @@
 	struct gsm_sim_handler *handler;
 
 	/* create handler and attach */
-	handler = talloc_zero(l23_ctx, struct gsm_sim_handler);
+	handler = talloc_zero(ms, struct gsm_sim_handler);
 	if (!handler)
 		return 0;
 	handler->handle = new_handle++;
diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c
index 9dbae7c..bd786b5 100644
--- a/src/host/layer23/src/mobile/app_mobile.c
+++ b/src/host/layer23/src/mobile/app_mobile.c
@@ -273,7 +273,7 @@
 		mncc_name = talloc_asprintf(ms, "/tmp/ms_mncc_%s", ms->name);
 
 		ms->mncc_entity.mncc_recv = mncc_recv_app;
-		ms->mncc_entity.sock_state = mncc_sock_init(ms, mncc_name, l23_ctx);
+		ms->mncc_entity.sock_state = mncc_sock_init(ms, mncc_name);
 
 		talloc_free(mncc_name);
 	} else if (ms->settings.ch_cap == GSM_CAP_SDCCH)
diff --git a/src/host/layer23/src/mobile/gsm322.c b/src/host/layer23/src/mobile/gsm322.c
index ad6a83b..8311a44 100644
--- a/src/host/layer23/src/mobile/gsm322.c
+++ b/src/host/layer23/src/mobile/gsm322.c
@@ -45,8 +45,6 @@
 
 const char *ba_version = "osmocom BA V1\n";
 
-extern void *l23_ctx;
-
 static void gsm322_cs_timeout(void *arg);
 static int gsm322_cs_select(struct osmocom_ms *ms, int index, uint16_t mcc,
 	uint16_t mnc, int any);
@@ -560,7 +558,7 @@
 	LOGP(DPLMN, LOGL_INFO, "Add to list of forbidden LAs "
 		"(mcc=%s, mnc=%s, lac=%04x)\n", gsm_print_mcc(mcc),
 		gsm_print_mnc(mnc), lac);
-	la = talloc_zero(l23_ctx, struct gsm322_la_list);
+	la = talloc_zero(ms, struct gsm322_la_list);
 	if (!la)
 		return -ENOMEM;
 	la->mcc = mcc;
@@ -905,7 +903,7 @@
 			if (cs->list[i].rxlev > found->rxlev)
 				found->rxlev = cs->list[i].rxlev;
 		} else {
-			temp = talloc_zero(l23_ctx, struct gsm322_plmn_list);
+			temp = talloc_zero(ms, struct gsm322_plmn_list);
 			if (!temp)
 				return -ENOMEM;
 			temp->mcc = cs->list[i].sysinfo->mcc;
@@ -2153,7 +2151,7 @@
 		cs->arfcn = cs->sel_arfcn;
 		cs->arfci = arfcn2index(cs->arfcn);
 		if (!cs->list[cs->arfci].sysinfo)
-			cs->list[cs->arfci].sysinfo = talloc_zero(l23_ctx,
+			cs->list[cs->arfci].sysinfo = talloc_zero(ms,
 							struct gsm48_sysinfo);
 		if (!cs->list[cs->arfci].sysinfo)
 			exit(-ENOMEM);
@@ -2260,7 +2258,7 @@
 		memset(cs->list[cs->arfci].sysinfo, 0,
 			sizeof(struct gsm48_sysinfo));
 	else
-		cs->list[cs->arfci].sysinfo = talloc_zero(l23_ctx,
+		cs->list[cs->arfci].sysinfo = talloc_zero(ms,
 						struct gsm48_sysinfo);
 	if (!cs->list[cs->arfci].sysinfo)
 		exit(-ENOMEM);
@@ -2481,7 +2479,7 @@
 		/* find or create ba list */
 		ba = gsm322_find_ba_list(cs, s->mcc, s->mnc);
 		if (!ba) {
-			ba = talloc_zero(l23_ctx, struct gsm322_ba_list);
+			ba = talloc_zero(ms, struct gsm322_ba_list);
 			if (!ba)
 				return NULL;
 			ba->mcc = s->mcc;
@@ -2523,7 +2521,7 @@
 	/* find or create ba list */
 	ba = gsm322_find_ba_list(cs, s->mcc, s->mnc);
 	if (!ba) {
-		ba = talloc_zero(l23_ctx, struct gsm322_ba_list);
+		ba = talloc_zero(cs->ms, struct gsm322_ba_list);
 		if (!ba)
 			return -ENOMEM;
 		ba->mcc = s->mcc;
@@ -4093,7 +4091,7 @@
 
 	time(&now);
 
-	nb = talloc_zero(l23_ctx, struct gsm322_neighbour);
+	nb = talloc_zero(cs->ms, struct gsm322_neighbour);
 	if (!nb)
 		return 0;
 
@@ -4423,8 +4421,8 @@
 		memset(cs->list[cs->arfci].sysinfo, 0,
 			sizeof(struct gsm48_sysinfo));
 	else
-		cs->list[cs->arfci].sysinfo = talloc_zero(l23_ctx,
-						struct gsm48_sysinfo);
+		cs->list[cs->arfci].sysinfo = talloc_zero(ms,
+			struct gsm48_sysinfo);
 	if (!cs->list[cs->arfci].sysinfo)
 		exit(-ENOMEM);
 	cs->si = cs->list[cs->arfci].sysinfo;
@@ -4595,7 +4593,7 @@
 			memset(cs->list[cs->arfci].sysinfo, 0,
 				sizeof(struct gsm48_sysinfo));
 		else
-			cs->list[cs->arfci].sysinfo = talloc_zero(l23_ctx,
+			cs->list[cs->arfci].sysinfo = talloc_zero(ms,
 							struct gsm48_sysinfo);
 		if (!cs->list[cs->arfci].sysinfo)
 			exit(-ENOMEM);
@@ -5074,7 +5072,7 @@
 				"stored BA list becomes obsolete.\n");
 		} else
 		while(!feof(fp)) {
-			ba = talloc_zero(l23_ctx, struct gsm322_ba_list);
+			ba = talloc_zero(ms, struct gsm322_ba_list);
 			if (!ba)
 				return -ENOMEM;
 			rc = fread(buf, 4, 1, fp);
diff --git a/src/host/layer23/src/mobile/gsm48_cc.c b/src/host/layer23/src/mobile/gsm48_cc.c
index 38dfab0..d398c76 100644
--- a/src/host/layer23/src/mobile/gsm48_cc.c
+++ b/src/host/layer23/src/mobile/gsm48_cc.c
@@ -38,8 +38,6 @@
 #include <osmocom/bb/mobile/voice.h>
 #include <l1ctl_proto.h>
 
-extern void *l23_ctx;
-
 static int gsm48_cc_tx_release(struct gsm_trans *trans, void *arg);
 static int gsm48_rel_null_free(struct gsm_trans *trans);
 int mncc_release_ind(struct osmocom_ms *ms, struct gsm_trans *trans,
diff --git a/src/host/layer23/src/mobile/mncc_sock.c b/src/host/layer23/src/mobile/mncc_sock.c
index 1e23942..7315927 100644
--- a/src/host/layer23/src/mobile/mncc_sock.c
+++ b/src/host/layer23/src/mobile/mncc_sock.c
@@ -252,13 +252,13 @@
 }
 
 
-struct mncc_sock_state *mncc_sock_init(void *inst, const char *name, void *tall_ctx)
+struct mncc_sock_state *mncc_sock_init(void *inst, const char *name)
 {
 	struct mncc_sock_state *state;
 	struct osmo_fd *bfd;
 	int rc;
 
-	state = talloc_zero(tall_ctx, struct mncc_sock_state);
+	state = talloc_zero(inst, struct mncc_sock_state);
 	if (!state)
 		return NULL;
 
diff --git a/src/host/layer23/src/mobile/mnccms.c b/src/host/layer23/src/mobile/mnccms.c
index d364ca3..b8c2558 100644
--- a/src/host/layer23/src/mobile/mnccms.c
+++ b/src/host/layer23/src/mobile/mnccms.c
@@ -32,7 +32,6 @@
 #include <osmocom/bb/mobile/mncc.h>
 #include <osmocom/bb/mobile/vty.h>
 
-void *l23_ctx;
 static uint32_t new_callref = 1;
 static LLIST_HEAD(call_list);
 
@@ -287,7 +286,7 @@
 	if (!call) {
 		if (llist_empty(&call_list))
 			first_call = 1;
-		call = talloc_zero(l23_ctx, struct gsm_call);
+		call = talloc_zero(ms, struct gsm_call);
 		if (!call)
 			return -ENOMEM;
 		call->ms = ms;
@@ -551,7 +550,7 @@
 		}
 	}
 
-	call = talloc_zero(l23_ctx, struct gsm_call);
+	call = talloc_zero(ms, struct gsm_call);
 	if (!call)
 		return -ENOMEM;
 	call->ms = ms;
diff --git a/src/host/layer23/src/mobile/subscriber.c b/src/host/layer23/src/mobile/subscriber.c
index 455db50..d332a07 100644
--- a/src/host/layer23/src/mobile/subscriber.c
+++ b/src/host/layer23/src/mobile/subscriber.c
@@ -36,8 +36,6 @@
  * if list is changed, the result is not written back to SIM */
 //#define TEST_EMPTY_FPLMN
 
-void *l23_ctx;
-
 static void subscr_sim_query_cb(struct osmocom_ms *ms, struct msgb *msg);
 static void subscr_sim_update_cb(struct osmocom_ms *ms, struct msgb *msg);
 static void subscr_sim_key_cb(struct osmocom_ms *ms, struct msgb *msg);
@@ -400,7 +398,7 @@
 			break;
 
 		/* add to list */
-		plmn = talloc_zero(l23_ctx, struct gsm_sub_plmn_list);
+		plmn = talloc_zero(ms, struct gsm_sub_plmn_list);
 		if (!plmn)
 			return -ENOMEM;
 		lai[0] = data[0];
@@ -504,7 +502,7 @@
 			break;
 
 		/* add to list */
-		na = talloc_zero(l23_ctx, struct gsm_sub_plmn_na);
+		na = talloc_zero(ms, struct gsm_sub_plmn_na);
 		if (!na)
 			return -ENOMEM;
 		lai[0] = data[0];
@@ -1119,7 +1117,7 @@
 
 	LOGP(DPLMN, LOGL_INFO, "Add to list of forbidden PLMNs "
 		"(mcc=%s, mnc=%s)\n", gsm_print_mcc(mcc), gsm_print_mnc(mnc));
-	na = talloc_zero(l23_ctx, struct gsm_sub_plmn_na);
+	na = talloc_zero(subscr->ms, struct gsm_sub_plmn_na);
 	if (!na)
 		return -ENOMEM;
 	na->mcc = mcc;
diff --git a/src/host/layer23/src/mobile/transaction.c b/src/host/layer23/src/mobile/transaction.c
index 45bf2b4..9824bd1 100644
--- a/src/host/layer23/src/mobile/transaction.c
+++ b/src/host/layer23/src/mobile/transaction.c
@@ -30,8 +30,6 @@
 #include <osmocom/bb/mobile/mncc.h>
 #include <osmocom/bb/mobile/transaction.h>
 
-extern void *l23_ctx;
-
 void _gsm48_cc_trans_free(struct gsm_trans *trans);
 void _gsm480_ss_trans_free(struct gsm_trans *trans);
 void _gsm411_sms_trans_free(struct gsm_trans *trans);
@@ -67,7 +65,7 @@
 {
 	struct gsm_trans *trans;
 
-	trans = talloc_zero(l23_ctx, struct gsm_trans);
+	trans = talloc_zero(ms, struct gsm_trans);
 	if (!trans)
 		return NULL;
 
diff --git a/src/host/layer23/src/mobile/vty_interface.c b/src/host/layer23/src/mobile/vty_interface.c
index 0f27194..06f66b5 100644
--- a/src/host/layer23/src/mobile/vty_interface.c
+++ b/src/host/layer23/src/mobile/vty_interface.c
@@ -43,8 +43,6 @@
 #include <osmocom/vty/telnet_interface.h>
 #include <osmocom/vty/misc.h>
 
-void *l23_ctx;
-
 int mncc_call(struct osmocom_ms *ms, char *number);
 int mncc_hangup(struct osmocom_ms *ms);
 int mncc_answer(struct osmocom_ms *ms);
@@ -2104,7 +2102,7 @@
 	if (vty_check_number(vty, argv[1]))
 		return CMD_WARNING;
 
-	abbrev = talloc_zero(l23_ctx, struct gsm_settings_abbrev);
+	abbrev = talloc_zero(ms, struct gsm_settings_abbrev);
 	if (!abbrev) {
 		vty_out(vty, "No Memory!%s", VTY_NEWLINE);
 		return CMD_WARNING;

-- 
To view, visit https://gerrit.osmocom.org/4731
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e3467ff739f3e6dc8dd60cc6d1fcd3f8e490ce9
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list