Commit a0df8d94 authored by Ricardo Ribalda's avatar Ricardo Ribalda Committed by Laurent Pinchart

media: uvcvideo: Support timestamp lists of any size

The tail of the list lives at the position before the head. This is
mathematically noted as:
```
(head-1) mod size.
```
Unfortunately C, does not have a modulus operator, but a remainder
operator (%).
The reminder operation has a different result than the modulus if
(head -1) is a negative number and size is not a power of two.

Adding size to (head-1) allows the code to run with any value of size.

This does not change the current behaviour of the driver, as the size is
always a power of two, but avoid tedious debugging if we ever change its
size.
Reviewed-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: default avatarRicardo Ribalda <ribalda@chromium.org>
Reviewed-by: default avatarTomasz Figa <tfiga@chromium.org>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://lore.kernel.org/r/20240323-resend-hwtimestamp-v10-1-b08e590d97c7@chromium.orgSigned-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
parent 91798162
...@@ -732,7 +732,7 @@ void uvc_video_clock_update(struct uvc_streaming *stream, ...@@ -732,7 +732,7 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
goto done; goto done;
first = &clock->samples[clock->head]; first = &clock->samples[clock->head];
last = &clock->samples[(clock->head - 1) % clock->size]; last = &clock->samples[(clock->head - 1 + clock->size) % clock->size];
/* First step, PTS to SOF conversion. */ /* First step, PTS to SOF conversion. */
delta_stc = buf->pts - (1UL << 31); delta_stc = buf->pts - (1UL << 31);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment