[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 May 17 20:06:08 UTC 2017


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: I0d5fcbdd77fe41d78cfe54731dd2ebfc4171f62c
---
M src/host/layer23/include/osmocom/bb/mobile/mncc_sock.h
M src/host/layer23/include/osmocom/bb/mobile/subscriber.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/gsm48_mm.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
12 files changed, 34 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/68/2668/2

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/include/osmocom/bb/mobile/subscriber.h b/src/host/layer23/include/osmocom/bb/mobile/subscriber.h
index ac785d4..8eda027 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/subscriber.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/subscriber.h
@@ -100,7 +100,7 @@
 int gsm_subscr_del_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
 	uint16_t mnc);
 int gsm_subscr_add_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
-					uint16_t mnc, uint8_t cause);
+					uint16_t mnc, uint8_t cause, struct osmocom_ms *ms);
 int gsm_subscr_is_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
 					uint16_t mnc);
 int gsm_subscr_dump_forbidden_plmn(struct osmocom_ms *ms,
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 7dc7208..30f3a67 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 0a18700..594637d 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);
@@ -562,7 +560,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;
@@ -907,7 +905,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;
@@ -2155,7 +2153,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);
@@ -2262,7 +2260,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);
@@ -2483,7 +2481,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;
@@ -2515,8 +2513,8 @@
 }
 
 /* store BA whenever a system informations changes */
-static int gsm322_store_ba_list(struct gsm322_cellsel *cs,
-	struct gsm48_sysinfo *s)
+static int gsm322_store_ba_list(struct osmocom_ms *ms,
+	struct gsm322_cellsel *cs, struct gsm48_sysinfo *s)
 {
 	struct gsm322_ba_list *ba;
 	int i, refer_pcs;
@@ -2525,7 +2523,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 -ENOMEM;
 		ba->mcc = s->mcc;
@@ -2595,7 +2593,7 @@
 	  || (s->si2bis && s->nb_ext_ind_si2 && !s->nb_ext_ind_si2bis)
 	  || (s->si2bis && s->si2ter && s->nb_ext_ind_si2
 		&& s->nb_ext_ind_si2bis)))
-		gsm322_store_ba_list(cs, s);
+		gsm322_store_ba_list(ms, cs, s);
 
 	/* update sel_si, if all relevant system informations received */
 	if (s->si1 && s->si2 && s->si3
@@ -2707,7 +2705,7 @@
 	 && s->si2
 	 && (!s->nb_ext_ind_si2 || s->si2bis)
 	 && (!s->si2ter_ind || s->si2ter))
-		gsm322_store_ba_list(cs, s);
+		gsm322_store_ba_list(ms, cs, s);
 
 	/* all relevant system informations received */
 	if (s->si1 && s->si2 && s->si3
@@ -4087,15 +4085,15 @@
  * neighbour cell measurement process in idle mode
  */
 
-static struct gsm322_neighbour *gsm322_nb_alloc(struct gsm322_cellsel *cs,
-	uint16_t arfcn)
+static struct gsm322_neighbour *gsm322_nb_alloc(struct osmocom_ms *ms,
+	struct gsm322_cellsel *cs, uint16_t arfcn)
 {
 	struct gsm322_neighbour *nb;
 	time_t now;
 
 	time(&now);
 
-	nb = talloc_zero(l23_ctx, struct gsm322_neighbour);
+	nb = talloc_zero(ms, struct gsm322_neighbour);
 	if (!nb)
 		return 0;
 
@@ -4425,8 +4423,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;
@@ -4504,7 +4502,7 @@
 				continue;
 			}
 #endif
-			nb = gsm322_nb_alloc(cs, arfcn);
+			nb = gsm322_nb_alloc(ms, cs, arfcn);
 			LOGP(DNB, LOGL_INFO, "Adding neighbour cell %s to "
 				"list.\n", gsm_print_arfcn(nb->arfcn));
 			if (!(cs->list[index].flags & GSM322_CS_FLAG_SUPPORT))
@@ -4597,7 +4595,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);
@@ -5081,7 +5079,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/gsm48_mm.c b/src/host/layer23/src/mobile/gsm48_mm.c
index 100129b..8f1d3df 100644
--- a/src/host/layer23/src/mobile/gsm48_mm.c
+++ b/src/host/layer23/src/mobile/gsm48_mm.c
@@ -2170,7 +2170,7 @@
 		LOGP(DSUM, LOGL_INFO, "Location updating is disabled by "
 			"configuration\n");
 		gsm_subscr_add_forbidden_plmn(subscr, cs->sel_mcc,
-			cs->sel_mnc, GSM48_REJECT_PLMN_NOT_ALLOWED);
+			cs->sel_mnc, GSM48_REJECT_PLMN_NOT_ALLOWED, ms);
 		msg_type = GSM322_EVENT_REG_FAILED;
 		goto _stop;
 	}
@@ -2632,7 +2632,7 @@
 		break;
 	case GSM48_REJECT_PLMN_NOT_ALLOWED:
 		gsm_subscr_add_forbidden_plmn(subscr, mm->lupd_mcc,
-			mm->lupd_mnc, mm->lupd_rej_cause);
+			mm->lupd_mnc, mm->lupd_rej_cause, ms);
 		LOGP(DSUM, LOGL_INFO, "Location update failed (PLMN not "
 			"allowed)\n");
 		break;
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..22848c0 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];
@@ -1110,7 +1108,7 @@
 
 /* add forbidden PLMN */
 int gsm_subscr_add_forbidden_plmn(struct gsm_subscriber *subscr, uint16_t mcc,
-					uint16_t mnc, uint8_t cause)
+	uint16_t mnc, uint8_t cause, struct osmocom_ms *ms)
 {
 	struct gsm_sub_plmn_na *na;
 
@@ -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(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 d6591d3..271837d 100644
--- a/src/host/layer23/src/mobile/vty_interface.c
+++ b/src/host/layer23/src/mobile/vty_interface.c
@@ -42,8 +42,6 @@
 #include <osmocom/bb/mobile/gsm411_sms.h>
 #include <osmocom/vty/telnet_interface.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);
@@ -2099,7 +2097,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/2668
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0d5fcbdd77fe41d78cfe54731dd2ebfc4171f62c
Gerrit-PatchSet: 2
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list