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 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
18 #include <linux/videodev.h>
19 #include <linux/videodev2.h>
20 #include <linux/module.h>
21 #include <linux/smp_lock.h>
22 #include <media/v4l2-ioctl.h>
26 #ifdef CONFIG_VIDEO_V4L1_COMPAT
27 struct video_tuner32
{
30 compat_ulong_t rangelow
, rangehigh
;
31 u32 flags
; /* It is really u32 in videodev.h */
35 static int get_video_tuner32(struct video_tuner
*kp
, struct video_tuner32 __user
*up
)
37 if (!access_ok(VERIFY_READ
, up
, sizeof(struct video_tuner32
)) ||
38 get_user(kp
->tuner
, &up
->tuner
) ||
39 copy_from_user(kp
->name
, up
->name
, 32) ||
40 get_user(kp
->rangelow
, &up
->rangelow
) ||
41 get_user(kp
->rangehigh
, &up
->rangehigh
) ||
42 get_user(kp
->flags
, &up
->flags
) ||
43 get_user(kp
->mode
, &up
->mode
) ||
44 get_user(kp
->signal
, &up
->signal
))
49 static int put_video_tuner32(struct video_tuner
*kp
, struct video_tuner32 __user
*up
)
51 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct video_tuner32
)) ||
52 put_user(kp
->tuner
, &up
->tuner
) ||
53 copy_to_user(up
->name
, kp
->name
, 32) ||
54 put_user(kp
->rangelow
, &up
->rangelow
) ||
55 put_user(kp
->rangehigh
, &up
->rangehigh
) ||
56 put_user(kp
->flags
, &up
->flags
) ||
57 put_user(kp
->mode
, &up
->mode
) ||
58 put_user(kp
->signal
, &up
->signal
))
63 struct video_buffer32
{
65 compat_int_t height
, width
, depth
, bytesperline
;
68 static int get_video_buffer32(struct video_buffer
*kp
, struct video_buffer32 __user
*up
)
72 if (!access_ok(VERIFY_READ
, up
, sizeof(struct video_buffer32
)) ||
73 get_user(tmp
, &up
->base
) ||
74 get_user(kp
->height
, &up
->height
) ||
75 get_user(kp
->width
, &up
->width
) ||
76 get_user(kp
->depth
, &up
->depth
) ||
77 get_user(kp
->bytesperline
, &up
->bytesperline
))
80 /* This is actually a physical address stored
83 kp
->base
= (void *)(unsigned long) tmp
;
88 static int put_video_buffer32(struct video_buffer
*kp
, struct video_buffer32 __user
*up
)
90 u32 tmp
= (u32
)((unsigned long)kp
->base
);
92 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct video_buffer32
)) ||
93 put_user(tmp
, &up
->base
) ||
94 put_user(kp
->height
, &up
->height
) ||
95 put_user(kp
->width
, &up
->width
) ||
96 put_user(kp
->depth
, &up
->depth
) ||
97 put_user(kp
->bytesperline
, &up
->bytesperline
))
102 struct video_clip32
{
103 s32 x
, y
, width
, height
; /* It's really s32 in videodev.h */
107 struct video_window32
{
108 u32 x
, y
, width
, height
, chromakey
, flags
;
109 compat_caddr_t clips
;
110 compat_int_t clipcount
;
113 static int get_video_window32(struct video_window
*kp
, struct video_window32 __user
*up
)
115 struct video_clip __user
*uclips
;
116 struct video_clip __user
*kclips
;
120 if (!access_ok(VERIFY_READ
, up
, sizeof(struct video_window32
)))
123 if (get_user(nclips
, &up
->clipcount
))
126 if (!access_ok(VERIFY_READ
, up
, sizeof(struct video_window32
)) ||
127 get_user(kp
->x
, &up
->x
) ||
128 get_user(kp
->y
, &up
->y
) ||
129 get_user(kp
->width
, &up
->width
) ||
130 get_user(kp
->height
, &up
->height
) ||
131 get_user(kp
->chromakey
, &up
->chromakey
) ||
132 get_user(kp
->flags
, &up
->flags
) ||
133 get_user(kp
->clipcount
, &up
->clipcount
))
136 nclips
= kp
->clipcount
;
141 if (get_user(p
, &up
->clips
))
143 uclips
= compat_ptr(p
);
145 /* If nclips < 0, then it is a clipping bitmap of size
146 VIDEO_CLIPMAP_SIZE */
148 if (!access_ok(VERIFY_READ
, uclips
, VIDEO_CLIPMAP_SIZE
))
150 kp
->clips
= compat_alloc_user_space(VIDEO_CLIPMAP_SIZE
);
151 if (copy_in_user(kp
->clips
, uclips
, VIDEO_CLIPMAP_SIZE
))
156 /* Otherwise it is an array of video_clip structs. */
157 if (!access_ok(VERIFY_READ
, uclips
, nclips
* sizeof(struct video_clip
)))
160 kp
->clips
= compat_alloc_user_space(nclips
* sizeof(struct video_clip
));
165 err
= copy_in_user(&kclips
->x
, &uclips
->x
, sizeof(kclips
->x
));
166 err
|= copy_in_user(&kclips
->y
, &uclips
->y
, sizeof(kclips
->y
));
167 err
|= copy_in_user(&kclips
->width
, &uclips
->width
, sizeof(kclips
->width
));
168 err
|= copy_in_user(&kclips
->height
, &uclips
->height
, sizeof(kclips
->height
));
178 /* You get back everything except the clips... */
179 static int put_video_window32(struct video_window
*kp
, struct video_window32 __user
*up
)
181 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct video_window32
)) ||
182 put_user(kp
->x
, &up
->x
) ||
183 put_user(kp
->y
, &up
->y
) ||
184 put_user(kp
->width
, &up
->width
) ||
185 put_user(kp
->height
, &up
->height
) ||
186 put_user(kp
->chromakey
, &up
->chromakey
) ||
187 put_user(kp
->flags
, &up
->flags
) ||
188 put_user(kp
->clipcount
, &up
->clipcount
))
193 struct video_code32
{
194 char loadwhat
[16]; /* name or tag of file being passed */
195 compat_int_t datasize
;
199 static int get_microcode32(struct video_code
*kp
, struct video_code32 __user
*up
)
201 if (!access_ok(VERIFY_READ
, up
, sizeof(struct video_code32
)) ||
202 copy_from_user(kp
->loadwhat
, up
->loadwhat
, sizeof(up
->loadwhat
)) ||
203 get_user(kp
->datasize
, &up
->datasize
) ||
204 copy_from_user(kp
->data
, up
->data
, up
->datasize
))
209 #define VIDIOCGTUNER32 _IOWR('v', 4, struct video_tuner32)
210 #define VIDIOCSTUNER32 _IOW('v', 5, struct video_tuner32)
211 #define VIDIOCGWIN32 _IOR('v', 9, struct video_window32)
212 #define VIDIOCSWIN32 _IOW('v', 10, struct video_window32)
213 #define VIDIOCGFBUF32 _IOR('v', 11, struct video_buffer32)
214 #define VIDIOCSFBUF32 _IOW('v', 12, struct video_buffer32)
215 #define VIDIOCGFREQ32 _IOR('v', 14, u32)
216 #define VIDIOCSFREQ32 _IOW('v', 15, u32)
217 #define VIDIOCSMICROCODE32 _IOW('v', 27, struct video_code32)
219 #define VIDIOCCAPTURE32 _IOW('v', 8, s32)
220 #define VIDIOCSYNC32 _IOW('v', 18, s32)
221 #define VIDIOCSWRITEMODE32 _IOW('v', 25, s32)
225 static long native_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
227 long ret
= -ENOIOCTLCMD
;
229 if (file
->f_op
->unlocked_ioctl
)
230 ret
= file
->f_op
->unlocked_ioctl(file
, cmd
, arg
);
241 struct v4l2_window32
{
243 enum v4l2_field field
;
245 compat_caddr_t clips
; /* actually struct v4l2_clip32 * */
247 compat_caddr_t bitmap
;
250 static int get_v4l2_window32(struct v4l2_window
*kp
, struct v4l2_window32 __user
*up
)
252 if (!access_ok(VERIFY_READ
, up
, sizeof(struct v4l2_window32
)) ||
253 copy_from_user(&kp
->w
, &up
->w
, sizeof(up
->w
)) ||
254 get_user(kp
->field
, &up
->field
) ||
255 get_user(kp
->chromakey
, &up
->chromakey
) ||
256 get_user(kp
->clipcount
, &up
->clipcount
))
258 if (kp
->clipcount
> 2048)
261 struct v4l2_clip32 __user
*uclips
;
262 struct v4l2_clip __user
*kclips
;
263 int n
= kp
->clipcount
;
266 if (get_user(p
, &up
->clips
))
268 uclips
= compat_ptr(p
);
269 kclips
= compat_alloc_user_space(n
* sizeof(struct v4l2_clip
));
272 if (copy_in_user(&kclips
->c
, &uclips
->c
, sizeof(uclips
->c
)))
274 if (put_user(n
? kclips
+ 1 : NULL
, &kclips
->next
))
284 static int put_v4l2_window32(struct v4l2_window
*kp
, struct v4l2_window32 __user
*up
)
286 if (copy_to_user(&up
->w
, &kp
->w
, sizeof(kp
->w
)) ||
287 put_user(kp
->field
, &up
->field
) ||
288 put_user(kp
->chromakey
, &up
->chromakey
) ||
289 put_user(kp
->clipcount
, &up
->clipcount
))
294 static inline int get_v4l2_pix_format(struct v4l2_pix_format
*kp
, struct v4l2_pix_format __user
*up
)
296 if (copy_from_user(kp
, up
, sizeof(struct v4l2_pix_format
)))
301 static inline int put_v4l2_pix_format(struct v4l2_pix_format
*kp
, struct v4l2_pix_format __user
*up
)
303 if (copy_to_user(up
, kp
, sizeof(struct v4l2_pix_format
)))
308 static inline int get_v4l2_vbi_format(struct v4l2_vbi_format
*kp
, struct v4l2_vbi_format __user
*up
)
310 if (copy_from_user(kp
, up
, sizeof(struct v4l2_vbi_format
)))
315 static inline int put_v4l2_vbi_format(struct v4l2_vbi_format
*kp
, struct v4l2_vbi_format __user
*up
)
317 if (copy_to_user(up
, kp
, sizeof(struct v4l2_vbi_format
)))
322 static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format
*kp
, struct v4l2_sliced_vbi_format __user
*up
)
324 if (copy_from_user(kp
, up
, sizeof(struct v4l2_sliced_vbi_format
)))
329 static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format
*kp
, struct v4l2_sliced_vbi_format __user
*up
)
331 if (copy_to_user(up
, kp
, sizeof(struct v4l2_sliced_vbi_format
)))
336 struct v4l2_format32
{
337 enum v4l2_buf_type type
;
339 struct v4l2_pix_format pix
;
340 struct v4l2_window32 win
;
341 struct v4l2_vbi_format vbi
;
342 struct v4l2_sliced_vbi_format sliced
;
343 __u8 raw_data
[200]; /* user-defined */
347 static int get_v4l2_format32(struct v4l2_format
*kp
, struct v4l2_format32 __user
*up
)
349 if (!access_ok(VERIFY_READ
, up
, sizeof(struct v4l2_format32
)) ||
350 get_user(kp
->type
, &up
->type
))
353 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
354 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
355 return get_v4l2_pix_format(&kp
->fmt
.pix
, &up
->fmt
.pix
);
356 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
357 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
358 return get_v4l2_window32(&kp
->fmt
.win
, &up
->fmt
.win
);
359 case V4L2_BUF_TYPE_VBI_CAPTURE
:
360 case V4L2_BUF_TYPE_VBI_OUTPUT
:
361 return get_v4l2_vbi_format(&kp
->fmt
.vbi
, &up
->fmt
.vbi
);
362 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
363 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
364 return get_v4l2_sliced_vbi_format(&kp
->fmt
.sliced
, &up
->fmt
.sliced
);
365 case V4L2_BUF_TYPE_PRIVATE
:
366 if (copy_from_user(kp
, up
, sizeof(kp
->fmt
.raw_data
)))
372 printk(KERN_INFO
"compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
378 static int put_v4l2_format32(struct v4l2_format
*kp
, struct v4l2_format32 __user
*up
)
380 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct v4l2_format32
)) ||
381 put_user(kp
->type
, &up
->type
))
384 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
385 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
386 return put_v4l2_pix_format(&kp
->fmt
.pix
, &up
->fmt
.pix
);
387 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
388 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
:
389 return put_v4l2_window32(&kp
->fmt
.win
, &up
->fmt
.win
);
390 case V4L2_BUF_TYPE_VBI_CAPTURE
:
391 case V4L2_BUF_TYPE_VBI_OUTPUT
:
392 return put_v4l2_vbi_format(&kp
->fmt
.vbi
, &up
->fmt
.vbi
);
393 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
:
394 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
:
395 return put_v4l2_sliced_vbi_format(&kp
->fmt
.sliced
, &up
->fmt
.sliced
);
396 case V4L2_BUF_TYPE_PRIVATE
:
397 if (copy_to_user(up
, kp
, sizeof(up
->fmt
.raw_data
)))
403 printk(KERN_INFO
"compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
409 struct v4l2_standard32
{
411 __u32 id
[2]; /* __u64 would get the alignment wrong */
413 struct v4l2_fract frameperiod
; /* Frames, not fields */
418 static int get_v4l2_standard32(struct v4l2_standard
*kp
, struct v4l2_standard32 __user
*up
)
420 /* other fields are not set by the user, nor used by the driver */
421 if (!access_ok(VERIFY_READ
, up
, sizeof(struct v4l2_standard32
)) ||
422 get_user(kp
->index
, &up
->index
))
427 static int put_v4l2_standard32(struct v4l2_standard
*kp
, struct v4l2_standard32 __user
*up
)
429 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct v4l2_standard32
)) ||
430 put_user(kp
->index
, &up
->index
) ||
431 copy_to_user(up
->id
, &kp
->id
, sizeof(__u64
)) ||
432 copy_to_user(up
->name
, kp
->name
, 24) ||
433 copy_to_user(&up
->frameperiod
, &kp
->frameperiod
, sizeof(kp
->frameperiod
)) ||
434 put_user(kp
->framelines
, &up
->framelines
) ||
435 copy_to_user(up
->reserved
, kp
->reserved
, 4 * sizeof(__u32
)))
440 struct v4l2_buffer32
{
442 enum v4l2_buf_type type
;
445 enum v4l2_field field
;
446 struct compat_timeval timestamp
;
447 struct v4l2_timecode timecode
;
450 /* memory location */
451 enum v4l2_memory memory
;
454 compat_long_t userptr
;
461 static int get_v4l2_buffer32(struct v4l2_buffer
*kp
, struct v4l2_buffer32 __user
*up
)
464 if (!access_ok(VERIFY_READ
, up
, sizeof(struct v4l2_buffer32
)) ||
465 get_user(kp
->index
, &up
->index
) ||
466 get_user(kp
->type
, &up
->type
) ||
467 get_user(kp
->flags
, &up
->flags
) ||
468 get_user(kp
->memory
, &up
->memory
) ||
469 get_user(kp
->input
, &up
->input
))
471 switch (kp
->memory
) {
472 case V4L2_MEMORY_MMAP
:
473 if (get_user(kp
->length
, &up
->length
) ||
474 get_user(kp
->m
.offset
, &up
->m
.offset
))
477 case V4L2_MEMORY_USERPTR
:
481 if (get_user(kp
->length
, &up
->length
) ||
482 get_user(tmp
, &up
->m
.userptr
))
485 kp
->m
.userptr
= (unsigned long)compat_ptr(tmp
);
488 case V4L2_MEMORY_OVERLAY
:
489 if (get_user(kp
->m
.offset
, &up
->m
.offset
))
496 static int put_v4l2_buffer32(struct v4l2_buffer
*kp
, struct v4l2_buffer32 __user
*up
)
498 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct v4l2_buffer32
)) ||
499 put_user(kp
->index
, &up
->index
) ||
500 put_user(kp
->type
, &up
->type
) ||
501 put_user(kp
->flags
, &up
->flags
) ||
502 put_user(kp
->memory
, &up
->memory
) ||
503 put_user(kp
->input
, &up
->input
))
505 switch (kp
->memory
) {
506 case V4L2_MEMORY_MMAP
:
507 if (put_user(kp
->length
, &up
->length
) ||
508 put_user(kp
->m
.offset
, &up
->m
.offset
))
511 case V4L2_MEMORY_USERPTR
:
512 if (put_user(kp
->length
, &up
->length
) ||
513 put_user(kp
->m
.userptr
, &up
->m
.userptr
))
516 case V4L2_MEMORY_OVERLAY
:
517 if (put_user(kp
->m
.offset
, &up
->m
.offset
))
521 if (put_user(kp
->bytesused
, &up
->bytesused
) ||
522 put_user(kp
->field
, &up
->field
) ||
523 put_user(kp
->timestamp
.tv_sec
, &up
->timestamp
.tv_sec
) ||
524 put_user(kp
->timestamp
.tv_usec
, &up
->timestamp
.tv_usec
) ||
525 copy_to_user(&up
->timecode
, &kp
->timecode
, sizeof(struct v4l2_timecode
)) ||
526 put_user(kp
->sequence
, &up
->sequence
) ||
527 put_user(kp
->reserved
, &up
->reserved
))
532 struct v4l2_framebuffer32
{
536 struct v4l2_pix_format fmt
;
539 static int get_v4l2_framebuffer32(struct v4l2_framebuffer
*kp
, struct v4l2_framebuffer32 __user
*up
)
543 if (!access_ok(VERIFY_READ
, up
, sizeof(struct v4l2_framebuffer32
)) ||
544 get_user(tmp
, &up
->base
) ||
545 get_user(kp
->capability
, &up
->capability
) ||
546 get_user(kp
->flags
, &up
->flags
))
548 kp
->base
= compat_ptr(tmp
);
549 get_v4l2_pix_format(&kp
->fmt
, &up
->fmt
);
553 static int put_v4l2_framebuffer32(struct v4l2_framebuffer
*kp
, struct v4l2_framebuffer32 __user
*up
)
555 u32 tmp
= (u32
)((unsigned long)kp
->base
);
557 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct v4l2_framebuffer32
)) ||
558 put_user(tmp
, &up
->base
) ||
559 put_user(kp
->capability
, &up
->capability
) ||
560 put_user(kp
->flags
, &up
->flags
))
562 put_v4l2_pix_format(&kp
->fmt
, &up
->fmt
);
566 struct v4l2_input32
{
567 __u32 index
; /* Which input */
568 __u8 name
[32]; /* Label */
569 __u32 type
; /* Type of input */
570 __u32 audioset
; /* Associated audios (bitfield) */
571 __u32 tuner
; /* Associated tuner */
575 } __attribute__ ((packed
));
577 /* The 64-bit v4l2_input struct has extra padding at the end of the struct.
578 Otherwise it is identical to the 32-bit version. */
579 static inline int get_v4l2_input32(struct v4l2_input
*kp
, struct v4l2_input32 __user
*up
)
581 if (copy_from_user(kp
, up
, sizeof(struct v4l2_input32
)))
586 static inline int put_v4l2_input32(struct v4l2_input
*kp
, struct v4l2_input32 __user
*up
)
588 if (copy_to_user(up
, kp
, sizeof(struct v4l2_input32
)))
593 struct v4l2_ext_controls32
{
598 compat_caddr_t controls
; /* actually struct v4l2_ext_control32 * */
601 struct v4l2_ext_control32
{
608 compat_caddr_t string
; /* actually char * */
610 } __attribute__ ((packed
));
612 /* The following function really belong in v4l2-common, but that causes
613 a circular dependency between modules. We need to think about this, but
614 for now this will do. */
616 /* Return non-zero if this control is a pointer type. Currently only
617 type STRING is a pointer type. */
618 static inline int ctrl_is_pointer(u32 id
)
621 case V4L2_CID_RDS_TX_PS_NAME
:
622 case V4L2_CID_RDS_TX_RADIO_TEXT
:
629 static int get_v4l2_ext_controls32(struct v4l2_ext_controls
*kp
, struct v4l2_ext_controls32 __user
*up
)
631 struct v4l2_ext_control32 __user
*ucontrols
;
632 struct v4l2_ext_control __user
*kcontrols
;
636 if (!access_ok(VERIFY_READ
, up
, sizeof(struct v4l2_ext_controls32
)) ||
637 get_user(kp
->ctrl_class
, &up
->ctrl_class
) ||
638 get_user(kp
->count
, &up
->count
) ||
639 get_user(kp
->error_idx
, &up
->error_idx
) ||
640 copy_from_user(kp
->reserved
, up
->reserved
, sizeof(kp
->reserved
)))
647 if (get_user(p
, &up
->controls
))
649 ucontrols
= compat_ptr(p
);
650 if (!access_ok(VERIFY_READ
, ucontrols
, n
* sizeof(struct v4l2_ext_control
)))
652 kcontrols
= compat_alloc_user_space(n
* sizeof(struct v4l2_ext_control
));
653 kp
->controls
= kcontrols
;
655 if (copy_in_user(kcontrols
, ucontrols
, sizeof(*kcontrols
)))
657 if (ctrl_is_pointer(kcontrols
->id
)) {
660 if (get_user(p
, &ucontrols
->string
))
663 if (put_user(s
, &kcontrols
->string
))
672 static int put_v4l2_ext_controls32(struct v4l2_ext_controls
*kp
, struct v4l2_ext_controls32 __user
*up
)
674 struct v4l2_ext_control32 __user
*ucontrols
;
675 struct v4l2_ext_control __user
*kcontrols
= kp
->controls
;
679 if (!access_ok(VERIFY_WRITE
, up
, sizeof(struct v4l2_ext_controls32
)) ||
680 put_user(kp
->ctrl_class
, &up
->ctrl_class
) ||
681 put_user(kp
->count
, &up
->count
) ||
682 put_user(kp
->error_idx
, &up
->error_idx
) ||
683 copy_to_user(up
->reserved
, kp
->reserved
, sizeof(up
->reserved
)))
688 if (get_user(p
, &up
->controls
))
690 ucontrols
= compat_ptr(p
);
691 if (!access_ok(VERIFY_WRITE
, ucontrols
, n
* sizeof(struct v4l2_ext_control
)))
695 unsigned size
= sizeof(*ucontrols
);
697 /* Do not modify the pointer when copying a pointer control.
698 The contents of the pointer was changed, not the pointer
700 if (ctrl_is_pointer(kcontrols
->id
))
701 size
-= sizeof(ucontrols
->value64
);
702 if (copy_in_user(ucontrols
, kcontrols
, size
))
710 #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
711 #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
712 #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
713 #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
714 #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
715 #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
716 #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
717 #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
718 #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
719 #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
720 #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
721 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
722 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
724 #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
726 #define VIDIOC_OVERLAY32_OLD _IOWR('V', 14, s32)
728 #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
729 #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
730 #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
731 #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
732 #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
733 #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
735 static long do_video_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
738 #ifdef CONFIG_VIDEO_V4L1_COMPAT
739 struct video_tuner vt
;
740 struct video_buffer vb
;
741 struct video_window vw
;
742 struct video_code vc
;
743 struct video_audio va
;
745 struct v4l2_format v2f
;
746 struct v4l2_buffer v2b
;
747 struct v4l2_framebuffer v2fb
;
748 struct v4l2_input v2i
;
749 struct v4l2_standard v2s
;
750 struct v4l2_ext_controls v2ecs
;
754 void __user
*up
= compat_ptr(arg
);
755 int compatible_arg
= 1;
758 /* First, convert the command. */
760 #ifdef CONFIG_VIDEO_V4L1_COMPAT
761 case VIDIOCGTUNER32
: cmd
= VIDIOCGTUNER
; break;
762 case VIDIOCSTUNER32
: cmd
= VIDIOCSTUNER
; break;
763 case VIDIOCGWIN32
: cmd
= VIDIOCGWIN
; break;
764 case VIDIOCSWIN32
: cmd
= VIDIOCSWIN
; break;
765 case VIDIOCGFBUF32
: cmd
= VIDIOCGFBUF
; break;
766 case VIDIOCSFBUF32
: cmd
= VIDIOCSFBUF
; break;
767 case VIDIOCGFREQ32
: cmd
= VIDIOCGFREQ
; break;
768 case VIDIOCSFREQ32
: cmd
= VIDIOCSFREQ
; break;
769 case VIDIOCSMICROCODE32
: cmd
= VIDIOCSMICROCODE
; break;
771 case VIDIOC_G_FMT32
: cmd
= VIDIOC_G_FMT
; break;
772 case VIDIOC_S_FMT32
: cmd
= VIDIOC_S_FMT
; break;
773 case VIDIOC_QUERYBUF32
: cmd
= VIDIOC_QUERYBUF
; break;
774 case VIDIOC_G_FBUF32
: cmd
= VIDIOC_G_FBUF
; break;
775 case VIDIOC_S_FBUF32
: cmd
= VIDIOC_S_FBUF
; break;
776 case VIDIOC_QBUF32
: cmd
= VIDIOC_QBUF
; break;
777 case VIDIOC_DQBUF32
: cmd
= VIDIOC_DQBUF
; break;
778 case VIDIOC_ENUMSTD32
: cmd
= VIDIOC_ENUMSTD
; break;
779 case VIDIOC_ENUMINPUT32
: cmd
= VIDIOC_ENUMINPUT
; break;
780 case VIDIOC_TRY_FMT32
: cmd
= VIDIOC_TRY_FMT
; break;
781 case VIDIOC_G_EXT_CTRLS32
: cmd
= VIDIOC_G_EXT_CTRLS
; break;
782 case VIDIOC_S_EXT_CTRLS32
: cmd
= VIDIOC_S_EXT_CTRLS
; break;
783 case VIDIOC_TRY_EXT_CTRLS32
: cmd
= VIDIOC_TRY_EXT_CTRLS
; break;
784 case VIDIOC_OVERLAY32
: cmd
= VIDIOC_OVERLAY
; break;
786 case VIDIOC_OVERLAY32_OLD
: cmd
= VIDIOC_OVERLAY
; break;
788 case VIDIOC_STREAMON32
: cmd
= VIDIOC_STREAMON
; break;
789 case VIDIOC_STREAMOFF32
: cmd
= VIDIOC_STREAMOFF
; break;
790 case VIDIOC_G_INPUT32
: cmd
= VIDIOC_G_INPUT
; break;
791 case VIDIOC_S_INPUT32
: cmd
= VIDIOC_S_INPUT
; break;
792 case VIDIOC_G_OUTPUT32
: cmd
= VIDIOC_G_OUTPUT
; break;
793 case VIDIOC_S_OUTPUT32
: cmd
= VIDIOC_S_OUTPUT
; break;
797 #ifdef CONFIG_VIDEO_V4L1_COMPAT
800 err
= get_video_tuner32(&karg
.vt
, up
);
805 err
= get_video_buffer32(&karg
.vb
, up
);
810 err
= get_video_window32(&karg
.vw
, up
);
820 case VIDIOCSMICROCODE
:
821 err
= get_microcode32(&karg
.vc
, up
);
826 err
= get_user(karg
.vx
, (u32 __user
*)up
);
832 case VIDIOCSWRITEMODE
:
835 case VIDIOC_STREAMON
:
836 case VIDIOC_STREAMOFF
:
838 case VIDIOC_S_OUTPUT
:
839 err
= get_user(karg
.vi
, (s32 __user
*)up
);
844 case VIDIOC_G_OUTPUT
:
851 err
= get_v4l2_format32(&karg
.v2f
, up
);
855 case VIDIOC_QUERYBUF
:
858 err
= get_v4l2_buffer32(&karg
.v2b
, up
);
863 err
= get_v4l2_framebuffer32(&karg
.v2fb
, up
);
872 err
= get_v4l2_standard32(&karg
.v2s
, up
);
876 case VIDIOC_ENUMINPUT
:
877 err
= get_v4l2_input32(&karg
.v2i
, up
);
881 case VIDIOC_G_EXT_CTRLS
:
882 case VIDIOC_S_EXT_CTRLS
:
883 case VIDIOC_TRY_EXT_CTRLS
:
884 err
= get_v4l2_ext_controls32(&karg
.v2ecs
, up
);
892 err
= native_ioctl(file
, cmd
, (unsigned long)up
);
894 mm_segment_t old_fs
= get_fs();
897 err
= native_ioctl(file
, cmd
, (unsigned long)&karg
);
901 /* Special case: even after an error we need to put the
902 results back for these ioctls since the error_idx will
903 contain information on which control failed. */
905 case VIDIOC_G_EXT_CTRLS
:
906 case VIDIOC_S_EXT_CTRLS
:
907 case VIDIOC_TRY_EXT_CTRLS
:
908 if (put_v4l2_ext_controls32(&karg
.v2ecs
, up
))
916 #ifdef CONFIG_VIDEO_V4L1_COMPAT
918 err
= put_video_tuner32(&karg
.vt
, up
);
922 err
= put_video_window32(&karg
.vw
, up
);
926 err
= put_video_buffer32(&karg
.vb
, up
);
930 err
= put_user(((u32
)karg
.vx
), (u32 __user
*)up
);
934 case VIDIOC_S_OUTPUT
:
936 case VIDIOC_G_OUTPUT
:
937 err
= put_user(((s32
)karg
.vi
), (s32 __user
*)up
);
941 err
= put_v4l2_framebuffer32(&karg
.v2fb
, up
);
947 err
= put_v4l2_format32(&karg
.v2f
, up
);
950 case VIDIOC_QUERYBUF
:
953 err
= put_v4l2_buffer32(&karg
.v2b
, up
);
957 err
= put_v4l2_standard32(&karg
.v2s
, up
);
960 case VIDIOC_ENUMINPUT
:
961 err
= put_v4l2_input32(&karg
.v2i
, up
);
967 long v4l2_compat_ioctl32(struct file
*file
, unsigned int cmd
, unsigned long arg
)
969 long ret
= -ENOIOCTLCMD
;
971 if (!file
->f_op
->unlocked_ioctl
)
975 #ifdef CONFIG_VIDEO_V4L1_COMPAT
983 case VIDIOCCAPTURE32
:
999 case VIDIOCSPLAYMODE
:
1000 case VIDIOCSWRITEMODE32
:
1001 case VIDIOCGPLAYINFO
:
1002 case VIDIOCSMICROCODE32
:
1006 #ifdef __OLD_VIDIOC_
1007 case VIDIOC_OVERLAY32_OLD
:
1008 case VIDIOC_S_PARM_OLD
:
1009 case VIDIOC_S_CTRL_OLD
:
1010 case VIDIOC_G_AUDIO_OLD
:
1011 case VIDIOC_G_AUDOUT_OLD
:
1012 case VIDIOC_CROPCAP_OLD
:
1014 case VIDIOC_QUERYCAP
:
1015 case VIDIOC_RESERVED
:
1016 case VIDIOC_ENUM_FMT
:
1017 case VIDIOC_G_FMT32
:
1018 case VIDIOC_S_FMT32
:
1019 case VIDIOC_REQBUFS
:
1020 case VIDIOC_QUERYBUF32
:
1021 case VIDIOC_G_FBUF32
:
1022 case VIDIOC_S_FBUF32
:
1023 case VIDIOC_OVERLAY32
:
1025 case VIDIOC_DQBUF32
:
1026 case VIDIOC_STREAMON32
:
1027 case VIDIOC_STREAMOFF32
:
1032 case VIDIOC_ENUMSTD32
:
1033 case VIDIOC_ENUMINPUT32
:
1036 case VIDIOC_G_TUNER
:
1037 case VIDIOC_S_TUNER
:
1038 case VIDIOC_G_AUDIO
:
1039 case VIDIOC_S_AUDIO
:
1040 case VIDIOC_QUERYCTRL
:
1041 case VIDIOC_QUERYMENU
:
1042 case VIDIOC_G_INPUT32
:
1043 case VIDIOC_S_INPUT32
:
1044 case VIDIOC_G_OUTPUT32
:
1045 case VIDIOC_S_OUTPUT32
:
1046 case VIDIOC_ENUMOUTPUT
:
1047 case VIDIOC_G_AUDOUT
:
1048 case VIDIOC_S_AUDOUT
:
1049 case VIDIOC_G_MODULATOR
:
1050 case VIDIOC_S_MODULATOR
:
1051 case VIDIOC_S_FREQUENCY
:
1052 case VIDIOC_G_FREQUENCY
:
1053 case VIDIOC_CROPCAP
:
1056 case VIDIOC_G_JPEGCOMP
:
1057 case VIDIOC_S_JPEGCOMP
:
1058 case VIDIOC_QUERYSTD
:
1059 case VIDIOC_TRY_FMT32
:
1060 case VIDIOC_ENUMAUDIO
:
1061 case VIDIOC_ENUMAUDOUT
:
1062 case VIDIOC_G_PRIORITY
:
1063 case VIDIOC_S_PRIORITY
:
1064 case VIDIOC_G_SLICED_VBI_CAP
:
1065 case VIDIOC_LOG_STATUS
:
1066 case VIDIOC_G_EXT_CTRLS32
:
1067 case VIDIOC_S_EXT_CTRLS32
:
1068 case VIDIOC_TRY_EXT_CTRLS32
:
1069 case VIDIOC_ENUM_FRAMESIZES
:
1070 case VIDIOC_ENUM_FRAMEINTERVALS
:
1071 case VIDIOC_G_ENC_INDEX
:
1072 case VIDIOC_ENCODER_CMD
:
1073 case VIDIOC_TRY_ENCODER_CMD
:
1074 case VIDIOC_DBG_S_REGISTER
:
1075 case VIDIOC_DBG_G_REGISTER
:
1076 case VIDIOC_DBG_G_CHIP_IDENT
:
1077 case VIDIOC_S_HW_FREQ_SEEK
:
1078 case VIDIOC_ENUM_DV_PRESETS
:
1079 case VIDIOC_S_DV_PRESET
:
1080 case VIDIOC_G_DV_PRESET
:
1081 case VIDIOC_QUERY_DV_PRESET
:
1082 case VIDIOC_S_DV_TIMINGS
:
1083 case VIDIOC_G_DV_TIMINGS
:
1084 case VIDIOC_DQEVENT
:
1085 case VIDIOC_SUBSCRIBE_EVENT
:
1086 case VIDIOC_UNSUBSCRIBE_EVENT
:
1087 ret
= do_video_ioctl(file
, cmd
, arg
);
1090 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1091 /* BTTV specific... */
1092 case _IOW('v', BASE_VIDIOCPRIVATE
+0, char [256]):
1093 case _IOR('v', BASE_VIDIOCPRIVATE
+1, char [256]):
1094 case _IOR('v' , BASE_VIDIOCPRIVATE
+2, unsigned int):
1095 case _IOW('v' , BASE_VIDIOCPRIVATE
+3, char [16]): /* struct bttv_pll_info */
1096 case _IOR('v' , BASE_VIDIOCPRIVATE
+4, int):
1097 case _IOR('v' , BASE_VIDIOCPRIVATE
+5, int):
1098 case _IOR('v' , BASE_VIDIOCPRIVATE
+6, int):
1099 case _IOR('v' , BASE_VIDIOCPRIVATE
+7, int):
1100 ret
= native_ioctl(file
, cmd
, (unsigned long)compat_ptr(arg
));
1104 printk(KERN_WARNING
"compat_ioctl32: "
1105 "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
1106 _IOC_TYPE(cmd
), _IOC_DIR(cmd
), _IOC_NR(cmd
), cmd
);
1111 EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32
);
1114 MODULE_LICENSE("GPL");