ns2: Move to one common/shared ns2_bind_alloc()

Avoid code duplication between three different drivers by sharing
the "core" of the bind initialization in a new, shared ns2_bind_alloc().

Change-Id: I535fc68e94fcd695de827dd922706adc1c5a2cb7
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index d4d215c..4f3bc5e 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -1353,4 +1353,36 @@
 	return transfer_cap;
 }
 
+/*! common allocation + low-level initialization of a bind. Called by vc-drivers */
+int ns2_bind_alloc(struct gprs_ns2_inst *nsi, const char *name,
+		   struct gprs_ns2_vc_bind **result)
+{
+	struct gprs_ns2_vc_bind *bind;
+
+	if (!name)
+		return -EINVAL;
+
+	if (gprs_ns2_bind_by_name(nsi, name))
+		return -EALREADY;
+
+	bind = talloc_zero(nsi, struct gprs_ns2_vc_bind);
+	if (!bind)
+		return -ENOSPC;
+
+	bind->name = talloc_strdup(bind, name);
+	if (!bind->name) {
+		talloc_free(bind);
+		return -ENOSPC;
+	}
+
+	bind->nsi = nsi;
+	INIT_LLIST_HEAD(&bind->nsvc);
+	llist_add(&bind->list, &nsi->binding);
+
+	if (result)
+		*result = bind;
+
+	return 0;
+}
+
 /*! @} */