linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: YongSu Yoo <yongsuyoo0215@gmail.com>
To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	mchehab@kernel.org, hps@selasky.org,
	kieran.bingham@ideasonboard.com
Cc: YongSu Yoo <yongsuyoo0215@gmail.com>
Subject: [PATCH] media: dvb_ringbuffer : Fix a bug in dvb_ringbuffer.c
Date: Thu, 23 Jun 2022 10:35:43 +0000	[thread overview]
Message-ID: <20220623103543.4138-1-yongsuyoo0215@gmail.com> (raw)

Signed-off-by:Yongsu Yoo <yongsuyoo0215@gmail.com>

The function dvb_ringbuffer_pkt_next in
/linux-next/drviers/media/dvb-core/dvb_ringbuffer.c,
which searches the idx of the next valid packet in the ring
buffer of the ca->slot_info[slot].rx_buffer at
/linux-next/drivers/media/dvb-core/dvb_ca_en50221.c,
has the following problem.
In calculating the amounts of the consumed address of the ring
buffer, if the read address(rbuf->pread) of the ring buffer is
smaller than the idx, the amounts of the searched address
should be (idx - rbuf->pread),
whereas if the read address(rbuf->pread) of the ring buffer is
larger than the idx, the amounts of the consumed address should
be (idx - rbuf->pread + rbug->size). But there exists an
incorrect logic that the rbug-size was not properly added on
(idx - rbug->pread) in the later case. With this commit, we
fixed this bug.
---
 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.17.1


             reply	other threads:[~2022-06-23 10:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 10:35 YongSu Yoo [this message]
2022-06-26 21:11 ` [PATCH] media: dvb_ringbuffer : Fix a bug in dvb_ringbuffer.c 유용수
2022-06-30 13:42   ` Hans Petter Selasky
2022-07-07  8:36     ` 유용수
2022-07-25  9:27       ` 유용수
     [not found] <CANXPkT6mYusYe8O0dbq3vW+24SsUZ19PqhOL+wLFRnbFXwu0Zg@mail.gmail.com>
     [not found] ` <CANXPkT7nOhH+5bD0ycyRBT9FKQBBszCVuWkqp4tFtVRf2+8DFg@mail.gmail.com>
2022-06-22 11:39   ` 유용수
2022-06-22 12:33     ` Kieran Bingham
2022-06-22 13:12       ` Hans Petter Selasky
2022-06-23  9:11         ` 유용수
2022-08-03 12:04           ` 유용수
2022-08-18 12:55             ` 유용수
2022-08-31 13:45               ` 유용수
2022-09-09 14:46                 ` Hans Petter Selasky
2022-09-12 12:31                   ` 유용수
2022-09-12 12:36                   ` Hans Petter Selasky
2022-09-13  8:36                     ` 유용수

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220623103543.4138-1-yongsuyoo0215@gmail.com \
    --to=yongsuyoo0215@gmail.com \
    --cc=hps@selasky.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).