fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmocom-bb/+/28549 )
Change subject: trxcon: return prim pointer from l1sched_prim_alloc()
......................................................................
trxcon: return prim pointer from l1sched_prim_alloc()
Returning prim pointer is more convinient from the API point of view.
Change-Id: I0fa41cf55e90d191d032bca1754941cca763b03e
Related: OS#5599, OS#3761
---
M src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h
M src/host/trxcon/src/l1ctl.c
M src/host/trxcon/src/sched_prim.c
3 files changed, 27 insertions(+), 27 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/49/28549/1
diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h
b/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h
index 602d86b..56cd378 100644
--- a/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h
+++ b/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h
@@ -358,8 +358,8 @@
enum l1sched_lchan_type chan);
/* Primitive management functions */
-int l1sched_prim_init(void *ctx, struct l1sched_ts_prim **prim,
- size_t pl_len, uint8_t chan_nr, uint8_t link_id);
+struct l1sched_ts_prim *l1sched_prim_alloc(void *ctx, size_t pl_len,
+ uint8_t chan_nr, uint8_t link_id);
int l1sched_prim_push(struct trx_instance *trx,
struct l1sched_ts_prim *prim, uint8_t chan_nr);
diff --git a/src/host/trxcon/src/l1ctl.c b/src/host/trxcon/src/l1ctl.c
index 980ac49..734fa77 100644
--- a/src/host/trxcon/src/l1ctl.c
+++ b/src/host/trxcon/src/l1ctl.c
@@ -541,9 +541,11 @@
}
/* Init a new primitive */
- rc = l1sched_prim_init(l1l->trx, &prim, len, ul->chan_nr, ul->link_id);
- if (rc)
+ prim = l1sched_prim_alloc(l1l->trx, len, ul->chan_nr, ul->link_id);
+ if (prim == NULL) {
+ rc = -ENOMEM;
goto exit;
+ }
/**
* Push this primitive to the transmit queue.
@@ -724,10 +726,11 @@
chan_nr, link_id, payload_len);
/* Init a new primitive */
- rc = l1sched_prim_init(l1l->trx, &prim, payload_len,
- chan_nr, link_id);
- if (rc)
+ prim = l1sched_prim_alloc(l1l->trx, payload_len, chan_nr, link_id);
+ if (prim == NULL) {
+ rc = -ENOMEM;
goto exit;
+ }
/* Push this primitive to transmit queue */
rc = l1sched_prim_push(l1l->trx, prim, chan_nr);
diff --git a/src/host/trxcon/src/sched_prim.c b/src/host/trxcon/src/sched_prim.c
index 8fae8ac..837c9fa 100644
--- a/src/host/trxcon/src/sched_prim.c
+++ b/src/host/trxcon/src/sched_prim.c
@@ -2,7 +2,8 @@
* OsmocomBB <-> SDR connection bridge
* TDMA scheduler: primitive management
*
- * (C) 2017 by Vadim Yanitskiy <axilirator(a)gmail.com>
+ * (C) 2017-2022 by Vadim Yanitskiy <axilirator(a)gmail.com>
+ * Contributions by sysmocom - s.f.m.c. GmbH
*
* All Rights Reserved
*
@@ -38,17 +39,16 @@
* and filling some meta-information (e.g. lchan type).
*
* @param ctx parent talloc context
- * @param prim external prim pointer (will point to the allocated prim)
* @param pl_len prim payload length
* @param chan_nr RSL channel description (used to set a proper chan)
* @param link_id RSL link description (used to set a proper chan)
- * @return zero in case of success, otherwise a error number
+ * @return allocated primitive or NULL
*/
-int l1sched_prim_init(void *ctx, struct l1sched_ts_prim **prim,
- size_t pl_len, uint8_t chan_nr, uint8_t link_id)
+struct l1sched_ts_prim *l1sched_prim_alloc(void *ctx, size_t pl_len,
+ uint8_t chan_nr, uint8_t link_id)
{
enum l1sched_lchan_type lchan_type;
- struct l1sched_ts_prim *new_prim;
+ struct l1sched_ts_prim *prim;
uint8_t len;
/* Determine lchan type */
@@ -56,7 +56,7 @@
if (!lchan_type) {
LOGP(DSCH, LOGL_ERROR, "Couldn't determine lchan type "
"for chan_nr=%02x and link_id=%02x\n", chan_nr, link_id);
- return -EINVAL;
+ return NULL;
}
/* How much memory do we need? */
@@ -64,20 +64,17 @@
len += pl_len; /* Requested payload size */
/* Allocate a new primitive */
- new_prim = talloc_zero_size(ctx, len);
- if (new_prim == NULL) {
+ prim = talloc_zero_size(ctx, len);
+ if (prim == NULL) {
LOGP(DSCH, LOGL_ERROR, "Failed to allocate memory\n");
- return -ENOMEM;
+ return NULL;
}
/* Init primitive header */
- new_prim->payload_len = pl_len;
- new_prim->chan = lchan_type;
+ prim->payload_len = pl_len;
+ prim->chan = lchan_type;
- /* Set external pointer */
- *prim = new_prim;
-
- return 0;
+ return prim;
}
/**
@@ -129,7 +126,6 @@
struct l1sched_ts_prim *prim;
uint8_t *mr_src_ptr;
bool cached;
- int rc;
/* "Dummy" Measurement Report */
static const uint8_t meas_rep_dummy[] = {
@@ -161,9 +157,10 @@
};
/* Allocate a new primitive */
- rc = l1sched_prim_init(lchan, &prim, GSM_MACBLOCK_LEN,
- l1sched_lchan_desc[lchan->type].chan_nr, L1SCHED_CH_LID_SACCH);
- OSMO_ASSERT(rc == 0);
+ prim = l1sched_prim_alloc(lchan, GSM_MACBLOCK_LEN,
+ l1sched_lchan_desc[lchan->type].chan_nr,
+ L1SCHED_CH_LID_SACCH);
+ OSMO_ASSERT(prim != NULL);
/* Check if the MR cache is populated (verify LAPDm header) */
cached = (lchan->sacch.mr_cache[2] != 0x00
--
To view, visit
https://gerrit.osmocom.org/c/osmocom-bb/+/28549
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I0fa41cf55e90d191d032bca1754941cca763b03e
Gerrit-Change-Number: 28549
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: newchange