mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Petter Selasky <hps@selasky.org>
To: 유용수 <yongsuyoo0215@gmail.com>,
	"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	mchehab@kernel.org
Cc: 0215yys@hanmail.net
Subject: Re: [PATCH] media: dvb_ringbuffer : Fix a bug in dvb_ringbuffer.c
Date: Mon, 12 Sep 2022 14:36:12 +0200	[thread overview]
Message-ID: <baf121ae-a5a4-47a3-bc3a-9255708009b9@selasky.org> (raw)
In-Reply-To: <085b9025-bc23-37d4-d430-afc432b4d783@selasky.org>

Hi Mauro and YongSu,

Answering my own question: The reason nobody has triggered this yet, is 
because the buffer size used is power of two. Because unsigned modulus 
is used, the result becomes correct. See below. But if non-power of two 
ring-buffer is used, then the result becomes incorrect. There is no 
block for non-power of two sized buffers. See:

https://github.com/search?q=dvb_set_pesfilter&type=code

cat << EOF > testX.c
#include <stdio.h>

int
main()
{
int consumed_old;
int consumed_fix;
size_t idx = 3;
ssize_t pread = 15;
ssize_t size = 256;

consumed_old = (idx - pread) % size;

consumed_fix = (idx - pread);
if (consumed_fix < 0)
consumed_fix += size;

printf("old=%d new=%d size=%zd\n", consumed_old, consumed_fix, size);

size = 254;

consumed_old = (idx - pread) % size;

consumed_fix = (idx - pread);
if (consumed_fix < 0)
consumed_fix += size;

printf("old=%d new=%d size=%zd\n", consumed_old, consumed_fix, size);

return (0);
}
EOF

cc testX.c && ./a.out
old=244 new=244 size=256
old=244 new=242 size=254

So either push the suggested fix, or block non-power of two buffer sizes!

Best regards,
--HPS

  parent reply	other threads:[~2022-09-12 12:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
2022-09-13  8:36                     ` 유용수
2022-06-23 10:35 YongSu Yoo
2022-06-26 21:11 ` 유용수
2022-06-30 13:42   ` Hans Petter Selasky
2022-07-07  8:36     ` 유용수
2022-07-25  9:27       ` 유용수

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=baf121ae-a5a4-47a3-bc3a-9255708009b9@selasky.org \
    --to=hps@selasky.org \
    --cc=0215yys@hanmail.net \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=yongsuyoo0215@gmail.com \
    /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

all inboxes | Powered by JetHome®