fixeria has submitted this change. ( 
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(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved



diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h 
b/src/host/trxcon/include/osmocom/bb/trxcon/l1sched.h
index b1eee39..cb82cfb 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_alloc(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 0d5bcb9..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_alloc(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_alloc(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 bf36e7a..a8e77fc 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 <[email protected]>
+ * (C) 2017-2022 by Vadim Yanitskiy <[email protected]>
+ * 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_alloc(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_alloc(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: 4
Gerrit-Owner: fixeria <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to