Re: [PATCH v4 5/8] media: v4l2-core: fix VIDIOC_DQEVENT for time64 ABI
From: Arnd Bergmann
Date: Tue Nov 26 2019 - 10:19:42 EST
On Tue, Nov 26, 2019 at 4:10 PM Hans Verkuil <hverkuil@xxxxxxxxx> wrote:
>
> On 11/26/19 3:43 PM, Arnd Bergmann wrote:
> > On Mon, Nov 25, 2019 at 3:40 PM Hans Verkuil <hverkuil@xxxxxxxxx> wrote:
> >> On 11/11/19 9:38 PM, Arnd Bergmann wrote:
> > struct v4l2_event *ev = parg;
> > struct v4l2_event_time32 ev32 = {
> > .type = ev->type,
> > .pending = ev->pending,
> > .sequence = ev->sequence,
> > .timestamp.tv_sec = ev->timestamp.tv_sec,
> > .timestamp.tv_nsec = ev->timestamp.tv_nsec,
> > .id = ev->id,
> > };
> >
> > memcpy(ev32.u, ev->u, sizeof(ev->u));
> > memcpy(ev32.reserved, ev->reserved, sizeof(ev->reserved));
> >
> > if (copy_to_user(arg, &ev32, sizeof(ev32)))
> > return -EFAULT;
> >
> > Unfortunately this is a little uglier because it still requires the two
> > memcpy() for the arrays, but I think it's good enough.
>
> I agree.
>
> Hmm, can't you do .u = ev->u ? Or is that not allowed by this syntax?
No, that doesn't work here since the two unions are considered
different types despite being defined identically. It would work by
giving the union a name, but that name would also become visible
to user space without adding more hacks.
Arnd