1 // SPDX-License-Identifier: GPL-2.0-only
3 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
4 * Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
6 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
7 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
8 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
9 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
10 * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
11 * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
13 * These routines maintain argument size conversion between 32bit and 64bit
17 #include <linux/compat.h>
18 #include <linux/module.h>
19 #include <linux/videodev2.h>
20 #include <linux/v4l2-subdev.h>
21 #include <media/v4l2-dev.h>
22 #include <media/v4l2-fh.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-ioctl.h>
27 * assign_in_user() - Copy from one __user var to another one
29 * @to: __user var where data will be stored
30 * @from: __user var where data will be retrieved.
32 * As this code very often needs to allocate userspace memory, it is easier
33 * to have a macro that will do both get_user() and put_user() at once.
35 * This function complements the macros defined at asm-generic/uaccess.h.
36 * It uses the same argument order as copy_in_user()
38 #define assign_in_user(to, from) \
40 typeof(*from) __assign_tmp; \
42 get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \
46 * get_user_cast() - Stores at a kernelspace local var the contents from a
47 * pointer with userspace data that is not tagged with __user.
49 * @__x: var where data will be stored
50 * @__ptr: var where data will be retrieved.
52 * Sometimes we need to declare a pointer without __user because it
53 * comes from a pointer struct field that will be retrieved from userspace
54 * by the 64-bit native ioctl handler. This function ensures that the
55 * @__ptr will be cast to __user before calling get_user() in order to
56 * avoid warnings with static code analyzers like smatch.
58 #define get_user_cast(__x, __ptr) \
60 get_user(__x, (typeof(*__ptr) __user *)(__ptr)); \
64 * put_user_force() - Stores the contents of a kernelspace local var
65 * into a userspace pointer, removing any __user cast.
67 * @__x: var where data will be stored
68 * @__ptr: var where data will be retrieved.
70 * Sometimes we need to remove the __user attribute from some data,
71 * by passing the __force macro. This function ensures that the
72 * @__ptr will be cast with __force before calling put_user(), in order to
73 * avoid warnings with static code analyzers like smatch.
75 #define put_user_force(__x, __ptr) \
77 put_user((typeof(*__x) __force *)(__x), __ptr); \
81 * assign_in_user_cast() - Copy from one __user var to another one
83 * @to: __user var where data will be stored
84 * @from: var where data will be retrieved that needs to be cast to __user.
86 * As this code very often needs to allocate userspace memory, it is easier
87 * to have a macro that will do both get_user_cast() and put_user() at once.
89 * This function should be used instead of assign_in_user() when the @from
90 * variable was not declared as __user. See get_user_cast() for more details.
92 * This function complements the macros defined at asm-generic/uaccess.h.
93 * It uses the same argument order as copy_in_user()
95 #define assign_in_user_cast(to, from) \
97 typeof(*from) __assign_tmp; \
99 get_user_cast(__assign_tmp, from) || put_user(__assign_tmp, to);\
103 * native_ioctl - Ancillary function that calls the native 64 bits ioctl
106 * @file: pointer to &struct file with the file handler
107 * @cmd: ioctl to be called
108 * @arg: arguments passed from/to the ioctl handler
110 * This function calls the native ioctl handler at v4l2-dev, e. g. v4l2_ioctl()
112 static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
114 long ret = -ENOIOCTLCMD;
116 if (file->f_op->unlocked_ioctl)
117 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
124 * Per-ioctl data copy handlers.
126 * Those come in pairs, with a get_v4l2_foo() and a put_v4l2_foo() routine,
127 * where "v4l2_foo" is the name of the V4L2 struct.
129 * They basically get two __user pointers, one with a 32-bits struct that
130 * came from the userspace call and a 64-bits struct, also allocated as
131 * userspace, but filled internally by do_video_ioctl().
133 * For ioctls that have pointers inside it, the functions will also
134 * receive an ancillary buffer with extra space, used to pass extra
135 * data to the routine.
143 struct v4l2_window32 {
145 __u32 field; /* enum v4l2_field */
147 compat_caddr_t clips; /* actually struct v4l2_clip32 * */
149 compat_caddr_t bitmap;
153 static int get_v4l2_window32(struct v4l2_window __user *p64,
154 struct v4l2_window32 __user *p32,
155 void __user *aux_buf, u32 aux_space)
157 struct v4l2_clip32 __user *uclips;
158 struct v4l2_clip __user *kclips;
162 if (!access_ok(p32, sizeof(*p32)) ||
163 copy_in_user(&p64->w, &p32->w, sizeof(p32->w)) ||
164 assign_in_user(&p64->field, &p32->field) ||
165 assign_in_user(&p64->chromakey, &p32->chromakey) ||
166 assign_in_user(&p64->global_alpha, &p32->global_alpha) ||
167 get_user(clipcount, &p32->clipcount) ||
168 put_user(clipcount, &p64->clipcount))
170 if (clipcount > 2048)
173 return put_user(NULL, &p64->clips);
175 if (get_user(p, &p32->clips))
177 uclips = compat_ptr(p);
178 if (aux_space < clipcount * sizeof(*kclips))
181 if (put_user(kclips, &p64->clips))
184 while (clipcount--) {
185 if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
187 if (put_user(clipcount ? kclips + 1 : NULL, &kclips->next))
195 static int put_v4l2_window32(struct v4l2_window __user *p64,
196 struct v4l2_window32 __user *p32)
198 struct v4l2_clip __user *kclips;
199 struct v4l2_clip32 __user *uclips;
203 if (copy_in_user(&p32->w, &p64->w, sizeof(p64->w)) ||
204 assign_in_user(&p32->field, &p64->field) ||
205 assign_in_user(&p32->chromakey, &p64->chromakey) ||
206 assign_in_user(&p32->global_alpha, &p64->global_alpha) ||
207 get_user(clipcount, &p64->clipcount) ||
208 put_user(clipcount, &p32->clipcount))
213 if (get_user(kclips, &p64->clips))
215 if (get_user(p, &p32->clips))
217 uclips = compat_ptr(p);
218 while (clipcount--) {
219 if (copy_in_user(&uclips->c, &kclips->c, sizeof(uclips->c)))
227 struct v4l2_format32 {
228 __u32 type; /* enum v4l2_buf_type */
230 struct v4l2_pix_format pix;
231 struct v4l2_pix_format_mplane pix_mp;
232 struct v4l2_window32 win;
233 struct v4l2_vbi_format vbi;
234 struct v4l2_sliced_vbi_format sliced;
235 struct v4l2_sdr_format sdr;
236 struct v4l2_meta_format meta;
237 __u8 raw_data[200]; /* user-defined */
242 * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument
243 * @index: on return, index of the first created buffer
244 * @count: entry: number of requested buffers,
245 * return: number of created buffers
246 * @memory: buffer memory type
247 * @format: frame format, for which buffers are requested
248 * @capabilities: capabilities of this buffer type.
249 * @reserved: future extensions
251 struct v4l2_create_buffers32 {
254 __u32 memory; /* enum v4l2_memory */
255 struct v4l2_format32 format;
260 static int __bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size)
264 if (get_user(type, &p32->type))
268 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
269 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: {
272 if (get_user(clipcount, &p32->fmt.win.clipcount))
274 if (clipcount > 2048)
276 *size = clipcount * sizeof(struct v4l2_clip);
285 static int bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size)
287 if (!access_ok(p32, sizeof(*p32)))
289 return __bufsize_v4l2_format(p32, size);
292 static int __get_v4l2_format32(struct v4l2_format __user *p64,
293 struct v4l2_format32 __user *p32,
294 void __user *aux_buf, u32 aux_space)
298 if (get_user(type, &p32->type) || put_user(type, &p64->type))
302 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
303 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
304 return copy_in_user(&p64->fmt.pix, &p32->fmt.pix,
305 sizeof(p64->fmt.pix)) ? -EFAULT : 0;
306 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
307 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
308 return copy_in_user(&p64->fmt.pix_mp, &p32->fmt.pix_mp,
309 sizeof(p64->fmt.pix_mp)) ? -EFAULT : 0;
310 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
311 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
312 return get_v4l2_window32(&p64->fmt.win, &p32->fmt.win,
314 case V4L2_BUF_TYPE_VBI_CAPTURE:
315 case V4L2_BUF_TYPE_VBI_OUTPUT:
316 return copy_in_user(&p64->fmt.vbi, &p32->fmt.vbi,
317 sizeof(p64->fmt.vbi)) ? -EFAULT : 0;
318 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
319 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
320 return copy_in_user(&p64->fmt.sliced, &p32->fmt.sliced,
321 sizeof(p64->fmt.sliced)) ? -EFAULT : 0;
322 case V4L2_BUF_TYPE_SDR_CAPTURE:
323 case V4L2_BUF_TYPE_SDR_OUTPUT:
324 return copy_in_user(&p64->fmt.sdr, &p32->fmt.sdr,
325 sizeof(p64->fmt.sdr)) ? -EFAULT : 0;
326 case V4L2_BUF_TYPE_META_CAPTURE:
327 case V4L2_BUF_TYPE_META_OUTPUT:
328 return copy_in_user(&p64->fmt.meta, &p32->fmt.meta,
329 sizeof(p64->fmt.meta)) ? -EFAULT : 0;
335 static int get_v4l2_format32(struct v4l2_format __user *p64,
336 struct v4l2_format32 __user *p32,
337 void __user *aux_buf, u32 aux_space)
339 if (!access_ok(p32, sizeof(*p32)))
341 return __get_v4l2_format32(p64, p32, aux_buf, aux_space);
344 static int bufsize_v4l2_create(struct v4l2_create_buffers32 __user *p32,
347 if (!access_ok(p32, sizeof(*p32)))
349 return __bufsize_v4l2_format(&p32->format, size);
352 static int get_v4l2_create32(struct v4l2_create_buffers __user *p64,
353 struct v4l2_create_buffers32 __user *p32,
354 void __user *aux_buf, u32 aux_space)
356 if (!access_ok(p32, sizeof(*p32)) ||
357 copy_in_user(p64, p32,
358 offsetof(struct v4l2_create_buffers32, format)))
360 return __get_v4l2_format32(&p64->format, &p32->format,
364 static int __put_v4l2_format32(struct v4l2_format __user *p64,
365 struct v4l2_format32 __user *p32)
369 if (get_user(type, &p64->type))
373 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
374 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
375 return copy_in_user(&p32->fmt.pix, &p64->fmt.pix,
376 sizeof(p64->fmt.pix)) ? -EFAULT : 0;
377 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
378 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
379 return copy_in_user(&p32->fmt.pix_mp, &p64->fmt.pix_mp,
380 sizeof(p64->fmt.pix_mp)) ? -EFAULT : 0;
381 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
382 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
383 return put_v4l2_window32(&p64->fmt.win, &p32->fmt.win);
384 case V4L2_BUF_TYPE_VBI_CAPTURE:
385 case V4L2_BUF_TYPE_VBI_OUTPUT:
386 return copy_in_user(&p32->fmt.vbi, &p64->fmt.vbi,
387 sizeof(p64->fmt.vbi)) ? -EFAULT : 0;
388 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
389 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
390 return copy_in_user(&p32->fmt.sliced, &p64->fmt.sliced,
391 sizeof(p64->fmt.sliced)) ? -EFAULT : 0;
392 case V4L2_BUF_TYPE_SDR_CAPTURE:
393 case V4L2_BUF_TYPE_SDR_OUTPUT:
394 return copy_in_user(&p32->fmt.sdr, &p64->fmt.sdr,
395 sizeof(p64->fmt.sdr)) ? -EFAULT : 0;
396 case V4L2_BUF_TYPE_META_CAPTURE:
397 case V4L2_BUF_TYPE_META_OUTPUT:
398 return copy_in_user(&p32->fmt.meta, &p64->fmt.meta,
399 sizeof(p64->fmt.meta)) ? -EFAULT : 0;
405 static int put_v4l2_format32(struct v4l2_format __user *p64,
406 struct v4l2_format32 __user *p32)
408 if (!access_ok(p32, sizeof(*p32)))
410 return __put_v4l2_format32(p64, p32);
413 static int put_v4l2_create32(struct v4l2_create_buffers __user *p64,
414 struct v4l2_create_buffers32 __user *p32)
416 if (!access_ok(p32, sizeof(*p32)) ||
417 copy_in_user(p32, p64,
418 offsetof(struct v4l2_create_buffers32, format)) ||
419 assign_in_user(&p32->capabilities, &p64->capabilities) ||
420 copy_in_user(p32->reserved, p64->reserved, sizeof(p64->reserved)))
422 return __put_v4l2_format32(&p64->format, &p32->format);
425 struct v4l2_standard32 {
429 struct v4l2_fract frameperiod; /* Frames, not fields */
434 static int get_v4l2_standard32(struct v4l2_standard __user *p64,
435 struct v4l2_standard32 __user *p32)
437 /* other fields are not set by the user, nor used by the driver */
438 if (!access_ok(p32, sizeof(*p32)) ||
439 assign_in_user(&p64->index, &p32->index))
444 static int put_v4l2_standard32(struct v4l2_standard __user *p64,
445 struct v4l2_standard32 __user *p32)
447 if (!access_ok(p32, sizeof(*p32)) ||
448 assign_in_user(&p32->index, &p64->index) ||
449 assign_in_user(&p32->id, &p64->id) ||
450 copy_in_user(p32->name, p64->name, sizeof(p32->name)) ||
451 copy_in_user(&p32->frameperiod, &p64->frameperiod,
452 sizeof(p32->frameperiod)) ||
453 assign_in_user(&p32->framelines, &p64->framelines) ||
454 copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
459 struct v4l2_plane32 {
464 compat_long_t userptr;
472 * This is correct for all architectures including i386, but not x32,
473 * which has different alignment requirements for timestamp
475 struct v4l2_buffer32 {
477 __u32 type; /* enum v4l2_buf_type */
480 __u32 field; /* enum v4l2_field */
485 struct v4l2_timecode timecode;
488 /* memory location */
489 __u32 memory; /* enum v4l2_memory */
492 compat_long_t userptr;
493 compat_caddr_t planes;
501 struct v4l2_buffer32_time32 {
503 __u32 type; /* enum v4l2_buf_type */
506 __u32 field; /* enum v4l2_field */
507 struct old_timeval32 timestamp;
508 struct v4l2_timecode timecode;
511 /* memory location */
512 __u32 memory; /* enum v4l2_memory */
515 compat_long_t userptr;
516 compat_caddr_t planes;
524 static int get_v4l2_plane32(struct v4l2_plane __user *p64,
525 struct v4l2_plane32 __user *p32,
526 enum v4l2_memory memory)
530 if (copy_in_user(p64, p32, 2 * sizeof(__u32)) ||
531 copy_in_user(&p64->data_offset, &p32->data_offset,
532 sizeof(p64->data_offset)))
536 case V4L2_MEMORY_MMAP:
537 case V4L2_MEMORY_OVERLAY:
538 if (copy_in_user(&p64->m.mem_offset, &p32->m.mem_offset,
539 sizeof(p32->m.mem_offset)))
542 case V4L2_MEMORY_USERPTR:
543 if (get_user(p, &p32->m.userptr) ||
544 put_user((unsigned long)compat_ptr(p), &p64->m.userptr))
547 case V4L2_MEMORY_DMABUF:
548 if (copy_in_user(&p64->m.fd, &p32->m.fd, sizeof(p32->m.fd)))
556 static int put_v4l2_plane32(struct v4l2_plane __user *p64,
557 struct v4l2_plane32 __user *p32,
558 enum v4l2_memory memory)
562 if (copy_in_user(p32, p64, 2 * sizeof(__u32)) ||
563 copy_in_user(&p32->data_offset, &p64->data_offset,
564 sizeof(p64->data_offset)))
568 case V4L2_MEMORY_MMAP:
569 case V4L2_MEMORY_OVERLAY:
570 if (copy_in_user(&p32->m.mem_offset, &p64->m.mem_offset,
571 sizeof(p64->m.mem_offset)))
574 case V4L2_MEMORY_USERPTR:
575 if (get_user(p, &p64->m.userptr) ||
576 put_user((compat_ulong_t)ptr_to_compat((void __user *)p),
580 case V4L2_MEMORY_DMABUF:
581 if (copy_in_user(&p32->m.fd, &p64->m.fd, sizeof(p64->m.fd)))
589 static int bufsize_v4l2_buffer(struct v4l2_buffer32 __user *p32, u32 *size)
594 if (!access_ok(p32, sizeof(*p32)) ||
595 get_user(type, &p32->type) ||
596 get_user(length, &p32->length))
599 if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
600 if (length > VIDEO_MAX_PLANES)
604 * We don't really care if userspace decides to kill itself
605 * by passing a very big length value
607 *size = length * sizeof(struct v4l2_plane);
614 static int bufsize_v4l2_buffer_time32(struct v4l2_buffer32_time32 __user *p32, u32 *size)
619 if (!access_ok(p32, sizeof(*p32)) ||
620 get_user(type, &p32->type) ||
621 get_user(length, &p32->length))
624 if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
625 if (length > VIDEO_MAX_PLANES)
629 * We don't really care if userspace decides to kill itself
630 * by passing a very big length value
632 *size = length * sizeof(struct v4l2_plane);
639 static int get_v4l2_buffer32(struct v4l2_buffer __user *p64,
640 struct v4l2_buffer32 __user *p32,
641 void __user *aux_buf, u32 aux_space)
646 enum v4l2_memory memory;
647 struct v4l2_plane32 __user *uplane32;
648 struct v4l2_plane __user *uplane;
652 if (!access_ok(p32, sizeof(*p32)) ||
653 assign_in_user(&p64->index, &p32->index) ||
654 get_user(type, &p32->type) ||
655 put_user(type, &p64->type) ||
656 assign_in_user(&p64->flags, &p32->flags) ||
657 get_user(memory, &p32->memory) ||
658 put_user(memory, &p64->memory) ||
659 get_user(length, &p32->length) ||
660 put_user(length, &p64->length) ||
661 get_user(request_fd, &p32->request_fd) ||
662 put_user(request_fd, &p64->request_fd))
665 if (V4L2_TYPE_IS_OUTPUT(type))
666 if (assign_in_user(&p64->bytesused, &p32->bytesused) ||
667 assign_in_user(&p64->field, &p32->field) ||
668 assign_in_user(&p64->timestamp.tv_sec,
669 &p32->timestamp.tv_sec) ||
670 assign_in_user(&p64->timestamp.tv_usec,
671 &p32->timestamp.tv_usec))
674 if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
675 u32 num_planes = length;
677 if (num_planes == 0) {
679 * num_planes == 0 is legal, e.g. when userspace doesn't
680 * need planes array on DQBUF
682 return put_user(NULL, &p64->m.planes);
684 if (num_planes > VIDEO_MAX_PLANES)
687 if (get_user(p, &p32->m.planes))
690 uplane32 = compat_ptr(p);
691 if (!access_ok(uplane32,
692 num_planes * sizeof(*uplane32)))
696 * We don't really care if userspace decides to kill itself
697 * by passing a very big num_planes value
699 if (aux_space < num_planes * sizeof(*uplane))
703 if (put_user_force(uplane, &p64->m.planes))
706 while (num_planes--) {
707 ret = get_v4l2_plane32(uplane, uplane32, memory);
715 case V4L2_MEMORY_MMAP:
716 case V4L2_MEMORY_OVERLAY:
717 if (assign_in_user(&p64->m.offset, &p32->m.offset))
720 case V4L2_MEMORY_USERPTR: {
721 compat_ulong_t userptr;
723 if (get_user(userptr, &p32->m.userptr) ||
724 put_user((unsigned long)compat_ptr(userptr),
729 case V4L2_MEMORY_DMABUF:
730 if (assign_in_user(&p64->m.fd, &p32->m.fd))
739 static int get_v4l2_buffer32_time32(struct v4l2_buffer_time32 __user *p64,
740 struct v4l2_buffer32_time32 __user *p32,
741 void __user *aux_buf, u32 aux_space)
746 enum v4l2_memory memory;
747 struct v4l2_plane32 __user *uplane32;
748 struct v4l2_plane __user *uplane;
752 if (!access_ok(p32, sizeof(*p32)) ||
753 assign_in_user(&p64->index, &p32->index) ||
754 get_user(type, &p32->type) ||
755 put_user(type, &p64->type) ||
756 assign_in_user(&p64->flags, &p32->flags) ||
757 get_user(memory, &p32->memory) ||
758 put_user(memory, &p64->memory) ||
759 get_user(length, &p32->length) ||
760 put_user(length, &p64->length) ||
761 get_user(request_fd, &p32->request_fd) ||
762 put_user(request_fd, &p64->request_fd))
765 if (V4L2_TYPE_IS_OUTPUT(type))
766 if (assign_in_user(&p64->bytesused, &p32->bytesused) ||
767 assign_in_user(&p64->field, &p32->field) ||
768 assign_in_user(&p64->timestamp.tv_sec,
769 &p32->timestamp.tv_sec) ||
770 assign_in_user(&p64->timestamp.tv_usec,
771 &p32->timestamp.tv_usec))
774 if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
775 u32 num_planes = length;
777 if (num_planes == 0) {
779 * num_planes == 0 is legal, e.g. when userspace doesn't
780 * need planes array on DQBUF
782 return put_user(NULL, &p64->m.planes);
784 if (num_planes > VIDEO_MAX_PLANES)
787 if (get_user(p, &p32->m.planes))
790 uplane32 = compat_ptr(p);
791 if (!access_ok(uplane32,
792 num_planes * sizeof(*uplane32)))
796 * We don't really care if userspace decides to kill itself
797 * by passing a very big num_planes value
799 if (aux_space < num_planes * sizeof(*uplane))
803 if (put_user_force(uplane, &p64->m.planes))
806 while (num_planes--) {
807 ret = get_v4l2_plane32(uplane, uplane32, memory);
815 case V4L2_MEMORY_MMAP:
816 case V4L2_MEMORY_OVERLAY:
817 if (assign_in_user(&p64->m.offset, &p32->m.offset))
820 case V4L2_MEMORY_USERPTR: {
821 compat_ulong_t userptr;
823 if (get_user(userptr, &p32->m.userptr) ||
824 put_user((unsigned long)compat_ptr(userptr),
829 case V4L2_MEMORY_DMABUF:
830 if (assign_in_user(&p64->m.fd, &p32->m.fd))
839 static int put_v4l2_buffer32(struct v4l2_buffer __user *p64,
840 struct v4l2_buffer32 __user *p32)
844 enum v4l2_memory memory;
845 struct v4l2_plane32 __user *uplane32;
846 struct v4l2_plane *uplane;
850 if (!access_ok(p32, sizeof(*p32)) ||
851 assign_in_user(&p32->index, &p64->index) ||
852 get_user(type, &p64->type) ||
853 put_user(type, &p32->type) ||
854 assign_in_user(&p32->flags, &p64->flags) ||
855 get_user(memory, &p64->memory) ||
856 put_user(memory, &p32->memory))
859 if (assign_in_user(&p32->bytesused, &p64->bytesused) ||
860 assign_in_user(&p32->field, &p64->field) ||
861 assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) ||
862 assign_in_user(&p32->timestamp.tv_usec, &p64->timestamp.tv_usec) ||
863 copy_in_user(&p32->timecode, &p64->timecode, sizeof(p64->timecode)) ||
864 assign_in_user(&p32->sequence, &p64->sequence) ||
865 assign_in_user(&p32->reserved2, &p64->reserved2) ||
866 assign_in_user(&p32->request_fd, &p64->request_fd) ||
867 get_user(length, &p64->length) ||
868 put_user(length, &p32->length))
871 if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
872 u32 num_planes = length;
876 /* We need to define uplane without __user, even though
877 * it does point to data in userspace here. The reason is
878 * that v4l2-ioctl.c copies it from userspace to kernelspace,
879 * so its definition in videodev2.h doesn't have a
880 * __user markup. Defining uplane with __user causes
881 * smatch warnings, so instead declare it without __user
882 * and cast it as a userspace pointer to put_v4l2_plane32().
884 if (get_user(uplane, &p64->m.planes))
886 if (get_user(p, &p32->m.planes))
888 uplane32 = compat_ptr(p);
890 while (num_planes--) {
891 ret = put_v4l2_plane32((void __user *)uplane,
900 case V4L2_MEMORY_MMAP:
901 case V4L2_MEMORY_OVERLAY:
902 if (assign_in_user(&p32->m.offset, &p64->m.offset))
905 case V4L2_MEMORY_USERPTR:
906 if (assign_in_user(&p32->m.userptr, &p64->m.userptr))
909 case V4L2_MEMORY_DMABUF:
910 if (assign_in_user(&p32->m.fd, &p64->m.fd))
919 static int put_v4l2_buffer32_time32(struct v4l2_buffer_time32 __user *p64,
920 struct v4l2_buffer32_time32 __user *p32)
924 enum v4l2_memory memory;
925 struct v4l2_plane32 __user *uplane32;
926 struct v4l2_plane *uplane;
930 if (!access_ok(p32, sizeof(*p32)) ||
931 assign_in_user(&p32->index, &p64->index) ||
932 get_user(type, &p64->type) ||
933 put_user(type, &p32->type) ||
934 assign_in_user(&p32->flags, &p64->flags) ||
935 get_user(memory, &p64->memory) ||
936 put_user(memory, &p32->memory))
939 if (assign_in_user(&p32->bytesused, &p64->bytesused) ||
940 assign_in_user(&p32->field, &p64->field) ||
941 assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) ||
942 assign_in_user(&p32->timestamp.tv_usec, &p64->timestamp.tv_usec) ||
943 copy_in_user(&p32->timecode, &p64->timecode, sizeof(p64->timecode)) ||
944 assign_in_user(&p32->sequence, &p64->sequence) ||
945 assign_in_user(&p32->reserved2, &p64->reserved2) ||
946 assign_in_user(&p32->request_fd, &p64->request_fd) ||
947 get_user(length, &p64->length) ||
948 put_user(length, &p32->length))
951 if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
952 u32 num_planes = length;
956 /* We need to define uplane without __user, even though
957 * it does point to data in userspace here. The reason is
958 * that v4l2-ioctl.c copies it from userspace to kernelspace,
959 * so its definition in videodev2.h doesn't have a
960 * __user markup. Defining uplane with __user causes
961 * smatch warnings, so instead declare it without __user
962 * and cast it as a userspace pointer to put_v4l2_plane32().
964 if (get_user(uplane, &p64->m.planes))
966 if (get_user(p, &p32->m.planes))
968 uplane32 = compat_ptr(p);
970 while (num_planes--) {
971 ret = put_v4l2_plane32((void __user *)uplane,
980 case V4L2_MEMORY_MMAP:
981 case V4L2_MEMORY_OVERLAY:
982 if (assign_in_user(&p32->m.offset, &p64->m.offset))
985 case V4L2_MEMORY_USERPTR:
986 if (assign_in_user(&p32->m.userptr, &p64->m.userptr))
989 case V4L2_MEMORY_DMABUF:
990 if (assign_in_user(&p32->m.fd, &p64->m.fd))
999 struct v4l2_framebuffer32 {
1002 compat_caddr_t base;
1015 static int get_v4l2_framebuffer32(struct v4l2_framebuffer __user *p64,
1016 struct v4l2_framebuffer32 __user *p32)
1020 if (!access_ok(p32, sizeof(*p32)) ||
1021 get_user(tmp, &p32->base) ||
1022 put_user_force(compat_ptr(tmp), &p64->base) ||
1023 assign_in_user(&p64->capability, &p32->capability) ||
1024 assign_in_user(&p64->flags, &p32->flags) ||
1025 copy_in_user(&p64->fmt, &p32->fmt, sizeof(p64->fmt)))
1030 static int put_v4l2_framebuffer32(struct v4l2_framebuffer __user *p64,
1031 struct v4l2_framebuffer32 __user *p32)
1035 if (!access_ok(p32, sizeof(*p32)) ||
1036 get_user(base, &p64->base) ||
1037 put_user(ptr_to_compat((void __user *)base), &p32->base) ||
1038 assign_in_user(&p32->capability, &p64->capability) ||
1039 assign_in_user(&p32->flags, &p64->flags) ||
1040 copy_in_user(&p32->fmt, &p64->fmt, sizeof(p64->fmt)))
1045 struct v4l2_input32 {
1046 __u32 index; /* Which input */
1047 __u8 name[32]; /* Label */
1048 __u32 type; /* Type of input */
1049 __u32 audioset; /* Associated audios (bitfield) */
1050 __u32 tuner; /* Associated tuner */
1058 * The 64-bit v4l2_input struct has extra padding at the end of the struct.
1059 * Otherwise it is identical to the 32-bit version.
1061 static inline int get_v4l2_input32(struct v4l2_input __user *p64,
1062 struct v4l2_input32 __user *p32)
1064 if (copy_in_user(p64, p32, sizeof(*p32)))
1069 static inline int put_v4l2_input32(struct v4l2_input __user *p64,
1070 struct v4l2_input32 __user *p32)
1072 if (copy_in_user(p32, p64, sizeof(*p32)))
1077 struct v4l2_ext_controls32 {
1083 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
1086 struct v4l2_ext_control32 {
1093 compat_caddr_t string; /* actually char * */
1095 } __attribute__ ((packed));
1097 /* Return true if this control is a pointer type. */
1098 static inline bool ctrl_is_pointer(struct file *file, u32 id)
1100 struct video_device *vdev = video_devdata(file);
1101 struct v4l2_fh *fh = NULL;
1102 struct v4l2_ctrl_handler *hdl = NULL;
1103 struct v4l2_query_ext_ctrl qec = { id };
1104 const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops;
1106 if (test_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags))
1107 fh = file->private_data;
1109 if (fh && fh->ctrl_handler)
1110 hdl = fh->ctrl_handler;
1111 else if (vdev->ctrl_handler)
1112 hdl = vdev->ctrl_handler;
1115 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, id);
1117 return ctrl && ctrl->is_ptr;
1120 if (!ops || !ops->vidioc_query_ext_ctrl)
1123 return !ops->vidioc_query_ext_ctrl(file, fh, &qec) &&
1124 (qec.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD);
1127 static int bufsize_v4l2_ext_controls(struct v4l2_ext_controls32 __user *p32,
1132 if (!access_ok(p32, sizeof(*p32)) ||
1133 get_user(count, &p32->count))
1135 if (count > V4L2_CID_MAX_CTRLS)
1137 *size = count * sizeof(struct v4l2_ext_control);
1141 static int get_v4l2_ext_controls32(struct file *file,
1142 struct v4l2_ext_controls __user *p64,
1143 struct v4l2_ext_controls32 __user *p32,
1144 void __user *aux_buf, u32 aux_space)
1146 struct v4l2_ext_control32 __user *ucontrols;
1147 struct v4l2_ext_control __user *kcontrols;
1152 if (!access_ok(p32, sizeof(*p32)) ||
1153 assign_in_user(&p64->which, &p32->which) ||
1154 get_user(count, &p32->count) ||
1155 put_user(count, &p64->count) ||
1156 assign_in_user(&p64->error_idx, &p32->error_idx) ||
1157 assign_in_user(&p64->request_fd, &p32->request_fd) ||
1158 copy_in_user(p64->reserved, p32->reserved, sizeof(p64->reserved)))
1162 return put_user(NULL, &p64->controls);
1163 if (count > V4L2_CID_MAX_CTRLS)
1165 if (get_user(p, &p32->controls))
1167 ucontrols = compat_ptr(p);
1168 if (!access_ok(ucontrols, count * sizeof(*ucontrols)))
1170 if (aux_space < count * sizeof(*kcontrols))
1172 kcontrols = aux_buf;
1173 if (put_user_force(kcontrols, &p64->controls))
1176 for (n = 0; n < count; n++) {
1179 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
1182 if (get_user(id, &kcontrols->id))
1185 if (ctrl_is_pointer(file, id)) {
1188 if (get_user(p, &ucontrols->string))
1191 if (put_user(s, &kcontrols->string))
1200 static int put_v4l2_ext_controls32(struct file *file,
1201 struct v4l2_ext_controls __user *p64,
1202 struct v4l2_ext_controls32 __user *p32)
1204 struct v4l2_ext_control32 __user *ucontrols;
1205 struct v4l2_ext_control *kcontrols;
1211 * We need to define kcontrols without __user, even though it does
1212 * point to data in userspace here. The reason is that v4l2-ioctl.c
1213 * copies it from userspace to kernelspace, so its definition in
1214 * videodev2.h doesn't have a __user markup. Defining kcontrols
1215 * with __user causes smatch warnings, so instead declare it
1216 * without __user and cast it as a userspace pointer where needed.
1218 if (!access_ok(p32, sizeof(*p32)) ||
1219 assign_in_user(&p32->which, &p64->which) ||
1220 get_user(count, &p64->count) ||
1221 put_user(count, &p32->count) ||
1222 assign_in_user(&p32->error_idx, &p64->error_idx) ||
1223 assign_in_user(&p32->request_fd, &p64->request_fd) ||
1224 copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)) ||
1225 get_user(kcontrols, &p64->controls))
1228 if (!count || count > (U32_MAX/sizeof(*ucontrols)))
1230 if (get_user(p, &p32->controls))
1232 ucontrols = compat_ptr(p);
1233 if (!access_ok(ucontrols, count * sizeof(*ucontrols)))
1236 for (n = 0; n < count; n++) {
1237 unsigned int size = sizeof(*ucontrols);
1240 if (get_user_cast(id, &kcontrols->id) ||
1241 put_user(id, &ucontrols->id) ||
1242 assign_in_user_cast(&ucontrols->size, &kcontrols->size) ||
1243 copy_in_user(&ucontrols->reserved2,
1244 (void __user *)&kcontrols->reserved2,
1245 sizeof(ucontrols->reserved2)))
1249 * Do not modify the pointer when copying a pointer control.
1250 * The contents of the pointer was changed, not the pointer
1253 if (ctrl_is_pointer(file, id))
1254 size -= sizeof(ucontrols->value64);
1256 if (copy_in_user(ucontrols,
1257 (void __user *)kcontrols, size))
1266 #ifdef CONFIG_X86_64
1268 * x86 is the only compat architecture with different struct alignment
1269 * between 32-bit and 64-bit tasks.
1271 * On all other architectures, v4l2_event32 and v4l2_event32_time32 are
1272 * the same as v4l2_event and v4l2_event_time32, so we can use the native
1273 * handlers, converting v4l2_event to v4l2_event_time32 if necessary.
1275 struct v4l2_event32 {
1291 struct v4l2_event32_time32 {
1299 struct old_timespec32 timestamp;
1304 static int put_v4l2_event32(struct v4l2_event __user *p64,
1305 struct v4l2_event32 __user *p32)
1307 if (!access_ok(p32, sizeof(*p32)) ||
1308 assign_in_user(&p32->type, &p64->type) ||
1309 copy_in_user(&p32->u, &p64->u, sizeof(p64->u)) ||
1310 assign_in_user(&p32->pending, &p64->pending) ||
1311 assign_in_user(&p32->sequence, &p64->sequence) ||
1312 assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) ||
1313 assign_in_user(&p32->timestamp.tv_nsec, &p64->timestamp.tv_nsec) ||
1314 assign_in_user(&p32->id, &p64->id) ||
1315 copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
1320 static int put_v4l2_event32_time32(struct v4l2_event_time32 __user *p64,
1321 struct v4l2_event32_time32 __user *p32)
1323 if (!access_ok(p32, sizeof(*p32)) ||
1324 assign_in_user(&p32->type, &p64->type) ||
1325 copy_in_user(&p32->u, &p64->u, sizeof(p64->u)) ||
1326 assign_in_user(&p32->pending, &p64->pending) ||
1327 assign_in_user(&p32->sequence, &p64->sequence) ||
1328 assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) ||
1329 assign_in_user(&p32->timestamp.tv_nsec, &p64->timestamp.tv_nsec) ||
1330 assign_in_user(&p32->id, &p64->id) ||
1331 copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
1337 struct v4l2_edid32 {
1342 compat_caddr_t edid;
1345 static int get_v4l2_edid32(struct v4l2_edid __user *p64,
1346 struct v4l2_edid32 __user *p32)
1350 if (!access_ok(p32, sizeof(*p32)) ||
1351 assign_in_user(&p64->pad, &p32->pad) ||
1352 assign_in_user(&p64->start_block, &p32->start_block) ||
1353 assign_in_user_cast(&p64->blocks, &p32->blocks) ||
1354 get_user(tmp, &p32->edid) ||
1355 put_user_force(compat_ptr(tmp), &p64->edid) ||
1356 copy_in_user(p64->reserved, p32->reserved, sizeof(p64->reserved)))
1361 static int put_v4l2_edid32(struct v4l2_edid __user *p64,
1362 struct v4l2_edid32 __user *p32)
1366 if (!access_ok(p32, sizeof(*p32)) ||
1367 assign_in_user(&p32->pad, &p64->pad) ||
1368 assign_in_user(&p32->start_block, &p64->start_block) ||
1369 assign_in_user(&p32->blocks, &p64->blocks) ||
1370 get_user(edid, &p64->edid) ||
1371 put_user(ptr_to_compat((void __user *)edid), &p32->edid) ||
1372 copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
1378 * List of ioctls that require 32-bits/64-bits conversion
1380 * The V4L2 ioctls that aren't listed there don't have pointer arguments
1381 * and the struct size is identical for both 32 and 64 bits versions, so
1382 * they don't need translations.
1385 #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
1386 #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
1387 #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
1388 #define VIDIOC_QUERYBUF32_TIME32 _IOWR('V', 9, struct v4l2_buffer32_time32)
1389 #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
1390 #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
1391 #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
1392 #define VIDIOC_QBUF32_TIME32 _IOWR('V', 15, struct v4l2_buffer32_time32)
1393 #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
1394 #define VIDIOC_DQBUF32_TIME32 _IOWR('V', 17, struct v4l2_buffer32_time32)
1395 #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
1396 #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
1397 #define VIDIOC_G_EDID32 _IOWR('V', 40, struct v4l2_edid32)
1398 #define VIDIOC_S_EDID32 _IOWR('V', 41, struct v4l2_edid32)
1399 #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
1400 #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
1401 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
1402 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
1403 #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
1404 #define VIDIOC_DQEVENT32_TIME32 _IOR ('V', 89, struct v4l2_event32_time32)
1405 #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
1406 #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
1407 #define VIDIOC_PREPARE_BUF32_TIME32 _IOWR('V', 93, struct v4l2_buffer32_time32)
1409 #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
1410 #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
1411 #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
1412 #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
1413 #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
1414 #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
1415 #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
1418 * alloc_userspace() - Allocates a 64-bits userspace pointer compatible
1419 * for calling the native 64-bits version of an ioctl.
1421 * @size: size of the structure itself to be allocated.
1422 * @aux_space: extra size needed to store "extra" data, e.g. space for
1423 * other __user data that is pointed to fields inside the
1425 * @new_p64: pointer to a pointer to be filled with the allocated struct.
1429 * if it can't allocate memory, either -ENOMEM or -EFAULT will be returned.
1432 static int alloc_userspace(unsigned int size, u32 aux_space,
1433 void __user **new_p64)
1435 *new_p64 = compat_alloc_user_space(size + aux_space);
1438 if (clear_user(*new_p64, size))
1444 * do_video_ioctl() - Ancillary function with handles a compat32 ioctl call
1446 * @file: pointer to &struct file with the file handler
1447 * @cmd: ioctl to be called
1448 * @arg: arguments passed from/to the ioctl handler
1450 * This function is called when a 32 bits application calls a V4L2 ioctl
1451 * and the Kernel is compiled with 64 bits.
1453 * This function is called by v4l2_compat_ioctl32() when the function is
1454 * not private to some specific driver.
1456 * It converts a 32-bits struct into a 64 bits one, calls the native 64-bits
1457 * ioctl handler and fills back the 32-bits struct with the results of the
1460 static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1462 void __user *p32 = compat_ptr(arg);
1463 void __user *new_p64 = NULL;
1464 void __user *aux_buf;
1466 int compatible_arg = 1;
1471 * 1. When struct size is different, converts the command.
1474 case VIDIOC_G_FMT32: ncmd = VIDIOC_G_FMT; break;
1475 case VIDIOC_S_FMT32: ncmd = VIDIOC_S_FMT; break;
1476 case VIDIOC_QUERYBUF32: ncmd = VIDIOC_QUERYBUF; break;
1477 case VIDIOC_QUERYBUF32_TIME32: ncmd = VIDIOC_QUERYBUF_TIME32; break;
1478 case VIDIOC_G_FBUF32: ncmd = VIDIOC_G_FBUF; break;
1479 case VIDIOC_S_FBUF32: ncmd = VIDIOC_S_FBUF; break;
1480 case VIDIOC_QBUF32: ncmd = VIDIOC_QBUF; break;
1481 case VIDIOC_QBUF32_TIME32: ncmd = VIDIOC_QBUF_TIME32; break;
1482 case VIDIOC_DQBUF32: ncmd = VIDIOC_DQBUF; break;
1483 case VIDIOC_DQBUF32_TIME32: ncmd = VIDIOC_DQBUF_TIME32; break;
1484 case VIDIOC_ENUMSTD32: ncmd = VIDIOC_ENUMSTD; break;
1485 case VIDIOC_ENUMINPUT32: ncmd = VIDIOC_ENUMINPUT; break;
1486 case VIDIOC_TRY_FMT32: ncmd = VIDIOC_TRY_FMT; break;
1487 case VIDIOC_G_EXT_CTRLS32: ncmd = VIDIOC_G_EXT_CTRLS; break;
1488 case VIDIOC_S_EXT_CTRLS32: ncmd = VIDIOC_S_EXT_CTRLS; break;
1489 case VIDIOC_TRY_EXT_CTRLS32: ncmd = VIDIOC_TRY_EXT_CTRLS; break;
1490 #ifdef CONFIG_X86_64
1491 case VIDIOC_DQEVENT32: ncmd = VIDIOC_DQEVENT; break;
1492 case VIDIOC_DQEVENT32_TIME32: ncmd = VIDIOC_DQEVENT_TIME32; break;
1494 case VIDIOC_OVERLAY32: ncmd = VIDIOC_OVERLAY; break;
1495 case VIDIOC_STREAMON32: ncmd = VIDIOC_STREAMON; break;
1496 case VIDIOC_STREAMOFF32: ncmd = VIDIOC_STREAMOFF; break;
1497 case VIDIOC_G_INPUT32: ncmd = VIDIOC_G_INPUT; break;
1498 case VIDIOC_S_INPUT32: ncmd = VIDIOC_S_INPUT; break;
1499 case VIDIOC_G_OUTPUT32: ncmd = VIDIOC_G_OUTPUT; break;
1500 case VIDIOC_S_OUTPUT32: ncmd = VIDIOC_S_OUTPUT; break;
1501 case VIDIOC_CREATE_BUFS32: ncmd = VIDIOC_CREATE_BUFS; break;
1502 case VIDIOC_PREPARE_BUF32: ncmd = VIDIOC_PREPARE_BUF; break;
1503 case VIDIOC_PREPARE_BUF32_TIME32: ncmd = VIDIOC_PREPARE_BUF_TIME32; break;
1504 case VIDIOC_G_EDID32: ncmd = VIDIOC_G_EDID; break;
1505 case VIDIOC_S_EDID32: ncmd = VIDIOC_S_EDID; break;
1506 default: ncmd = cmd; break;
1510 * 2. Allocates a 64-bits userspace pointer to store the
1511 * values of the ioctl and copy data from the 32-bits __user
1515 case VIDIOC_OVERLAY32:
1516 case VIDIOC_STREAMON32:
1517 case VIDIOC_STREAMOFF32:
1518 case VIDIOC_S_INPUT32:
1519 case VIDIOC_S_OUTPUT32:
1520 err = alloc_userspace(sizeof(unsigned int), 0, &new_p64);
1521 if (!err && assign_in_user((unsigned int __user *)new_p64,
1522 (compat_uint_t __user *)p32))
1527 case VIDIOC_G_INPUT32:
1528 case VIDIOC_G_OUTPUT32:
1529 err = alloc_userspace(sizeof(unsigned int), 0, &new_p64);
1533 case VIDIOC_G_EDID32:
1534 case VIDIOC_S_EDID32:
1535 err = alloc_userspace(sizeof(struct v4l2_edid), 0, &new_p64);
1537 err = get_v4l2_edid32(new_p64, p32);
1541 case VIDIOC_G_FMT32:
1542 case VIDIOC_S_FMT32:
1543 case VIDIOC_TRY_FMT32:
1544 err = bufsize_v4l2_format(p32, &aux_space);
1546 err = alloc_userspace(sizeof(struct v4l2_format),
1547 aux_space, &new_p64);
1549 aux_buf = new_p64 + sizeof(struct v4l2_format);
1550 err = get_v4l2_format32(new_p64, p32,
1551 aux_buf, aux_space);
1556 case VIDIOC_CREATE_BUFS32:
1557 err = bufsize_v4l2_create(p32, &aux_space);
1559 err = alloc_userspace(sizeof(struct v4l2_create_buffers),
1560 aux_space, &new_p64);
1562 aux_buf = new_p64 + sizeof(struct v4l2_create_buffers);
1563 err = get_v4l2_create32(new_p64, p32,
1564 aux_buf, aux_space);
1569 case VIDIOC_PREPARE_BUF32:
1570 case VIDIOC_QUERYBUF32:
1572 case VIDIOC_DQBUF32:
1573 err = bufsize_v4l2_buffer(p32, &aux_space);
1575 err = alloc_userspace(sizeof(struct v4l2_buffer),
1576 aux_space, &new_p64);
1578 aux_buf = new_p64 + sizeof(struct v4l2_buffer);
1579 err = get_v4l2_buffer32(new_p64, p32,
1580 aux_buf, aux_space);
1585 case VIDIOC_PREPARE_BUF32_TIME32:
1586 case VIDIOC_QUERYBUF32_TIME32:
1587 case VIDIOC_QBUF32_TIME32:
1588 case VIDIOC_DQBUF32_TIME32:
1589 err = bufsize_v4l2_buffer_time32(p32, &aux_space);
1591 err = alloc_userspace(sizeof(struct v4l2_buffer),
1592 aux_space, &new_p64);
1594 aux_buf = new_p64 + sizeof(struct v4l2_buffer);
1595 err = get_v4l2_buffer32_time32(new_p64, p32,
1596 aux_buf, aux_space);
1601 case VIDIOC_S_FBUF32:
1602 err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0,
1605 err = get_v4l2_framebuffer32(new_p64, p32);
1609 case VIDIOC_G_FBUF32:
1610 err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0,
1615 case VIDIOC_ENUMSTD32:
1616 err = alloc_userspace(sizeof(struct v4l2_standard), 0,
1619 err = get_v4l2_standard32(new_p64, p32);
1623 case VIDIOC_ENUMINPUT32:
1624 err = alloc_userspace(sizeof(struct v4l2_input), 0, &new_p64);
1626 err = get_v4l2_input32(new_p64, p32);
1630 case VIDIOC_G_EXT_CTRLS32:
1631 case VIDIOC_S_EXT_CTRLS32:
1632 case VIDIOC_TRY_EXT_CTRLS32:
1633 err = bufsize_v4l2_ext_controls(p32, &aux_space);
1635 err = alloc_userspace(sizeof(struct v4l2_ext_controls),
1636 aux_space, &new_p64);
1638 aux_buf = new_p64 + sizeof(struct v4l2_ext_controls);
1639 err = get_v4l2_ext_controls32(file, new_p64, p32,
1640 aux_buf, aux_space);
1644 #ifdef CONFIG_X86_64
1645 case VIDIOC_DQEVENT32:
1646 err = alloc_userspace(sizeof(struct v4l2_event), 0, &new_p64);
1649 case VIDIOC_DQEVENT32_TIME32:
1650 err = alloc_userspace(sizeof(struct v4l2_event_time32), 0, &new_p64);
1659 * 3. Calls the native 64-bits ioctl handler.
1661 * For the functions where a conversion was not needed,
1662 * compatible_arg is true, and it will call it with the arguments
1663 * provided by userspace and stored at @p32 var.
1665 * Otherwise, it will pass the newly allocated @new_p64 argument.
1668 err = native_ioctl(file, ncmd, (unsigned long)p32);
1670 err = native_ioctl(file, ncmd, (unsigned long)new_p64);
1676 * 4. Special case: even after an error we need to put the
1677 * results back for some ioctls.
1679 * In the case of EXT_CTRLS, the error_idx will contain information
1680 * on which control failed.
1682 * In the case of S_EDID, the driver can return E2BIG and set
1683 * the blocks to maximum allowed value.
1686 case VIDIOC_G_EXT_CTRLS32:
1687 case VIDIOC_S_EXT_CTRLS32:
1688 case VIDIOC_TRY_EXT_CTRLS32:
1689 if (put_v4l2_ext_controls32(file, new_p64, p32))
1692 case VIDIOC_S_EDID32:
1693 if (put_v4l2_edid32(new_p64, p32))
1701 * 5. Copy the data returned at the 64 bits userspace pointer to
1702 * the original 32 bits structure.
1705 case VIDIOC_S_INPUT32:
1706 case VIDIOC_S_OUTPUT32:
1707 case VIDIOC_G_INPUT32:
1708 case VIDIOC_G_OUTPUT32:
1709 if (assign_in_user((compat_uint_t __user *)p32,
1710 ((unsigned int __user *)new_p64)))
1714 case VIDIOC_G_FBUF32:
1715 err = put_v4l2_framebuffer32(new_p64, p32);
1718 #ifdef CONFIG_X86_64
1719 case VIDIOC_DQEVENT32:
1720 err = put_v4l2_event32(new_p64, p32);
1723 case VIDIOC_DQEVENT32_TIME32:
1724 err = put_v4l2_event32_time32(new_p64, p32);
1728 case VIDIOC_G_EDID32:
1729 err = put_v4l2_edid32(new_p64, p32);
1732 case VIDIOC_G_FMT32:
1733 case VIDIOC_S_FMT32:
1734 case VIDIOC_TRY_FMT32:
1735 err = put_v4l2_format32(new_p64, p32);
1738 case VIDIOC_CREATE_BUFS32:
1739 err = put_v4l2_create32(new_p64, p32);
1742 case VIDIOC_PREPARE_BUF32:
1743 case VIDIOC_QUERYBUF32:
1745 case VIDIOC_DQBUF32:
1746 err = put_v4l2_buffer32(new_p64, p32);
1749 case VIDIOC_PREPARE_BUF32_TIME32:
1750 case VIDIOC_QUERYBUF32_TIME32:
1751 case VIDIOC_QBUF32_TIME32:
1752 case VIDIOC_DQBUF32_TIME32:
1753 err = put_v4l2_buffer32_time32(new_p64, p32);
1756 case VIDIOC_ENUMSTD32:
1757 err = put_v4l2_standard32(new_p64, p32);
1760 case VIDIOC_ENUMINPUT32:
1761 err = put_v4l2_input32(new_p64, p32);
1768 * v4l2_compat_ioctl32() - Handles a compat32 ioctl call
1770 * @file: pointer to &struct file with the file handler
1771 * @cmd: ioctl to be called
1772 * @arg: arguments passed from/to the ioctl handler
1774 * This function is meant to be used as .compat_ioctl fops at v4l2-dev.c
1775 * in order to deal with 32-bit calls on a 64-bits Kernel.
1777 * This function calls do_video_ioctl() for non-private V4L2 ioctls.
1778 * If the function is a private one it calls vdev->fops->compat_ioctl32
1781 long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
1783 struct video_device *vdev = video_devdata(file);
1784 long ret = -ENOIOCTLCMD;
1786 if (!file->f_op->unlocked_ioctl)
1789 if (_IOC_TYPE(cmd) == 'V' && _IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)
1790 ret = do_video_ioctl(file, cmd, arg);
1791 else if (vdev->fops->compat_ioctl32)
1792 ret = vdev->fops->compat_ioctl32(file, cmd, arg);
1794 if (ret == -ENOIOCTLCMD)
1795 pr_debug("compat_ioctl32: unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
1796 _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), cmd);
1799 EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32);