public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	"hn.chen" <hn.chen@sunplusit.com>
Subject: Re: [PATCH v7 1/6] media: uvcvideo: Fix underflow addressing on hw timestamp
Date: Fri, 10 Mar 2023 21:18:32 +0900	[thread overview]
Message-ID: <20230310121832.GH1045797@google.com> (raw)
In-Reply-To: <20220920-resend-hwtimestamp-v7-1-cf1d78bb8821@chromium.org>

On (23/03/10 10:01), Ricardo Ribalda wrote:
> If head is 0, we will be addressing clock->samples[-1], which will
> result in undefined behaviour.

[..]

>  	first = &clock->samples[clock->head];
> -	last = &clock->samples[(clock->head - 1) % clock->size];
> +	last = &clock->samples[(clock->head - 1 + clock->size) % clock->size];

Just for visibility:

Per offline discussion with Ricardo, this should not cause a samples[-1]
access, as all arithmetic operations there `unsigned`

    75ef:       41 8d 46 ff             lea    -0x1(%r14),%eax
    75f3:       31 d2                   xor    %edx,%edx
    75f5:       f7 f1                   div    %ecx
    75f7:       41 89 d5                mov    %edx,%r13d

Regardless of that, Ricardo still has a point, there is a bug in the code.

  reply	other threads:[~2023-03-10 12:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10  9:01 [PATCH v7 0/6] uvcvideo: Fixes for hw timestamping Ricardo Ribalda
2023-03-10  9:01 ` [PATCH v7 1/6] media: uvcvideo: Fix underflow addressing on hw timestamp Ricardo Ribalda
2023-03-10 12:18   ` Sergey Senozhatsky [this message]
2023-03-10  9:01 ` [PATCH v7 2/6] media: uvcvideo: Ignore empty TS packets Ricardo Ribalda
2023-03-10  9:01 ` [PATCH v7 3/6] media: uvcvideo: Quirk for invalid dev_sof in Logitech C922 Ricardo Ribalda
2023-03-10  9:01 ` [PATCH v7 4/6] media: uvcvideo: Allow hw clock updates with buffers not full Ricardo Ribalda
2023-03-10  9:01 ` [PATCH v7 5/6] media: uvcvideo: Refactor clock circular buffer Ricardo Ribalda
2023-03-10  9:01 ` [PATCH v7 6/6] media: uvcvideo: Fix hw timestamp handling for slow FPS Ricardo Ribalda
2023-03-15 12:34   ` Sergey Senozhatsky
2023-08-15 11:26 ` [PATCH v7 0/6] uvcvideo: Fixes for hw timestamping Ricardo Ribalda
2023-09-04 11:55   ` Ricardo Ribalda
2023-11-10 10:23     ` Ricardo Ribalda

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=20230310121832.GH1045797@google.com \
    --to=senozhatsky@chromium.org \
    --cc=hn.chen@sunplusit.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.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