All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: dvb_ringbuffer: Fix bug in DVB's ringbuffer logic
@ 2022-09-27  7:32 Hans Petter Selasky
  0 siblings, 0 replies; only message in thread
From: Hans Petter Selasky @ 2022-09-27  7:32 UTC (permalink / raw)
  To: linux-media, 유용수

Properly account for negative values when computing the consumed
value for DVB ringbuffers, by adding the size of the ring-buffer.
The modulus is unsigned so no out of bounds is possible, but
dvb_ringbuffer_pkt_next() may fail for CA's at least when the
default buffer size of 65535 bytes is used.

The current logic only works for buffer sizes that are power of two.

Signed-off-by: Yong Su Yoo <yongsuyoo0215@gmail.com>
Signed-off-by: Hans Petter Selasky <hps@selasky.org>
---
  drivers/media/dvb-core/dvb_ringbuffer.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-core/dvb_ringbuffer.c 
b/drivers/media/dvb-core/dvb_ringbuffer.c
index d1d471af0636..7d4558de8e83 100644
--- a/drivers/media/dvb-core/dvb_ringbuffer.c
+++ b/drivers/media/dvb-core/dvb_ringbuffer.c
@@ -335,7 +335,9 @@ ssize_t dvb_ringbuffer_pkt_next(struct 
dvb_ringbuffer *rbuf, size_t idx, size_t*
  		idx = (idx + curpktlen + DVB_RINGBUFFER_PKTHDRSIZE) % rbuf->size;
  	}

-	consumed = (idx - rbuf->pread) % rbuf->size;
+	consumed = (idx - rbuf->pread);
+	if (consumed < 0)
+		consumed += rbuf->size;

  	while((dvb_ringbuffer_avail(rbuf) - consumed) > 
DVB_RINGBUFFER_PKTHDRSIZE) {

-- 
2.37.3

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-27  7:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27  7:32 [PATCH] media: dvb_ringbuffer: Fix bug in DVB's ringbuffer logic Hans Petter Selasky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.