2 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
3 * Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
5 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
6 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
8 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
9 * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
10 * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
12 * These routines maintain argument size conversion between 32bit and 64bit
16 #include <linux/compat.h>
17 #include <linux/module.h>
18 #include <linux/videodev2.h>
19 #include <linux/v4l2-subdev.h>
20 #include <media/v4l2-dev.h>
21 #include <media/v4l2-ioctl.h>
23 static long native_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
25 long ret
= -ENOIOCTLCMD
;
27 if (file
->f_op
->unlocked_ioctl
)
28 ret
= file
->f_op
->unlocked_ioctl(file
, cmd
, arg
);
39 struct v4l2_window32
{
41 __u32 field
; /* enum v4l2_field */
43 compat_caddr_t clips
; /* actually struct v4l2_clip32 * */
45 compat_caddr_t bitmap
;
49 static int get_v4l2_window32(struct v4l2_window
*kp
, struct v4l2_window32 __user
*up
)
51 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
52 copy_from_user(&kp
->w
, &up
->w
, sizeof(up
->w
)) ||
53 get_user(kp
->field
, &up
->field
) ||
54 get_user(kp
->chromakey
, &up
->chromakey
) ||
55 get_user(kp
->clipcount
, &up
->clipcount
) ||
56 get_user(kp
->global_alpha
, &up
->global_alpha
))
58 if (kp
->clipcount
> 2048)
61 struct v4l2_clip32 __user
*uclips
;
62 struct v4l2_clip __user
*kclips
;
63 int n
= kp
->clipcount
;
66 if (get_user(p
, &up
->clips
))
68 uclips
= compat_ptr(p
);
69 kclips
= compat_alloc_user_space(n
* sizeof(*kclips
));
72 if (copy_in_user(&kclips
->c
, &uclips
->c
, sizeof(uclips
->c
)))
74 if (put_user(n
? kclips
+ 1 : NULL
, &kclips
->next
))
84 static int put_v4l2_window32(struct v4l2_window
*kp
, struct v4l2_window32 __user
*up
)
86 if (copy_to_user(&up
->w
, &kp
->w
, sizeof(kp
->w
)) ||
87 put_user(kp
->field
, &up
->field
) ||
88 put_user(kp
->chromakey
, &up
->chromakey
) ||
89 put_user(kp
->clipcount
, &up
->clipcount
) ||
90 put_user(kp
->global_alpha
, &up
->global_alpha
))
95 struct v4l2_format32
{
96 __u32 type
; /* enum v4l2_buf_type */
98 struct v4l2_pix_format pix
;
99 struct v4l2_pix_format_mplane pix_mp
;
100 struct v4l2_window32 win
;
101 struct v4l2_vbi_format vbi
;
102 struct v4l2_sliced_vbi_format sliced
;
103 struct v4l2_sdr_format sdr
;
104 struct v4l2_meta_format meta
;
105 __u8 raw_data
[200]; /* user-defined */
110 * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument
111 * @index: on return, index of the first created buffer
112 * @count: entry: number of requested buffers,
113 * return: number of created buffers
114 * @memory: buffer memory type
115 * @format: frame format, for which buffers are requested
116 * @reserved: future extensions
118 struct v4l2_create_buffers32
{
121 __u32 memory
; /* enum v4l2_memory */
122 struct v4l2_format32 format
;
126 static int __get_v4l2_format32(struct v4l2_format
*kp
, struct v4l2_format32 __user
*up
)
128 if (get_user(kp
->type
, &up
->type
))
132 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
133 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
134 return copy_from_user(&kp
->fmt
.pix
, &up
->fmt
.pix
,
135 sizeof(kp
->fmt
.pix
)) ? -EFAULT
: 0;
136 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
137 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
138 return copy_from_user(&kp
->fmt
.pix_mp
, &up
->fmt
.pix_mp
,
139 sizeof(kp
->fmt
.pix_mp
)) ? -EFAULT
: 0;
140 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
141 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
142 return get_v4l2_window32(&kp
->fmt
.win
, &up
->fmt
.win
);
143 case V4L2_BUF_TYPE_VBI_CAPTURE
:
144 case V4L2_BUF_TYPE_VBI_OUTPUT
:
145 return copy_from_user(&kp
->fmt
.vbi
, &up
->fmt
.vbi
,
146 sizeof(kp
->fmt
.vbi
)) ? -EFAULT
: 0;
147 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
148 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
149 return copy_from_user(&kp
->fmt
.sliced
, &up
->fmt
.sliced
,
150 sizeof(kp
->fmt
.sliced
)) ? -EFAULT
: 0;
151 case V4L2_BUF_TYPE_SDR_CAPTURE
:
152 case V4L2_BUF_TYPE_SDR_OUTPUT
:
153 return copy_from_user(&kp
->fmt
.sdr
, &up
->fmt
.sdr
,
154 sizeof(kp
->fmt
.sdr
)) ? -EFAULT
: 0;
155 case V4L2_BUF_TYPE_META_CAPTURE
:
156 return copy_from_user(&kp
->fmt
.meta
, &up
->fmt
.meta
,
157 sizeof(kp
->fmt
.meta
)) ? -EFAULT
: 0;
159 pr_info("compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
165 static int get_v4l2_format32(struct v4l2_format
*kp
, struct v4l2_format32 __user
*up
)
167 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)))
169 return __get_v4l2_format32(kp
, up
);
172 static int get_v4l2_create32(struct v4l2_create_buffers
*kp
, struct v4l2_create_buffers32 __user
*up
)
174 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
175 copy_from_user(kp
, up
, offsetof(struct v4l2_create_buffers32
, format
)))
177 return __get_v4l2_format32(&kp
->format
, &up
->format
);
180 static int __put_v4l2_format32(struct v4l2_format
*kp
, struct v4l2_format32 __user
*up
)
182 if (put_user(kp
->type
, &up
->type
))
186 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
187 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
188 return copy_to_user(&up
->fmt
.pix
, &kp
->fmt
.pix
,
189 sizeof(kp
->fmt
.pix
)) ? -EFAULT
: 0;
190 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
:
191 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
:
192 return copy_to_user(&up
->fmt
.pix_mp
, &kp
->fmt
.pix_mp
,
193 sizeof(kp
->fmt
.pix_mp
)) ? -EFAULT
: 0;
194 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
195 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
196 return put_v4l2_window32(&kp
->fmt
.win
, &up
->fmt
.win
);
197 case V4L2_BUF_TYPE_VBI_CAPTURE
:
198 case V4L2_BUF_TYPE_VBI_OUTPUT
:
199 return copy_to_user(&up
->fmt
.vbi
, &kp
->fmt
.vbi
,
200 sizeof(kp
->fmt
.vbi
)) ? -EFAULT
: 0;
201 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
202 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
203 return copy_to_user(&up
->fmt
.sliced
, &kp
->fmt
.sliced
,
204 sizeof(kp
->fmt
.sliced
)) ? -EFAULT
: 0;
205 case V4L2_BUF_TYPE_SDR_CAPTURE
:
206 case V4L2_BUF_TYPE_SDR_OUTPUT
:
207 return copy_to_user(&up
->fmt
.sdr
, &kp
->fmt
.sdr
,
208 sizeof(kp
->fmt
.sdr
)) ? -EFAULT
: 0;
209 case V4L2_BUF_TYPE_META_CAPTURE
:
210 return copy_to_user(&up
->fmt
.meta
, &kp
->fmt
.meta
,
211 sizeof(kp
->fmt
.meta
)) ? -EFAULT
: 0;
213 pr_info("compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
219 static int put_v4l2_format32(struct v4l2_format
*kp
, struct v4l2_format32 __user
*up
)
221 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)))
223 return __put_v4l2_format32(kp
, up
);
226 static int put_v4l2_create32(struct v4l2_create_buffers
*kp
, struct v4l2_create_buffers32 __user
*up
)
228 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
229 copy_to_user(up
, kp
, offsetof(struct v4l2_create_buffers32
, format
)) ||
230 copy_to_user(up
->reserved
, kp
->reserved
, sizeof(kp
->reserved
)))
232 return __put_v4l2_format32(&kp
->format
, &up
->format
);
235 struct v4l2_standard32
{
239 struct v4l2_fract frameperiod
; /* Frames, not fields */
244 static int get_v4l2_standard32(struct v4l2_standard
*kp
, struct v4l2_standard32 __user
*up
)
246 /* other fields are not set by the user, nor used by the driver */
247 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
248 get_user(kp
->index
, &up
->index
))
253 static int put_v4l2_standard32(struct v4l2_standard
*kp
, struct v4l2_standard32 __user
*up
)
255 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
256 put_user(kp
->index
, &up
->index
) ||
257 put_user(kp
->id
, &up
->id
) ||
258 copy_to_user(up
->name
, kp
->name
, sizeof(up
->name
)) ||
259 copy_to_user(&up
->frameperiod
, &kp
->frameperiod
,
260 sizeof(kp
->frameperiod
)) ||
261 put_user(kp
->framelines
, &up
->framelines
) ||
262 copy_to_user(up
->reserved
, kp
->reserved
, sizeof(kp
->reserved
)))
267 struct v4l2_plane32
{
272 compat_long_t userptr
;
279 struct v4l2_buffer32
{
281 __u32 type
; /* enum v4l2_buf_type */
284 __u32 field
; /* enum v4l2_field */
285 struct compat_timeval timestamp
;
286 struct v4l2_timecode timecode
;
289 /* memory location */
290 __u32 memory
; /* enum v4l2_memory */
293 compat_long_t userptr
;
294 compat_caddr_t planes
;
302 static int get_v4l2_plane32(struct v4l2_plane __user
*up
, struct v4l2_plane32 __user
*up32
,
303 enum v4l2_memory memory
)
308 if (copy_in_user(up
, up32
, 2 * sizeof(__u32
)) ||
309 copy_in_user(&up
->data_offset
, &up32
->data_offset
,
310 sizeof(up
->data_offset
)))
314 case V4L2_MEMORY_MMAP
:
315 case V4L2_MEMORY_OVERLAY
:
316 if (copy_in_user(&up
->m
.mem_offset
, &up32
->m
.mem_offset
,
317 sizeof(up32
->m
.mem_offset
)))
320 case V4L2_MEMORY_USERPTR
:
321 if (get_user(p
, &up32
->m
.userptr
))
323 up_pln
= compat_ptr(p
);
324 if (put_user((unsigned long)up_pln
, &up
->m
.userptr
))
327 case V4L2_MEMORY_DMABUF
:
328 if (copy_in_user(&up
->m
.fd
, &up32
->m
.fd
, sizeof(up32
->m
.fd
)))
336 static int put_v4l2_plane32(struct v4l2_plane __user
*up
, struct v4l2_plane32 __user
*up32
,
337 enum v4l2_memory memory
)
341 if (copy_in_user(up32
, up
, 2 * sizeof(__u32
)) ||
342 copy_in_user(&up32
->data_offset
, &up
->data_offset
,
343 sizeof(up
->data_offset
)))
347 case V4L2_MEMORY_MMAP
:
348 case V4L2_MEMORY_OVERLAY
:
349 if (copy_in_user(&up32
->m
.mem_offset
, &up
->m
.mem_offset
,
350 sizeof(up
->m
.mem_offset
)))
353 case V4L2_MEMORY_USERPTR
:
354 if (get_user(p
, &up
->m
.userptr
) ||
355 put_user((compat_ulong_t
)ptr_to_compat((__force
void *)p
),
359 case V4L2_MEMORY_DMABUF
:
360 if (copy_in_user(&up32
->m
.fd
, &up
->m
.fd
,
369 static int get_v4l2_buffer32(struct v4l2_buffer
*kp
, struct v4l2_buffer32 __user
*up
)
371 struct v4l2_plane32 __user
*uplane32
;
372 struct v4l2_plane __user
*uplane
;
376 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
377 get_user(kp
->index
, &up
->index
) ||
378 get_user(kp
->type
, &up
->type
) ||
379 get_user(kp
->flags
, &up
->flags
) ||
380 get_user(kp
->memory
, &up
->memory
) ||
381 get_user(kp
->length
, &up
->length
))
384 if (V4L2_TYPE_IS_OUTPUT(kp
->type
))
385 if (get_user(kp
->bytesused
, &up
->bytesused
) ||
386 get_user(kp
->field
, &up
->field
) ||
387 get_user(kp
->timestamp
.tv_sec
, &up
->timestamp
.tv_sec
) ||
388 get_user(kp
->timestamp
.tv_usec
, &up
->timestamp
.tv_usec
))
391 if (V4L2_TYPE_IS_MULTIPLANAR(kp
->type
)) {
392 unsigned int num_planes
;
394 if (kp
->length
== 0) {
396 /* num_planes == 0 is legal, e.g. when userspace doesn't
397 * need planes array on DQBUF*/
399 } else if (kp
->length
> VIDEO_MAX_PLANES
) {
403 if (get_user(p
, &up
->m
.planes
))
406 uplane32
= compat_ptr(p
);
407 if (!access_ok(VERIFY_READ
, uplane32
,
408 kp
->length
* sizeof(*uplane32
)))
411 /* We don't really care if userspace decides to kill itself
412 * by passing a very big num_planes value */
413 uplane
= compat_alloc_user_space(kp
->length
* sizeof(*uplane
));
414 kp
->m
.planes
= (__force
struct v4l2_plane
*)uplane
;
416 for (num_planes
= 0; num_planes
< kp
->length
; num_planes
++) {
417 ret
= get_v4l2_plane32(uplane
, uplane32
, kp
->memory
);
424 switch (kp
->memory
) {
425 case V4L2_MEMORY_MMAP
:
426 case V4L2_MEMORY_OVERLAY
:
427 if (get_user(kp
->m
.offset
, &up
->m
.offset
))
430 case V4L2_MEMORY_USERPTR
:
434 if (get_user(tmp
, &up
->m
.userptr
))
437 kp
->m
.userptr
= (unsigned long)compat_ptr(tmp
);
440 case V4L2_MEMORY_DMABUF
:
441 if (get_user(kp
->m
.fd
, &up
->m
.fd
))
450 static int put_v4l2_buffer32(struct v4l2_buffer
*kp
, struct v4l2_buffer32 __user
*up
)
452 struct v4l2_plane32 __user
*uplane32
;
453 struct v4l2_plane __user
*uplane
;
458 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
459 put_user(kp
->index
, &up
->index
) ||
460 put_user(kp
->type
, &up
->type
) ||
461 put_user(kp
->flags
, &up
->flags
) ||
462 put_user(kp
->memory
, &up
->memory
))
465 if (put_user(kp
->bytesused
, &up
->bytesused
) ||
466 put_user(kp
->field
, &up
->field
) ||
467 put_user(kp
->timestamp
.tv_sec
, &up
->timestamp
.tv_sec
) ||
468 put_user(kp
->timestamp
.tv_usec
, &up
->timestamp
.tv_usec
) ||
469 copy_to_user(&up
->timecode
, &kp
->timecode
, sizeof(kp
->timecode
)) ||
470 put_user(kp
->sequence
, &up
->sequence
) ||
471 put_user(kp
->reserved2
, &up
->reserved2
) ||
472 put_user(kp
->reserved
, &up
->reserved
) ||
473 put_user(kp
->length
, &up
->length
))
476 if (V4L2_TYPE_IS_MULTIPLANAR(kp
->type
)) {
477 num_planes
= kp
->length
;
481 uplane
= (__force
struct v4l2_plane __user
*)kp
->m
.planes
;
482 if (get_user(p
, &up
->m
.planes
))
484 uplane32
= compat_ptr(p
);
486 while (--num_planes
>= 0) {
487 ret
= put_v4l2_plane32(uplane
, uplane32
, kp
->memory
);
494 switch (kp
->memory
) {
495 case V4L2_MEMORY_MMAP
:
496 case V4L2_MEMORY_OVERLAY
:
497 if (put_user(kp
->m
.offset
, &up
->m
.offset
))
500 case V4L2_MEMORY_USERPTR
:
501 if (put_user(kp
->m
.userptr
, &up
->m
.userptr
))
504 case V4L2_MEMORY_DMABUF
:
505 if (put_user(kp
->m
.fd
, &up
->m
.fd
))
514 struct v4l2_framebuffer32
{
530 static int get_v4l2_framebuffer32(struct v4l2_framebuffer
*kp
, struct v4l2_framebuffer32 __user
*up
)
534 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
535 get_user(tmp
, &up
->base
) ||
536 get_user(kp
->capability
, &up
->capability
) ||
537 get_user(kp
->flags
, &up
->flags
) ||
538 copy_from_user(&kp
->fmt
, &up
->fmt
, sizeof(up
->fmt
)))
540 kp
->base
= (__force
void *)compat_ptr(tmp
);
544 static int put_v4l2_framebuffer32(struct v4l2_framebuffer
*kp
, struct v4l2_framebuffer32 __user
*up
)
546 u32 tmp
= (u32
)((unsigned long)kp
->base
);
548 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
549 put_user(tmp
, &up
->base
) ||
550 put_user(kp
->capability
, &up
->capability
) ||
551 put_user(kp
->flags
, &up
->flags
) ||
552 copy_to_user(&up
->fmt
, &kp
->fmt
, sizeof(up
->fmt
)))
557 struct v4l2_input32
{
558 __u32 index
; /* Which input */
559 __u8 name
[32]; /* Label */
560 __u32 type
; /* Type of input */
561 __u32 audioset
; /* Associated audios (bitfield) */
562 __u32 tuner
; /* Associated tuner */
569 /* The 64-bit v4l2_input struct has extra padding at the end of the struct.
570 Otherwise it is identical to the 32-bit version. */
571 static inline int get_v4l2_input32(struct v4l2_input
*kp
, struct v4l2_input32 __user
*up
)
573 if (copy_from_user(kp
, up
, sizeof(*up
)))
578 static inline int put_v4l2_input32(struct v4l2_input
*kp
, struct v4l2_input32 __user
*up
)
580 if (copy_to_user(up
, kp
, sizeof(*up
)))
585 struct v4l2_ext_controls32
{
590 compat_caddr_t controls
; /* actually struct v4l2_ext_control32 * */
593 struct v4l2_ext_control32
{
600 compat_caddr_t string
; /* actually char * */
602 } __attribute__ ((packed
));
604 /* The following function really belong in v4l2-common, but that causes
605 a circular dependency between modules. We need to think about this, but
606 for now this will do. */
608 /* Return non-zero if this control is a pointer type. Currently only
609 type STRING is a pointer type. */
610 static inline int ctrl_is_pointer(u32 id
)
613 case V4L2_CID_RDS_TX_PS_NAME
:
614 case V4L2_CID_RDS_TX_RADIO_TEXT
:
621 static int get_v4l2_ext_controls32(struct v4l2_ext_controls
*kp
, struct v4l2_ext_controls32 __user
*up
)
623 struct v4l2_ext_control32 __user
*ucontrols
;
624 struct v4l2_ext_control __user
*kcontrols
;
628 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
629 get_user(kp
->which
, &up
->which
) ||
630 get_user(kp
->count
, &up
->count
) ||
631 get_user(kp
->error_idx
, &up
->error_idx
) ||
632 copy_from_user(kp
->reserved
, up
->reserved
, sizeof(kp
->reserved
)))
634 if (kp
->count
== 0) {
637 } else if (kp
->count
> V4L2_CID_MAX_CTRLS
) {
640 if (get_user(p
, &up
->controls
))
642 ucontrols
= compat_ptr(p
);
643 if (!access_ok(VERIFY_READ
, ucontrols
, kp
->count
* sizeof(*ucontrols
)))
645 kcontrols
= compat_alloc_user_space(kp
->count
* sizeof(*kcontrols
));
646 kp
->controls
= (__force
struct v4l2_ext_control
*)kcontrols
;
647 for (n
= 0; n
< kp
->count
; n
++) {
650 if (copy_in_user(kcontrols
, ucontrols
, sizeof(*ucontrols
)))
652 if (get_user(id
, &kcontrols
->id
))
654 if (ctrl_is_pointer(id
)) {
657 if (get_user(p
, &ucontrols
->string
))
660 if (put_user(s
, &kcontrols
->string
))
669 static int put_v4l2_ext_controls32(struct v4l2_ext_controls
*kp
, struct v4l2_ext_controls32 __user
*up
)
671 struct v4l2_ext_control32 __user
*ucontrols
;
672 struct v4l2_ext_control __user
*kcontrols
=
673 (__force
struct v4l2_ext_control __user
*)kp
->controls
;
677 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
678 put_user(kp
->which
, &up
->which
) ||
679 put_user(kp
->count
, &up
->count
) ||
680 put_user(kp
->error_idx
, &up
->error_idx
) ||
681 copy_to_user(up
->reserved
, kp
->reserved
, sizeof(up
->reserved
)))
686 if (get_user(p
, &up
->controls
))
688 ucontrols
= compat_ptr(p
);
689 if (!access_ok(VERIFY_WRITE
, ucontrols
, n
* sizeof(*ucontrols
)))
693 unsigned size
= sizeof(*ucontrols
);
696 if (get_user(id
, &kcontrols
->id
))
698 /* Do not modify the pointer when copying a pointer control.
699 The contents of the pointer was changed, not the pointer
701 if (ctrl_is_pointer(id
))
702 size
-= sizeof(ucontrols
->value64
);
703 if (copy_in_user(ucontrols
, kcontrols
, size
))
711 struct v4l2_event32
{
719 struct compat_timespec timestamp
;
724 static int put_v4l2_event32(struct v4l2_event
*kp
, struct v4l2_event32 __user
*up
)
726 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
727 put_user(kp
->type
, &up
->type
) ||
728 copy_to_user(&up
->u
, &kp
->u
, sizeof(kp
->u
)) ||
729 put_user(kp
->pending
, &up
->pending
) ||
730 put_user(kp
->sequence
, &up
->sequence
) ||
731 put_user(kp
->timestamp
.tv_sec
, &up
->timestamp
.tv_sec
) ||
732 put_user(kp
->timestamp
.tv_nsec
, &up
->timestamp
.tv_nsec
) ||
733 put_user(kp
->id
, &up
->id
) ||
734 copy_to_user(up
->reserved
, kp
->reserved
, sizeof(kp
->reserved
)))
747 static int get_v4l2_edid32(struct v4l2_edid
*kp
, struct v4l2_edid32 __user
*up
)
751 if (!access_ok(VERIFY_READ
, up
, sizeof(*up
)) ||
752 get_user(kp
->pad
, &up
->pad
) ||
753 get_user(kp
->start_block
, &up
->start_block
) ||
754 get_user(kp
->blocks
, &up
->blocks
) ||
755 get_user(tmp
, &up
->edid
) ||
756 copy_from_user(kp
->reserved
, up
->reserved
, sizeof(kp
->reserved
)))
758 kp
->edid
= (__force u8
*)compat_ptr(tmp
);
762 static int put_v4l2_edid32(struct v4l2_edid
*kp
, struct v4l2_edid32 __user
*up
)
764 u32 tmp
= (u32
)((unsigned long)kp
->edid
);
766 if (!access_ok(VERIFY_WRITE
, up
, sizeof(*up
)) ||
767 put_user(kp
->pad
, &up
->pad
) ||
768 put_user(kp
->start_block
, &up
->start_block
) ||
769 put_user(kp
->blocks
, &up
->blocks
) ||
770 put_user(tmp
, &up
->edid
) ||
771 copy_to_user(up
->reserved
, kp
->reserved
, sizeof(up
->reserved
)))
777 #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
778 #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
779 #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
780 #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
781 #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
782 #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
783 #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
784 #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
785 #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
786 #define VIDIOC_G_EDID32 _IOWR('V', 40, struct v4l2_edid32)
787 #define VIDIOC_S_EDID32 _IOWR('V', 41, struct v4l2_edid32)
788 #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
789 #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
790 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
791 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
792 #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
793 #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
794 #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
796 #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
797 #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
798 #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
799 #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
800 #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
801 #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
802 #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
804 static long do_video_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
807 struct v4l2_format v2f
;
808 struct v4l2_buffer v2b
;
809 struct v4l2_framebuffer v2fb
;
810 struct v4l2_input v2i
;
811 struct v4l2_standard v2s
;
812 struct v4l2_ext_controls v2ecs
;
813 struct v4l2_event v2ev
;
814 struct v4l2_create_buffers v2crt
;
815 struct v4l2_edid v2edid
;
819 void __user
*up
= compat_ptr(arg
);
820 int compatible_arg
= 1;
823 /* First, convert the command. */
825 case VIDIOC_G_FMT32
: cmd
= VIDIOC_G_FMT
; break;
826 case VIDIOC_S_FMT32
: cmd
= VIDIOC_S_FMT
; break;
827 case VIDIOC_QUERYBUF32
: cmd
= VIDIOC_QUERYBUF
; break;
828 case VIDIOC_G_FBUF32
: cmd
= VIDIOC_G_FBUF
; break;
829 case VIDIOC_S_FBUF32
: cmd
= VIDIOC_S_FBUF
; break;
830 case VIDIOC_QBUF32
: cmd
= VIDIOC_QBUF
; break;
831 case VIDIOC_DQBUF32
: cmd
= VIDIOC_DQBUF
; break;
832 case VIDIOC_ENUMSTD32
: cmd
= VIDIOC_ENUMSTD
; break;
833 case VIDIOC_ENUMINPUT32
: cmd
= VIDIOC_ENUMINPUT
; break;
834 case VIDIOC_TRY_FMT32
: cmd
= VIDIOC_TRY_FMT
; break;
835 case VIDIOC_G_EXT_CTRLS32
: cmd
= VIDIOC_G_EXT_CTRLS
; break;
836 case VIDIOC_S_EXT_CTRLS32
: cmd
= VIDIOC_S_EXT_CTRLS
; break;
837 case VIDIOC_TRY_EXT_CTRLS32
: cmd
= VIDIOC_TRY_EXT_CTRLS
; break;
838 case VIDIOC_DQEVENT32
: cmd
= VIDIOC_DQEVENT
; break;
839 case VIDIOC_OVERLAY32
: cmd
= VIDIOC_OVERLAY
; break;
840 case VIDIOC_STREAMON32
: cmd
= VIDIOC_STREAMON
; break;
841 case VIDIOC_STREAMOFF32
: cmd
= VIDIOC_STREAMOFF
; break;
842 case VIDIOC_G_INPUT32
: cmd
= VIDIOC_G_INPUT
; break;
843 case VIDIOC_S_INPUT32
: cmd
= VIDIOC_S_INPUT
; break;
844 case VIDIOC_G_OUTPUT32
: cmd
= VIDIOC_G_OUTPUT
; break;
845 case VIDIOC_S_OUTPUT32
: cmd
= VIDIOC_S_OUTPUT
; break;
846 case VIDIOC_CREATE_BUFS32
: cmd
= VIDIOC_CREATE_BUFS
; break;
847 case VIDIOC_PREPARE_BUF32
: cmd
= VIDIOC_PREPARE_BUF
; break;
848 case VIDIOC_G_EDID32
: cmd
= VIDIOC_G_EDID
; break;
849 case VIDIOC_S_EDID32
: cmd
= VIDIOC_S_EDID
; break;
854 case VIDIOC_STREAMON
:
855 case VIDIOC_STREAMOFF
:
857 case VIDIOC_S_OUTPUT
:
858 err
= get_user(karg
.vi
, (s32 __user
*)up
);
863 case VIDIOC_G_OUTPUT
:
869 err
= get_v4l2_edid32(&karg
.v2edid
, up
);
876 err
= get_v4l2_format32(&karg
.v2f
, up
);
880 case VIDIOC_CREATE_BUFS
:
881 err
= get_v4l2_create32(&karg
.v2crt
, up
);
885 case VIDIOC_PREPARE_BUF
:
886 case VIDIOC_QUERYBUF
:
889 err
= get_v4l2_buffer32(&karg
.v2b
, up
);
894 err
= get_v4l2_framebuffer32(&karg
.v2fb
, up
);
903 err
= get_v4l2_standard32(&karg
.v2s
, up
);
907 case VIDIOC_ENUMINPUT
:
908 err
= get_v4l2_input32(&karg
.v2i
, up
);
912 case VIDIOC_G_EXT_CTRLS
:
913 case VIDIOC_S_EXT_CTRLS
:
914 case VIDIOC_TRY_EXT_CTRLS
:
915 err
= get_v4l2_ext_controls32(&karg
.v2ecs
, up
);
926 err
= native_ioctl(file
, cmd
, (unsigned long)up
);
928 mm_segment_t old_fs
= get_fs();
931 err
= native_ioctl(file
, cmd
, (unsigned long)&karg
);
935 /* Special case: even after an error we need to put the
936 results back for these ioctls since the error_idx will
937 contain information on which control failed. */
939 case VIDIOC_G_EXT_CTRLS
:
940 case VIDIOC_S_EXT_CTRLS
:
941 case VIDIOC_TRY_EXT_CTRLS
:
942 if (put_v4l2_ext_controls32(&karg
.v2ecs
, up
))
946 if (put_v4l2_edid32(&karg
.v2edid
, up
))
955 case VIDIOC_S_OUTPUT
:
957 case VIDIOC_G_OUTPUT
:
958 err
= put_user(((s32
)karg
.vi
), (s32 __user
*)up
);
962 err
= put_v4l2_framebuffer32(&karg
.v2fb
, up
);
966 err
= put_v4l2_event32(&karg
.v2ev
, up
);
970 err
= put_v4l2_edid32(&karg
.v2edid
, up
);
976 err
= put_v4l2_format32(&karg
.v2f
, up
);
979 case VIDIOC_CREATE_BUFS
:
980 err
= put_v4l2_create32(&karg
.v2crt
, up
);
983 case VIDIOC_PREPARE_BUF
:
984 case VIDIOC_QUERYBUF
:
987 err
= put_v4l2_buffer32(&karg
.v2b
, up
);
991 err
= put_v4l2_standard32(&karg
.v2s
, up
);
994 case VIDIOC_ENUMINPUT
:
995 err
= put_v4l2_input32(&karg
.v2i
, up
);
1001 long v4l2_compat_ioctl32(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1003 struct video_device
*vdev
= video_devdata(file
);
1004 long ret
= -ENOIOCTLCMD
;
1006 if (!file
->f_op
->unlocked_ioctl
)
1009 if (_IOC_TYPE(cmd
) == 'V' && _IOC_NR(cmd
) < BASE_VIDIOC_PRIVATE
)
1010 ret
= do_video_ioctl(file
, cmd
, arg
);
1011 else if (vdev
->fops
->compat_ioctl32
)
1012 ret
= vdev
->fops
->compat_ioctl32(file
, cmd
, arg
);
1014 if (ret
== -ENOIOCTLCMD
)
1015 pr_debug("compat_ioctl32: unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
1016 _IOC_TYPE(cmd
), _IOC_DIR(cmd
), _IOC_NR(cmd
), cmd
);
1019 EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32
);