Re: [PATCH] media: uvcvideo: Silence memcpy() run-time false positive warnings

From: Andy Shevchenko
Date: Tue Feb 07 2023 - 17:07:22 EST


On Mon, Jan 09, 2023 at 11:46:00AM +0100, Ricardo Ribalda wrote:
> Hi Laurent
>
> I was thinking about something on the line of the attached patch,
>
> uvc_frame_header->data could also be replaced with a union.
>
> Warning, not tested ;)

...

> +struct uvc_frame_header {
> + u8 length;
> + u8 flags;
> + u8 data[];
> +} __packed;

__packed! (See below)

...

> + pts = (u32 *) header->data;

Ai-ai-ai.
Here is just a yellow flag...

...

> uvc_dbg(stream->dev, FRAME,
> "%s(): t-sys %lluns, SOF %u, len %u, flags 0x%x, PTS %u, STC %u frame SOF %u\n",
> __func__, ktime_to_ns(time), meta->sof, meta->length,
> meta->flags,
> + has_pts ? *pts : 0,

...and here is a red flag. What you need to have is

void *pts;
u32 pts_val;

pts_val = get_unaligned_be32(); // or le32

...use pts_val...

> + has_scr ? scr->scr : 0,
> + has_scr ? scr->frame_sof & 0x7ff : 0);


--
With Best Regards,
Andy Shevchenko