1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189 |
- /*
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- * Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
- *
- * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
- * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
- * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
- * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
- * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
- * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
- *
- * These routines maintain argument size conversion between 32bit and 64bit
- * ioctls.
- */
- #include <linux/compat.h>
- #include <linux/module.h>
- #include <linux/videodev2.h>
- #include <media/v4l2-dev.h>
- #include <media/v4l2-ioctl.h>
- #define convert_in_user(srcptr, dstptr) \
- ({ \
- typeof(*srcptr) val; \
- \
- get_user(val, srcptr) || put_user(val, dstptr); \
- })
- static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
- {
- long ret = -ENOIOCTLCMD;
- if (file->f_op->unlocked_ioctl)
- ret = file->f_op->unlocked_ioctl(file, cmd, arg);
- return ret;
- }
- struct v4l2_clip32 {
- struct v4l2_rect c;
- compat_caddr_t next;
- };
- struct v4l2_window32 {
- struct v4l2_rect w;
- enum v4l2_field field;
- __u32 chromakey;
- compat_caddr_t clips; /* actually struct v4l2_clip32 * */
- __u32 clipcount;
- compat_caddr_t bitmap;
- };
- static int bufsize_v4l2_window32(struct v4l2_window32 __user *up)
- {
- __u32 clipcount;
- if (get_user(clipcount, &up->clipcount))
- return -EFAULT;
- if (clipcount > 2048)
- return -EINVAL;
- return clipcount * sizeof(struct v4l2_clip);
- }
- static int get_v4l2_window32(struct v4l2_window __user *kp, struct
- v4l2_window32 __user *up, void __user *aux_buf, int aux_space)
- {
- __u32 clipcount;
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
- copy_in_user(&kp->w, &up->w, sizeof(up->w)) ||
- convert_in_user(&up->field, &kp->field) ||
- convert_in_user(&up->chromakey, &kp->chromakey) ||
- get_user(clipcount, &up->clipcount) ||
- put_user(clipcount, &kp->clipcount))
- return -EFAULT;
- if (clipcount > 2048)
- return -EINVAL;
- if (clipcount) {
- struct v4l2_clip32 __user *uclips;
- struct v4l2_clip __user *kclips;
- int n = clipcount;
- compat_caddr_t p;
- if (get_user(p, &up->clips))
- return -EFAULT;
- uclips = compat_ptr(p);
- if (aux_space < n * sizeof(struct v4l2_clip))
- return -EFAULT;
- kclips = aux_buf;
- if (put_user(kclips, &kp->clips))
- return -EFAULT;
- while (--n >= 0) {
- if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
- return -EFAULT;
- if (put_user(n ? kclips + 1 : NULL, &kclips->next))
- return -EFAULT;
- uclips += 1;
- kclips += 1;
- }
- } else {
- if (put_user(NULL, &kp->clips))
- return -EFAULT;
- }
- return 0;
- }
- static int put_v4l2_window32(struct v4l2_window __user *kp, struct v4l2_window32 __user *up)
- {
- if (copy_in_user(&up->w, &kp->w, sizeof(kp->w)) ||
- convert_in_user(&kp->field, &up->field) ||
- convert_in_user(&kp->chromakey, &up->chromakey) ||
- convert_in_user(&kp->clipcount, &up->clipcount))
- return -EFAULT;
- return 0;
- }
- static inline int get_v4l2_pix_format(struct v4l2_pix_format __user *kp, struct v4l2_pix_format __user *up)
- {
- if (copy_in_user(kp, up, sizeof(struct v4l2_pix_format)))
- return -EFAULT;
- return 0;
- }
- static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane __user *kp,
- struct v4l2_pix_format_mplane __user *up)
- {
- if (copy_in_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
- return -EFAULT;
- return 0;
- }
- static inline int put_v4l2_pix_format(struct v4l2_pix_format __user *kp, struct v4l2_pix_format __user *up)
- {
- if (copy_in_user(up, kp, sizeof(struct v4l2_pix_format)))
- return -EFAULT;
- return 0;
- }
- static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane __user *kp,
- struct v4l2_pix_format_mplane __user *up)
- {
- if (copy_in_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
- return -EFAULT;
- return 0;
- }
- static inline int get_v4l2_vbi_format(struct v4l2_vbi_format __user *kp, struct v4l2_vbi_format __user *up)
- {
- if (copy_in_user(kp, up, sizeof(struct v4l2_vbi_format)))
- return -EFAULT;
- return 0;
- }
- static inline int put_v4l2_vbi_format(struct v4l2_vbi_format __user *kp, struct v4l2_vbi_format __user *up)
- {
- if (copy_in_user(up, kp, sizeof(struct v4l2_vbi_format)))
- return -EFAULT;
- return 0;
- }
- static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format __user *kp, struct v4l2_sliced_vbi_format __user *up)
- {
- if (copy_in_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
- return -EFAULT;
- return 0;
- }
- static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format __user *kp, struct v4l2_sliced_vbi_format __user *up)
- {
- if (copy_in_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
- return -EFAULT;
- return 0;
- }
- struct v4l2_format32 {
- enum v4l2_buf_type type;
- union {
- struct v4l2_pix_format pix;
- struct v4l2_pix_format_mplane pix_mp;
- struct v4l2_window32 win;
- struct v4l2_vbi_format vbi;
- struct v4l2_sliced_vbi_format sliced;
- __u8 raw_data[200]; /* user-defined */
- } fmt;
- };
- /**
- * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument
- * @index: on return, index of the first created buffer
- * @count: entry: number of requested buffers,
- * return: number of created buffers
- * @memory: buffer memory type
- * @format: frame format, for which buffers are requested
- * @reserved: future extensions
- */
- struct v4l2_create_buffers32 {
- __u32 index;
- __u32 count;
- enum v4l2_memory memory;
- struct v4l2_format32 format;
- __u32 reserved[8];
- };
- static int __bufsize_v4l2_format32(struct v4l2_format32 __user *up)
- {
- __u32 type;
- if (get_user(type, &up->type))
- return -EFAULT;
- switch (type) {
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
- return bufsize_v4l2_window32(&up->fmt.win);
- default:
- return 0;
- }
- }
- static int __get_v4l2_format32(struct v4l2_format __user *kp, struct
- v4l2_format32 __user *up, void __user *aux_buf, int aux_space)
- {
- __u32 type;
- if (get_user(type, &up->type) || put_user(type, &kp->type))
- return -EFAULT;
- switch (type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT:
- return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
- case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
- return get_v4l2_pix_format_mplane(&kp->fmt.pix_mp,
- &up->fmt.pix_mp);
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
- return get_v4l2_window32(&kp->fmt.win, &up->fmt.win, aux_buf, aux_space);
- case V4L2_BUF_TYPE_VBI_CAPTURE:
- case V4L2_BUF_TYPE_VBI_OUTPUT:
- return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
- case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
- case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
- return get_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
- case V4L2_BUF_TYPE_PRIVATE:
- if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data)))
- return -EFAULT;
- return 0;
- default:
- printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
- kp->type);
- return -EINVAL;
- }
- }
- static int bufsize_v4l2_format32(struct v4l2_format32 __user *up)
- {
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)))
- return -EFAULT;
- return __bufsize_v4l2_format32(up);
- }
- static int get_v4l2_format32(struct v4l2_format __user *kp, struct
- v4l2_format32 __user *up, void __user *aux_buf, int aux_space)
- {
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)))
- return -EFAULT;
- return __get_v4l2_format32(kp, up, aux_buf, aux_space);
- }
- static int bufsize_v4l2_create32(struct v4l2_create_buffers32 __user *up)
- {
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)))
- return -EFAULT;
- return __bufsize_v4l2_format32(&up->format);
- }
- static int get_v4l2_create32(struct v4l2_create_buffers __user *kp, struct
- v4l2_create_buffers32 __user *up, void __user *aux_buf,
- int aux_space)
- {
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) ||
- copy_in_user(kp, up, offsetof(struct v4l2_create_buffers32, format.fmt)))
- return -EFAULT;
- return __get_v4l2_format32(&kp->format, &up->format, aux_buf, aux_space);
- }
- static int __put_v4l2_format32(struct v4l2_format __user *kp, struct v4l2_format32 __user *up)
- {
- __u32 type;
- if (get_user(type, &kp->type))
- return -EFAULT;
- switch (type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT:
- return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
- case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
- return put_v4l2_pix_format_mplane(&kp->fmt.pix_mp,
- &up->fmt.pix_mp);
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
- return put_v4l2_window32(&kp->fmt.win, &up->fmt.win);
- case V4L2_BUF_TYPE_VBI_CAPTURE:
- case V4L2_BUF_TYPE_VBI_OUTPUT:
- return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
- case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
- case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
- return put_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
- case V4L2_BUF_TYPE_PRIVATE:
- if (copy_to_user(up, kp, sizeof(up->fmt.raw_data)))
- return -EFAULT;
- return 0;
- default:
- printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
- kp->type);
- return -EINVAL;
- }
- }
- static int put_v4l2_format32(struct v4l2_format __user *kp, struct v4l2_format32 __user *up)
- {
- if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
- put_user(kp->type, &up->type))
- return -EFAULT;
- return __put_v4l2_format32(kp, up);
- }
- static int put_v4l2_create32(struct v4l2_create_buffers __user *kp, struct v4l2_create_buffers32 __user *up)
- {
- if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) ||
- copy_in_user(up, kp, offsetof(struct v4l2_create_buffers32, format.fmt)))
- return -EFAULT;
- return __put_v4l2_format32(&kp->format, &up->format);
- }
- struct v4l2_standard32 {
- __u32 index;
- __u32 id[2]; /* __u64 would get the alignment wrong */
- __u8 name[24];
- struct v4l2_fract frameperiod; /* Frames, not fields */
- __u32 framelines;
- __u32 reserved[4];
- };
- static int get_v4l2_standard32(struct v4l2_standard __user *kp, struct v4l2_standard32 __user *up)
- {
- /* other fields are not set by the user, nor used by the driver */
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
- convert_in_user(&up->index, &kp->index))
- return -EFAULT;
- return 0;
- }
- static int put_v4l2_standard32(struct v4l2_standard __user *kp, struct v4l2_standard32 __user *up)
- {
- if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
- convert_in_user(&kp->index, &up->index) ||
- copy_in_user(up->id, &kp->id, sizeof(__u64)) ||
- copy_in_user(up->name, kp->name, 24) ||
- copy_in_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) ||
- convert_in_user(&kp->framelines, &up->framelines) ||
- copy_in_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
- return -EFAULT;
- return 0;
- }
- struct v4l2_plane32 {
- __u32 bytesused;
- __u32 length;
- union {
- __u32 mem_offset;
- compat_long_t userptr;
- } m;
- __u32 data_offset;
- __u32 reserved[11];
- };
- struct v4l2_buffer32 {
- __u32 index;
- enum v4l2_buf_type type;
- __u32 bytesused;
- __u32 flags;
- enum v4l2_field field;
- struct compat_timeval timestamp;
- struct v4l2_timecode timecode;
- __u32 sequence;
- /* memory location */
- enum v4l2_memory memory;
- union {
- __u32 offset;
- compat_long_t userptr;
- compat_caddr_t planes;
- } m;
- __u32 length;
- __u32 input;
- __u32 reserved;
- };
- static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
- enum v4l2_memory memory)
- {
- compat_long_t p;
- if (copy_in_user(up, up32, 2 * sizeof(__u32)) ||
- copy_in_user(&up->data_offset, &up32->data_offset,
- sizeof(__u32)))
- return -EFAULT;
- if (memory == V4L2_MEMORY_USERPTR) {
- if (get_user(p, &up32->m.userptr) ||
- put_user((unsigned long) compat_ptr(p),
- &up->m.userptr))
- return -EFAULT;
- } else {
- if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset,
- sizeof(__u32)))
- return -EFAULT;
- }
- return 0;
- }
- static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
- enum v4l2_memory memory)
- {
- if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
- copy_in_user(&up32->data_offset, &up->data_offset,
- sizeof(__u32)))
- return -EFAULT;
- /* For MMAP, driver might've set up the offset, so copy it back.
- * USERPTR stays the same (was userspace-provided), so no copying. */
- if (memory == V4L2_MEMORY_MMAP)
- if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset,
- sizeof(__u32)))
- return -EFAULT;
- return 0;
- }
- static int bufsize_v4l2_buffer32(struct v4l2_buffer32 __user *up)
- {
- __u32 type;
- __u32 length;
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
- get_user(type, &up->type) ||
- get_user(length, &up->length))
- return -EFAULT;
- if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
- if (length > VIDEO_MAX_PLANES)
- return -EINVAL;
- /* We don't really care if userspace decides to kill itself
- * by passing a very big length value
- */
- return length * sizeof(struct v4l2_plane);
- }
- return 0;
- }
- static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, struct
- v4l2_buffer32 __user *up, void __user *aux_buf, int aux_space)
- {
- __u32 type;
- __u32 length;
- enum v4l2_memory memory;
- struct v4l2_plane32 __user *uplane32;
- struct v4l2_plane __user *uplane;
- compat_caddr_t p;
- int num_planes;
- int ret;
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
- convert_in_user(&up->index, &kp->index) ||
- get_user(type, &up->type) ||
- put_user(type, &kp->type) ||
- convert_in_user(&up->flags, &kp->flags) ||
- get_user(memory, &up->memory) ||
- put_user(memory, &kp->memory) ||
- convert_in_user(&up->input, &kp->input) ||
- get_user(length, &up->length) ||
- put_user(length, &kp->length))
- return -EFAULT;
- if (V4L2_TYPE_IS_OUTPUT(type))
- if (convert_in_user(&up->bytesused, &kp->bytesused) ||
- convert_in_user(&up->field, &kp->field) ||
- convert_in_user(&up->timestamp.tv_sec, &kp->timestamp.tv_sec) ||
- convert_in_user(&up->timestamp.tv_usec,
- &kp->timestamp.tv_usec))
- return -EFAULT;
- if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
- num_planes = length;
- if (num_planes == 0) {
- /* num_planes == 0 is legal, e.g. when userspace doesn't
- * need planes array on DQBUF*/
- return put_user(NULL, &kp->m.planes);
- }
- if (get_user(p, &up->m.planes))
- return -EFAULT;
- uplane32 = compat_ptr(p);
- if (!access_ok(VERIFY_READ, uplane32,
- num_planes * sizeof(struct v4l2_plane32)))
- return -EFAULT;
- /* We don't really care if userspace decides to kill itself
- * by passing a very big num_planes value */
- if (aux_space < num_planes * sizeof(struct v4l2_plane))
- return -EFAULT;
- uplane = aux_buf;
- if (put_user((__force struct v4l2_plane *)uplane,
- &kp->m.planes))
- return -EFAULT;
- while (--num_planes >= 0) {
- ret = get_v4l2_plane32(uplane, uplane32, memory);
- if (ret)
- return ret;
- ++uplane;
- ++uplane32;
- }
- } else {
- switch (memory) {
- case V4L2_MEMORY_MMAP:
- if (convert_in_user(&up->m.offset, &kp->m.offset))
- return -EFAULT;
- break;
- case V4L2_MEMORY_USERPTR:
- {
- compat_long_t tmp;
- if (get_user(tmp, &up->m.userptr) ||
- put_user((unsigned long)
- compat_ptr(tmp),
- &kp->m.userptr))
- return -EFAULT;
- }
- break;
- case V4L2_MEMORY_OVERLAY:
- if (convert_in_user(&up->m.offset, &kp->m.offset))
- return -EFAULT;
- break;
- }
- }
- return 0;
- }
- static int put_v4l2_buffer32(struct v4l2_buffer __user *kp, struct v4l2_buffer32 __user *up)
- {
- __u32 type;
- __u32 length;
- enum v4l2_memory memory;
- struct v4l2_plane32 __user *uplane32;
- struct v4l2_plane __user *uplane;
- compat_caddr_t p;
- int num_planes;
- int ret;
- if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) ||
- convert_in_user(&kp->index, &up->index) ||
- get_user(type, &kp->type) ||
- put_user(type, &up->type) ||
- convert_in_user(&kp->flags, &up->flags) ||
- get_user(memory, &kp->memory) ||
- put_user(memory, &up->memory) ||
- convert_in_user(&kp->input, &up->input))
- return -EFAULT;
- if (convert_in_user(&kp->bytesused, &up->bytesused) ||
- convert_in_user(&kp->field, &up->field) ||
- convert_in_user(&kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
- convert_in_user(&kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
- copy_in_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
- convert_in_user(&kp->sequence, &up->sequence) ||
- convert_in_user(&kp->reserved, &up->reserved) ||
- get_user(length, &kp->length) ||
- put_user(length, &up->length))
- return -EFAULT;
- if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
- num_planes = length;
- if (num_planes == 0)
- return 0;
- if (get_user(uplane, ((__force struct v4l2_plane __user **)&kp->m.planes)))
- return -EFAULT;
- if (get_user(p, &up->m.planes))
- return -EFAULT;
- uplane32 = compat_ptr(p);
- while (--num_planes >= 0) {
- ret = put_v4l2_plane32(uplane, uplane32, memory);
- if (ret)
- return ret;
- ++uplane;
- ++uplane32;
- }
- } else {
- switch (memory) {
- case V4L2_MEMORY_MMAP:
- if (convert_in_user(&kp->m.offset, &up->m.offset))
- return -EFAULT;
- break;
- case V4L2_MEMORY_USERPTR:
- if (convert_in_user(&kp->m.userptr, &up->m.userptr))
- return -EFAULT;
- break;
- case V4L2_MEMORY_OVERLAY:
- if (convert_in_user(&kp->m.offset, &up->m.offset))
- return -EFAULT;
- break;
- }
- }
- return 0;
- }
- struct v4l2_framebuffer32 {
- __u32 capability;
- __u32 flags;
- compat_caddr_t base;
- struct v4l2_pix_format fmt;
- };
- static int get_v4l2_framebuffer32(struct v4l2_framebuffer __user *kp, struct v4l2_framebuffer32 __user *up)
- {
- compat_caddr_t tmp;
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) ||
- get_user(tmp, &up->base) ||
- put_user((__force void *)compat_ptr(tmp), &kp->base) ||
- convert_in_user(&up->capability, &kp->capability) ||
- convert_in_user(&up->flags, &kp->flags) ||
- get_v4l2_pix_format(&kp->fmt, &up->fmt))
- return -EFAULT;
- return 0;
- }
- static int put_v4l2_framebuffer32(struct v4l2_framebuffer __user *kp, struct v4l2_framebuffer32 __user *up)
- {
- void *base;
- if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) ||
- get_user(base, &kp->base) ||
- put_user(ptr_to_compat(base), &up->base) ||
- convert_in_user(&kp->capability, &up->capability) ||
- convert_in_user(&kp->flags, &up->flags) ||
- put_v4l2_pix_format(&kp->fmt, &up->fmt))
- return -EFAULT;
- return 0;
- }
- struct v4l2_input32 {
- __u32 index; /* Which input */
- __u8 name[32]; /* Label */
- __u32 type; /* Type of input */
- __u32 audioset; /* Associated audios (bitfield) */
- __u32 tuner; /* Associated tuner */
- v4l2_std_id std;
- __u32 status;
- __u32 reserved[4];
- } __attribute__ ((packed));
- /* The 64-bit v4l2_input struct has extra padding at the end of the struct.
- Otherwise it is identical to the 32-bit version. */
- static inline int get_v4l2_input32(struct v4l2_input __user *kp, struct v4l2_input32 __user *up)
- {
- if (copy_in_user(kp, up, sizeof(struct v4l2_input32)))
- return -EFAULT;
- return 0;
- }
- static inline int put_v4l2_input32(struct v4l2_input __user *kp, struct v4l2_input32 __user *up)
- {
- if (copy_in_user(up, kp, sizeof(struct v4l2_input32)))
- return -EFAULT;
- return 0;
- }
- struct v4l2_ext_controls32 {
- __u32 ctrl_class;
- __u32 count;
- __u32 error_idx;
- __u32 reserved[2];
- compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
- };
- struct v4l2_ext_control32 {
- __u32 id;
- __u32 size;
- __u32 reserved2[1];
- union {
- __s32 value;
- __s64 value64;
- compat_caddr_t string; /* actually char * */
- };
- } __attribute__ ((packed));
- /* The following function really belong in v4l2-common, but that causes
- a circular dependency between modules. We need to think about this, but
- for now this will do. */
- /* Return non-zero if this control is a pointer type. Currently only
- type STRING is a pointer type. */
- static inline int ctrl_is_pointer(u32 id)
- {
- switch (id) {
- case V4L2_CID_RDS_TX_PS_NAME:
- case V4L2_CID_RDS_TX_RADIO_TEXT:
- return 1;
- default:
- return 0;
- }
- }
- static int bufsize_v4l2_ext_controls32(struct v4l2_ext_controls32 __user *up)
- {
- __u32 count;
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) ||
- get_user(count, &up->count))
- return -EFAULT;
- if (count > V4L2_CID_MAX_CTRLS)
- return -EINVAL;
- return count * sizeof(struct v4l2_ext_control);
- }
- static int get_v4l2_ext_controls32(struct v4l2_ext_controls __user *kp, struct
- v4l2_ext_controls32 __user *up, void __user *aux_buf,
- int aux_space)
- {
- struct v4l2_ext_control32 __user *ucontrols;
- struct v4l2_ext_control __user *kcontrols;
- __u32 count;
- unsigned int n;
- compat_caddr_t p;
- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) ||
- convert_in_user(&up->ctrl_class, &kp->ctrl_class) ||
- get_user(count, &up->count) ||
- put_user(count, &kp->count) ||
- convert_in_user(&up->error_idx, &kp->error_idx) ||
- copy_in_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
- return -EFAULT;
- if (count == 0)
- return put_user(NULL, &kp->controls);
- if (get_user(p, &up->controls))
- return -EFAULT;
- ucontrols = compat_ptr(p);
- if (!access_ok(VERIFY_READ, ucontrols,
- count * sizeof(struct v4l2_ext_control32)))
- return -EFAULT;
- if (aux_space < count * sizeof(struct v4l2_ext_control))
- return -EFAULT;
- kcontrols = aux_buf;
- if (put_user((__force struct v4l2_ext_control *)kcontrols,
- &kp->controls))
- return -EFAULT;
- for (n = 0; n < count; n++) {
- if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
- return -EFAULT;
- if (ctrl_is_pointer(kcontrols->id)) {
- void __user *s;
- if (get_user(p, &ucontrols->string))
- return -EFAULT;
- s = compat_ptr(p);
- if (put_user(s, &kcontrols->string))
- return -EFAULT;
- }
- ucontrols++;
- kcontrols++;
- }
- return 0;
- }
- static int put_v4l2_ext_controls32(struct v4l2_ext_controls __user *kp, struct v4l2_ext_controls32 __user *up)
- {
- struct v4l2_ext_control32 __user *ucontrols;
- struct v4l2_ext_control __user *kcontrols;
- __u32 count;
- unsigned int n;
- compat_caddr_t p;
- if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) ||
- get_user(kcontrols, &kp->controls) ||
- convert_in_user(&kp->ctrl_class, &up->ctrl_class) ||
- get_user(count, &kp->count) ||
- put_user(count, &up->count) ||
- convert_in_user(&kp->error_idx, &up->error_idx) ||
- copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved)))
- return -EFAULT;
- if (!count)
- return 0;
- if (get_user(p, &up->controls))
- return -EFAULT;
- ucontrols = compat_ptr(p);
- if (!access_ok(VERIFY_WRITE, ucontrols,
- count * sizeof(struct v4l2_ext_control32)))
- return -EFAULT;
- for (n = 0; n < count; n++) {
- unsigned size = sizeof(*ucontrols);
- /* Do not modify the pointer when copying a pointer control.
- The contents of the pointer was changed, not the pointer
- itself. */
- if (ctrl_is_pointer(kcontrols->id))
- size -= sizeof(ucontrols->value64);
- if (copy_in_user(ucontrols, kcontrols, size))
- return -EFAULT;
- ucontrols++;
- kcontrols++;
- }
- return 0;
- }
- struct v4l2_event32 {
- __u32 type;
- union {
- __u8 data[64];
- } u;
- __u32 pending;
- __u32 sequence;
- struct compat_timespec timestamp;
- __u32 id;
- __u32 reserved[8];
- };
- static int put_v4l2_event32(struct v4l2_event __user *kp, struct v4l2_event32 __user *up)
- {
- if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_event32)) ||
- convert_in_user(&kp->type, &up->type) ||
- copy_in_user(&up->u, &kp->u, sizeof(kp->u)) ||
- convert_in_user(&kp->pending, &up->pending) ||
- convert_in_user(&kp->sequence, &up->sequence) ||
- convert_in_user(&kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
- convert_in_user(&kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) ||
- convert_in_user(&kp->id, &up->id) ||
- copy_in_user(up->reserved, kp->reserved, 8 * sizeof(__u32)))
- return -EFAULT;
- return 0;
- }
- #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
- #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
- #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
- #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
- #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
- #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
- #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
- #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
- #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
- #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
- #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
- #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
- #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
- #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
- #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
- #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
- #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
- #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
- #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
- #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
- #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
- #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
- #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
- /*
- * Note that these macros contain return statements to avoid the need for the
- * "caller" to check return values.
- */
- #define ALLOC_USER_SPACE(size) \
- ({ \
- void __user *up_native; \
- up_native = compat_alloc_user_space(size); \
- if (!up_native) \
- return -ENOMEM; \
- if (clear_user(up_native, size)) \
- return -EFAULT; \
- up_native; \
- })
- #define ALLOC_AND_GET(bufsizefunc, getfunc, structname) \
- do { \
- aux_space = bufsizefunc(up); \
- if (aux_space < 0) \
- return aux_space; \
- up_native = ALLOC_USER_SPACE(sizeof(struct structname) + aux_space); \
- aux_buf = up_native + sizeof(struct structname); \
- err = getfunc(up_native, up, aux_buf, aux_space); \
- } while (0)
- static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
- {
- void __user *up = compat_ptr(arg);
- void __user *up_native = NULL;
- void __user *aux_buf;
- int aux_space;
- int compatible_arg = 1;
- long err = 0;
- /* First, convert the command. */
- switch (cmd) {
- case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
- case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
- case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
- case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break;
- case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break;
- case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break;
- case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break;
- case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break;
- case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break;
- case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break;
- case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break;
- case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break;
- case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break;
- case VIDIOC_DQEVENT32: cmd = VIDIOC_DQEVENT; break;
- case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break;
- case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break;
- case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break;
- case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break;
- case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
- case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break;
- case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break;
- case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break;
- case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break;
- }
- switch (cmd) {
- case VIDIOC_OVERLAY:
- case VIDIOC_STREAMON:
- case VIDIOC_STREAMOFF:
- case VIDIOC_S_INPUT:
- case VIDIOC_S_OUTPUT:
- up_native = ALLOC_USER_SPACE(sizeof(unsigned __user));
- if (convert_in_user((compat_uint_t __user *)up,
- (unsigned __user *) up_native))
- return -EFAULT;
- compatible_arg = 0;
- break;
- case VIDIOC_G_INPUT:
- case VIDIOC_G_OUTPUT:
- up_native = ALLOC_USER_SPACE(sizeof(unsigned __user));
- compatible_arg = 0;
- break;
- case VIDIOC_G_FMT:
- case VIDIOC_S_FMT:
- case VIDIOC_TRY_FMT:
- ALLOC_AND_GET(bufsize_v4l2_format32, get_v4l2_format32, v4l2_format);
- compatible_arg = 0;
- break;
- case VIDIOC_CREATE_BUFS:
- ALLOC_AND_GET(bufsize_v4l2_create32, get_v4l2_create32, v4l2_create_buffers);
- compatible_arg = 0;
- break;
- case VIDIOC_PREPARE_BUF:
- case VIDIOC_QUERYBUF:
- case VIDIOC_QBUF:
- case VIDIOC_DQBUF:
- ALLOC_AND_GET(bufsize_v4l2_buffer32, get_v4l2_buffer32, v4l2_buffer);
- compatible_arg = 0;
- break;
- case VIDIOC_S_FBUF:
- up_native = ALLOC_USER_SPACE(sizeof(struct v4l2_framebuffer));
- err = get_v4l2_framebuffer32(up_native, up);
- compatible_arg = 0;
- break;
- case VIDIOC_G_FBUF:
- up_native = ALLOC_USER_SPACE(sizeof(struct v4l2_framebuffer));
- compatible_arg = 0;
- break;
- case VIDIOC_ENUMSTD:
- up_native = ALLOC_USER_SPACE(sizeof(struct v4l2_standard));
- err = get_v4l2_standard32(up_native, up);
- compatible_arg = 0;
- break;
- case VIDIOC_ENUMINPUT:
- up_native = ALLOC_USER_SPACE(sizeof(struct v4l2_input));
- err = get_v4l2_input32(up_native, up);
- compatible_arg = 0;
- break;
- case VIDIOC_G_EXT_CTRLS:
- case VIDIOC_S_EXT_CTRLS:
- case VIDIOC_TRY_EXT_CTRLS:
- ALLOC_AND_GET(bufsize_v4l2_ext_controls32, get_v4l2_ext_controls32, v4l2_ext_controls);
- compatible_arg = 0;
- break;
- case VIDIOC_DQEVENT:
- up_native = ALLOC_USER_SPACE(sizeof(struct v4l2_event));
- compatible_arg = 0;
- break;
- }
- if (err)
- return err;
- if (compatible_arg)
- err = native_ioctl(file, cmd, (unsigned long)up);
- else
- err = native_ioctl(file, cmd, (unsigned long)up_native);
- /* Special case: even after an error we need to put the
- results back for these ioctls since the error_idx will
- contain information on which control failed. */
- switch (cmd) {
- case VIDIOC_G_EXT_CTRLS:
- case VIDIOC_S_EXT_CTRLS:
- case VIDIOC_TRY_EXT_CTRLS:
- if (put_v4l2_ext_controls32(up_native, up))
- err = -EFAULT;
- break;
- }
- if (err)
- return err;
- switch (cmd) {
- case VIDIOC_S_INPUT:
- case VIDIOC_S_OUTPUT:
- case VIDIOC_G_INPUT:
- case VIDIOC_G_OUTPUT:
- err = convert_in_user(((unsigned __user *)up_native),
- (compat_uint_t __user *)up);
- break;
- case VIDIOC_G_FBUF:
- err = put_v4l2_framebuffer32(up_native, up);
- break;
- case VIDIOC_DQEVENT:
- err = put_v4l2_event32(up_native, up);
- break;
- case VIDIOC_G_FMT:
- case VIDIOC_S_FMT:
- case VIDIOC_TRY_FMT:
- err = put_v4l2_format32(up_native, up);
- break;
- case VIDIOC_CREATE_BUFS:
- err = put_v4l2_create32(up_native, up);
- break;
- case VIDIOC_QUERYBUF:
- case VIDIOC_QBUF:
- case VIDIOC_DQBUF:
- err = put_v4l2_buffer32(up_native, up);
- break;
- case VIDIOC_ENUMSTD:
- err = put_v4l2_standard32(up_native, up);
- break;
- case VIDIOC_ENUMINPUT:
- err = put_v4l2_input32(up_native, up);
- break;
- }
- return err;
- }
- long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
- {
- struct video_device *vdev = video_devdata(file);
- long ret = -ENOIOCTLCMD;
- if (!file->f_op->unlocked_ioctl)
- return ret;
- switch (cmd) {
- case VIDIOC_QUERYCAP:
- case VIDIOC_RESERVED:
- case VIDIOC_ENUM_FMT:
- case VIDIOC_G_FMT32:
- case VIDIOC_S_FMT32:
- case VIDIOC_REQBUFS:
- case VIDIOC_QUERYBUF32:
- case VIDIOC_G_FBUF32:
- case VIDIOC_S_FBUF32:
- case VIDIOC_OVERLAY32:
- case VIDIOC_QBUF32:
- case VIDIOC_DQBUF32:
- case VIDIOC_STREAMON32:
- case VIDIOC_STREAMOFF32:
- case VIDIOC_G_PARM:
- case VIDIOC_S_PARM:
- case VIDIOC_G_STD:
- case VIDIOC_S_STD:
- case VIDIOC_ENUMSTD32:
- case VIDIOC_ENUMINPUT32:
- case VIDIOC_G_CTRL:
- case VIDIOC_S_CTRL:
- case VIDIOC_G_TUNER:
- case VIDIOC_S_TUNER:
- case VIDIOC_G_AUDIO:
- case VIDIOC_S_AUDIO:
- case VIDIOC_QUERYCTRL:
- case VIDIOC_QUERYMENU:
- case VIDIOC_G_INPUT32:
- case VIDIOC_S_INPUT32:
- case VIDIOC_G_OUTPUT32:
- case VIDIOC_S_OUTPUT32:
- case VIDIOC_ENUMOUTPUT:
- case VIDIOC_G_AUDOUT:
- case VIDIOC_S_AUDOUT:
- case VIDIOC_G_MODULATOR:
- case VIDIOC_S_MODULATOR:
- case VIDIOC_S_FREQUENCY:
- case VIDIOC_G_FREQUENCY:
- case VIDIOC_CROPCAP:
- case VIDIOC_G_CROP:
- case VIDIOC_S_CROP:
- case VIDIOC_G_SELECTION:
- case VIDIOC_S_SELECTION:
- case VIDIOC_G_JPEGCOMP:
- case VIDIOC_S_JPEGCOMP:
- case VIDIOC_QUERYSTD:
- case VIDIOC_TRY_FMT32:
- case VIDIOC_ENUMAUDIO:
- case VIDIOC_ENUMAUDOUT:
- case VIDIOC_G_PRIORITY:
- case VIDIOC_S_PRIORITY:
- case VIDIOC_G_SLICED_VBI_CAP:
- case VIDIOC_LOG_STATUS:
- case VIDIOC_G_EXT_CTRLS32:
- case VIDIOC_S_EXT_CTRLS32:
- case VIDIOC_TRY_EXT_CTRLS32:
- case VIDIOC_ENUM_FRAMESIZES:
- case VIDIOC_ENUM_FRAMEINTERVALS:
- case VIDIOC_G_ENC_INDEX:
- case VIDIOC_ENCODER_CMD:
- case VIDIOC_TRY_ENCODER_CMD:
- case VIDIOC_DECODER_CMD:
- case VIDIOC_TRY_DECODER_CMD:
- case VIDIOC_DBG_S_REGISTER:
- case VIDIOC_DBG_G_REGISTER:
- case VIDIOC_DBG_G_CHIP_IDENT:
- case VIDIOC_S_HW_FREQ_SEEK:
- case VIDIOC_ENUM_DV_PRESETS:
- case VIDIOC_S_DV_PRESET:
- case VIDIOC_G_DV_PRESET:
- case VIDIOC_QUERY_DV_PRESET:
- case VIDIOC_S_DV_TIMINGS:
- case VIDIOC_G_DV_TIMINGS:
- case VIDIOC_DQEVENT:
- case VIDIOC_DQEVENT32:
- case VIDIOC_SUBSCRIBE_EVENT:
- case VIDIOC_UNSUBSCRIBE_EVENT:
- case VIDIOC_CREATE_BUFS32:
- case VIDIOC_PREPARE_BUF32:
- ret = do_video_ioctl(file, cmd, arg);
- break;
- default:
- if (vdev->fops->compat_ioctl32)
- ret = vdev->fops->compat_ioctl32(file, cmd, arg);
- if (ret == -ENOIOCTLCMD)
- printk(KERN_WARNING "compat_ioctl32: "
- "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
- _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd),
- cmd);
- break;
- }
- return ret;
- }
- EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32);
|