aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Mädel <t.maedel@alfeld.de>2022-04-09 02:00:09 +0200
committerHarald Welte <laforge@osmocom.org>2022-04-09 13:21:52 +0200
commit480d989d62dcde76f4418b7f3459743fcd6384f9 (patch)
treedde8d474483f7e4ee59ccef4eb68ed03d19051ca /src
parent38b1c5d3f0acc4673187a07c45b95a6b2dadda0c (diff)
RIFO: fix frame_rifo_in check on frame number wrap-around
frame_rifo_in would previously return -ERANGE when a frame was written which was at the edge of the wrap-around of the frame number (because the maximum value was already across the boundary) Also: fixed some typos Change-Id: I88abfc77543d5c64b01f40944b2914e03e57d08f
Diffstat (limited to 'src')
-rw-r--r--src/octoi/e1oip.c2
-rw-r--r--src/octoi/frame_rifo.c6
-rw-r--r--src/octoi/frame_rifo.h7
3 files changed, 12 insertions, 3 deletions
diff --git a/src/octoi/e1oip.c b/src/octoi/e1oip.c
index 176db01..00c671d 100644
--- a/src/octoi/e1oip.c
+++ b/src/octoi/e1oip.c
@@ -98,7 +98,7 @@ static void fifo_threshold_cb(struct frame_fifo *fifo, unsigned int frames, void
rc = frame_fifo_out(&iline->e1o.fifo, buf[i]);
if (rc < 0) {
/* this situation cannot really happen: The FIFO called us that
- * a certain threshold is reached, ubt now it cannot provide
+ * a certain threshold is reached, but now it cannot provide
* frames? */
LOGPEER(iline->peer, LOGL_ERROR,
"frame_fifo_out failure for frame %u/%u\n", iline->e1o.next_seq + i, i);
diff --git a/src/octoi/frame_rifo.c b/src/octoi/frame_rifo.c
index 0ddaae5..fbcbbfa 100644
--- a/src/octoi/frame_rifo.c
+++ b/src/octoi/frame_rifo.c
@@ -106,14 +106,16 @@ void frame_rifo_init(struct frame_rifo *rifo)
* \param rifo The RIFO to which we want to put (append) multiple frames
* \param frame Pointer to memory containing the frame data
* \param fn Absolute frame number at which to insert the frame.
- * \returns 0 on success; -1 on error (overflow */
+ * \returns 0 on success; -1 on error (overflow) */
int frame_rifo_in(struct frame_rifo *rifo, const uint8_t *frame, uint32_t fn)
{
uint32_t bucket;
uint8_t *dst;
- if (fn > frame_rifo_max_in_fn(rifo))
+ if (fn > frame_rifo_max_in_fn(rifo) && fn < frame_rifo_min_in_fn(rifo))
+ {
return -ERANGE;
+ }
bucket = bucket_for_fn(rifo, fn);
dst = rifo->buf + bucket * BYTES_PER_FRAME;
diff --git a/src/octoi/frame_rifo.h b/src/octoi/frame_rifo.h
index 22379ac..f107537 100644
--- a/src/octoi/frame_rifo.h
+++ b/src/octoi/frame_rifo.h
@@ -19,6 +19,13 @@ static inline uint32_t frame_rifo_max_in_fn(const struct frame_rifo *ff)
return ff->next_out_fn + FRAMES_PER_FIFO - 1;
}
+/* minimum frame number we currently can store in the rifo */
+static inline uint32_t frame_rifo_min_in_fn(const struct frame_rifo *ff)
+{
+ return ff->next_out_fn - 1;
+}
+
+
void frame_rifo_init(struct frame_rifo *rifo);
/* number of frames currently available in FIFO */