Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1 | /* |
| 2 | * ioctl32.c: Conversion between 32bit and 64bit native ioctls. |
| 3 | * Separated from fs stuff by Arnd Bergmann <arnd@arndb.de> |
| 4 | * |
| 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 |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 8 | * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 9 | * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 10 | * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl> |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 11 | * |
| 12 | * These routines maintain argument size conversion between 32bit and 64bit |
| 13 | * ioctls. |
| 14 | */ |
| 15 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 16 | #include <linux/compat.h> |
Nickolay V. Shmyrev | 133b735 | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 17 | #include <linux/module.h> |
Laurent Pinchart | b9d0aa6 | 2011-12-18 20:41:19 -0300 | [diff] [blame] | 18 | #include <linux/videodev2.h> |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 19 | #include <linux/v4l2-subdev.h> |
Laurent Pinchart | b9d0aa6 | 2011-12-18 20:41:19 -0300 | [diff] [blame] | 20 | #include <media/v4l2-dev.h> |
Mauro Carvalho Chehab | 2864462 | 2008-07-20 20:26:54 -0300 | [diff] [blame] | 21 | #include <media/v4l2-ioctl.h> |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 22 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 23 | static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 24 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 25 | long ret = -ENOIOCTLCMD; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 26 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 27 | if (file->f_op->unlocked_ioctl) |
| 28 | ret = file->f_op->unlocked_ioctl(file, cmd, arg); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 29 | |
| 30 | return ret; |
| 31 | } |
| 32 | |
| 33 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 34 | struct v4l2_clip32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 35 | struct v4l2_rect c; |
| 36 | compat_caddr_t next; |
| 37 | }; |
| 38 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 39 | struct v4l2_window32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 40 | struct v4l2_rect w; |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 41 | __u32 field; /* enum v4l2_field */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 42 | __u32 chromakey; |
| 43 | compat_caddr_t clips; /* actually struct v4l2_clip32 * */ |
| 44 | __u32 clipcount; |
| 45 | compat_caddr_t bitmap; |
| 46 | }; |
| 47 | |
| 48 | static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 49 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 50 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) || |
| 51 | copy_from_user(&kp->w, &up->w, sizeof(up->w)) || |
| 52 | get_user(kp->field, &up->field) || |
| 53 | get_user(kp->chromakey, &up->chromakey) || |
| 54 | get_user(kp->clipcount, &up->clipcount)) |
| 55 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 56 | if (kp->clipcount > 2048) |
| 57 | return -EINVAL; |
| 58 | if (kp->clipcount) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 59 | struct v4l2_clip32 __user *uclips; |
| 60 | struct v4l2_clip __user *kclips; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 61 | int n = kp->clipcount; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 62 | compat_caddr_t p; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 63 | |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 64 | if (get_user(p, &up->clips)) |
| 65 | return -EFAULT; |
| 66 | uclips = compat_ptr(p); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 67 | kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip)); |
| 68 | kp->clips = kclips; |
| 69 | while (--n >= 0) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 70 | if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c))) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 71 | return -EFAULT; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 72 | if (put_user(n ? kclips + 1 : NULL, &kclips->next)) |
| 73 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 74 | uclips += 1; |
| 75 | kclips += 1; |
| 76 | } |
| 77 | } else |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 78 | kp->clips = NULL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 83 | { |
Roel Kluin | f2e6c6a | 2009-12-16 11:35:45 -0300 | [diff] [blame] | 84 | if (copy_to_user(&up->w, &kp->w, sizeof(kp->w)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 85 | put_user(kp->field, &up->field) || |
| 86 | put_user(kp->chromakey, &up->chromakey) || |
| 87 | put_user(kp->clipcount, &up->clipcount)) |
| 88 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 93 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 94 | if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format))) |
| 95 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 96 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 97 | } |
| 98 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 99 | static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp, |
| 100 | struct v4l2_pix_format_mplane __user *up) |
| 101 | { |
| 102 | if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane))) |
| 103 | return -EFAULT; |
| 104 | return 0; |
| 105 | } |
| 106 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 107 | static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 108 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 109 | if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format))) |
| 110 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 111 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 112 | } |
| 113 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 114 | static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp, |
| 115 | struct v4l2_pix_format_mplane __user *up) |
| 116 | { |
| 117 | if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane))) |
| 118 | return -EFAULT; |
| 119 | return 0; |
| 120 | } |
| 121 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 122 | static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 123 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 124 | if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format))) |
| 125 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 126 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 130 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 131 | if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format))) |
| 132 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 133 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 134 | } |
| 135 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 136 | static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up) |
| 137 | { |
| 138 | if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format))) |
| 139 | return -EFAULT; |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up) |
| 144 | { |
| 145 | if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format))) |
| 146 | return -EFAULT; |
| 147 | return 0; |
| 148 | } |
| 149 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 150 | struct v4l2_format32 { |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 151 | __u32 type; /* enum v4l2_buf_type */ |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 152 | union { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 153 | struct v4l2_pix_format pix; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 154 | struct v4l2_pix_format_mplane pix_mp; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 155 | struct v4l2_window32 win; |
| 156 | struct v4l2_vbi_format vbi; |
| 157 | struct v4l2_sliced_vbi_format sliced; |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 158 | __u8 raw_data[200]; /* user-defined */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 159 | } fmt; |
| 160 | }; |
| 161 | |
Guennadi Liakhovetski | 09362ec | 2011-09-07 18:07:23 -0300 | [diff] [blame] | 162 | /** |
| 163 | * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument |
| 164 | * @index: on return, index of the first created buffer |
| 165 | * @count: entry: number of requested buffers, |
| 166 | * return: number of created buffers |
| 167 | * @memory: buffer memory type |
| 168 | * @format: frame format, for which buffers are requested |
| 169 | * @reserved: future extensions |
| 170 | */ |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 171 | struct v4l2_create_buffers32 { |
Guennadi Liakhovetski | 09362ec | 2011-09-07 18:07:23 -0300 | [diff] [blame] | 172 | __u32 index; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 173 | __u32 count; |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 174 | __u32 memory; /* enum v4l2_memory */ |
Guennadi Liakhovetski | 09362ec | 2011-09-07 18:07:23 -0300 | [diff] [blame] | 175 | struct v4l2_format32 format; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 176 | __u32 reserved[8]; |
| 177 | }; |
| 178 | |
| 179 | static int __get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 180 | { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 181 | switch (kp->type) { |
| 182 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 183 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 184 | return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix); |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 185 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
| 186 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
| 187 | return get_v4l2_pix_format_mplane(&kp->fmt.pix_mp, |
| 188 | &up->fmt.pix_mp); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 189 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 190 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 191 | return get_v4l2_window32(&kp->fmt.win, &up->fmt.win); |
| 192 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 193 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 194 | return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 195 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 196 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 197 | return get_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 198 | default: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 199 | printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n", |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 200 | kp->type); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 201 | return -EINVAL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 205 | static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 206 | { |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 207 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) || |
| 208 | get_user(kp->type, &up->type)) |
| 209 | return -EFAULT; |
| 210 | return __get_v4l2_format32(kp, up); |
| 211 | } |
| 212 | |
| 213 | static int get_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up) |
| 214 | { |
| 215 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) || |
| 216 | copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, format.fmt))) |
| 217 | return -EFAULT; |
| 218 | return __get_v4l2_format32(&kp->format, &up->format); |
| 219 | } |
| 220 | |
| 221 | static int __put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 222 | { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 223 | switch (kp->type) { |
| 224 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 225 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 226 | return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix); |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 227 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
| 228 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
| 229 | return put_v4l2_pix_format_mplane(&kp->fmt.pix_mp, |
| 230 | &up->fmt.pix_mp); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 231 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 232 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 233 | return put_v4l2_window32(&kp->fmt.win, &up->fmt.win); |
| 234 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 235 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 236 | return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 237 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 238 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 239 | return put_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 240 | default: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 241 | printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n", |
| 242 | kp->type); |
| 243 | return -EINVAL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 247 | static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 248 | { |
| 249 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) || |
| 250 | put_user(kp->type, &up->type)) |
| 251 | return -EFAULT; |
| 252 | return __put_v4l2_format32(kp, up); |
| 253 | } |
| 254 | |
| 255 | static int put_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up) |
| 256 | { |
| 257 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) || |
| 258 | copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, format.fmt))) |
| 259 | return -EFAULT; |
| 260 | return __put_v4l2_format32(&kp->format, &up->format); |
| 261 | } |
| 262 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 263 | struct v4l2_standard32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 264 | __u32 index; |
| 265 | __u32 id[2]; /* __u64 would get the alignment wrong */ |
| 266 | __u8 name[24]; |
| 267 | struct v4l2_fract frameperiod; /* Frames, not fields */ |
| 268 | __u32 framelines; |
| 269 | __u32 reserved[4]; |
| 270 | }; |
| 271 | |
| 272 | static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 273 | { |
| 274 | /* other fields are not set by the user, nor used by the driver */ |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 275 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) || |
| 276 | get_user(kp->index, &up->index)) |
| 277 | return -EFAULT; |
| 278 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 282 | { |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 283 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 284 | put_user(kp->index, &up->index) || |
| 285 | copy_to_user(up->id, &kp->id, sizeof(__u64)) || |
| 286 | copy_to_user(up->name, kp->name, 24) || |
| 287 | copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) || |
| 288 | put_user(kp->framelines, &up->framelines) || |
| 289 | copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32))) |
| 290 | return -EFAULT; |
| 291 | return 0; |
| 292 | } |
| 293 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 294 | struct v4l2_plane32 { |
| 295 | __u32 bytesused; |
| 296 | __u32 length; |
| 297 | union { |
| 298 | __u32 mem_offset; |
| 299 | compat_long_t userptr; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 300 | __s32 fd; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 301 | } m; |
| 302 | __u32 data_offset; |
| 303 | __u32 reserved[11]; |
| 304 | }; |
| 305 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 306 | struct v4l2_buffer32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 307 | __u32 index; |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 308 | __u32 type; /* enum v4l2_buf_type */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 309 | __u32 bytesused; |
| 310 | __u32 flags; |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 311 | __u32 field; /* enum v4l2_field */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 312 | struct compat_timeval timestamp; |
| 313 | struct v4l2_timecode timecode; |
| 314 | __u32 sequence; |
| 315 | |
| 316 | /* memory location */ |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 317 | __u32 memory; /* enum v4l2_memory */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 318 | union { |
| 319 | __u32 offset; |
| 320 | compat_long_t userptr; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 321 | compat_caddr_t planes; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 322 | __s32 fd; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 323 | } m; |
| 324 | __u32 length; |
Sakari Ailus | 2b719d7 | 2012-05-02 09:40:03 -0300 | [diff] [blame] | 325 | __u32 reserved2; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 326 | __u32 reserved; |
| 327 | }; |
| 328 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 329 | static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32, |
| 330 | enum v4l2_memory memory) |
| 331 | { |
| 332 | void __user *up_pln; |
| 333 | compat_long_t p; |
| 334 | |
| 335 | if (copy_in_user(up, up32, 2 * sizeof(__u32)) || |
| 336 | copy_in_user(&up->data_offset, &up32->data_offset, |
| 337 | sizeof(__u32))) |
| 338 | return -EFAULT; |
| 339 | |
| 340 | if (memory == V4L2_MEMORY_USERPTR) { |
| 341 | if (get_user(p, &up32->m.userptr)) |
| 342 | return -EFAULT; |
| 343 | up_pln = compat_ptr(p); |
| 344 | if (put_user((unsigned long)up_pln, &up->m.userptr)) |
| 345 | return -EFAULT; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 346 | } else if (memory == V4L2_MEMORY_DMABUF) { |
| 347 | if (copy_in_user(&up->m.fd, &up32->m.fd, sizeof(int))) |
| 348 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 349 | } else { |
| 350 | if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset, |
| 351 | sizeof(__u32))) |
| 352 | return -EFAULT; |
| 353 | } |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32, |
| 359 | enum v4l2_memory memory) |
| 360 | { |
| 361 | if (copy_in_user(up32, up, 2 * sizeof(__u32)) || |
| 362 | copy_in_user(&up32->data_offset, &up->data_offset, |
| 363 | sizeof(__u32))) |
| 364 | return -EFAULT; |
| 365 | |
| 366 | /* For MMAP, driver might've set up the offset, so copy it back. |
| 367 | * USERPTR stays the same (was userspace-provided), so no copying. */ |
| 368 | if (memory == V4L2_MEMORY_MMAP) |
| 369 | if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset, |
| 370 | sizeof(__u32))) |
| 371 | return -EFAULT; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 372 | /* For DMABUF, driver might've set up the fd, so copy it back. */ |
| 373 | if (memory == V4L2_MEMORY_DMABUF) |
| 374 | if (copy_in_user(&up32->m.fd, &up->m.fd, |
| 375 | sizeof(int))) |
| 376 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 381 | static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 382 | { |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 383 | struct v4l2_plane32 __user *uplane32; |
| 384 | struct v4l2_plane __user *uplane; |
| 385 | compat_caddr_t p; |
| 386 | int num_planes; |
| 387 | int ret; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 388 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 389 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) || |
| 390 | get_user(kp->index, &up->index) || |
| 391 | get_user(kp->type, &up->type) || |
| 392 | get_user(kp->flags, &up->flags) || |
Mauro Carvalho Chehab | cc831f8 | 2012-07-05 21:48:58 -0300 | [diff] [blame] | 393 | get_user(kp->memory, &up->memory)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 394 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 395 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 396 | if (V4L2_TYPE_IS_OUTPUT(kp->type)) |
| 397 | if (get_user(kp->bytesused, &up->bytesused) || |
| 398 | get_user(kp->field, &up->field) || |
| 399 | get_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) || |
| 400 | get_user(kp->timestamp.tv_usec, |
| 401 | &up->timestamp.tv_usec)) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 402 | return -EFAULT; |
| 403 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 404 | if (V4L2_TYPE_IS_MULTIPLANAR(kp->type)) { |
| 405 | if (get_user(kp->length, &up->length)) |
| 406 | return -EFAULT; |
| 407 | |
| 408 | num_planes = kp->length; |
| 409 | if (num_planes == 0) { |
| 410 | kp->m.planes = NULL; |
| 411 | /* num_planes == 0 is legal, e.g. when userspace doesn't |
| 412 | * need planes array on DQBUF*/ |
| 413 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 414 | } |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 415 | |
| 416 | if (get_user(p, &up->m.planes)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 417 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 418 | |
| 419 | uplane32 = compat_ptr(p); |
| 420 | if (!access_ok(VERIFY_READ, uplane32, |
| 421 | num_planes * sizeof(struct v4l2_plane32))) |
| 422 | return -EFAULT; |
| 423 | |
| 424 | /* We don't really care if userspace decides to kill itself |
| 425 | * by passing a very big num_planes value */ |
| 426 | uplane = compat_alloc_user_space(num_planes * |
| 427 | sizeof(struct v4l2_plane)); |
| 428 | kp->m.planes = uplane; |
| 429 | |
| 430 | while (--num_planes >= 0) { |
| 431 | ret = get_v4l2_plane32(uplane, uplane32, kp->memory); |
| 432 | if (ret) |
| 433 | return ret; |
| 434 | ++uplane; |
| 435 | ++uplane32; |
| 436 | } |
| 437 | } else { |
| 438 | switch (kp->memory) { |
| 439 | case V4L2_MEMORY_MMAP: |
| 440 | if (get_user(kp->length, &up->length) || |
| 441 | get_user(kp->m.offset, &up->m.offset)) |
| 442 | return -EFAULT; |
| 443 | break; |
| 444 | case V4L2_MEMORY_USERPTR: |
| 445 | { |
| 446 | compat_long_t tmp; |
| 447 | |
| 448 | if (get_user(kp->length, &up->length) || |
| 449 | get_user(tmp, &up->m.userptr)) |
| 450 | return -EFAULT; |
| 451 | |
| 452 | kp->m.userptr = (unsigned long)compat_ptr(tmp); |
| 453 | } |
| 454 | break; |
| 455 | case V4L2_MEMORY_OVERLAY: |
| 456 | if (get_user(kp->m.offset, &up->m.offset)) |
| 457 | return -EFAULT; |
| 458 | break; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 459 | case V4L2_MEMORY_DMABUF: |
| 460 | if (get_user(kp->m.fd, &up->m.fd)) |
| 461 | return -EFAULT; |
| 462 | break; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 463 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 464 | } |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 465 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 470 | { |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 471 | struct v4l2_plane32 __user *uplane32; |
| 472 | struct v4l2_plane __user *uplane; |
| 473 | compat_caddr_t p; |
| 474 | int num_planes; |
| 475 | int ret; |
| 476 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 477 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) || |
| 478 | put_user(kp->index, &up->index) || |
| 479 | put_user(kp->type, &up->type) || |
| 480 | put_user(kp->flags, &up->flags) || |
Mauro Carvalho Chehab | cc831f8 | 2012-07-05 21:48:58 -0300 | [diff] [blame] | 481 | put_user(kp->memory, &up->memory)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 482 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 483 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 484 | if (put_user(kp->bytesused, &up->bytesused) || |
| 485 | put_user(kp->field, &up->field) || |
| 486 | put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) || |
| 487 | put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || |
| 488 | copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || |
| 489 | put_user(kp->sequence, &up->sequence) || |
Sakari Ailus | 2b719d7 | 2012-05-02 09:40:03 -0300 | [diff] [blame] | 490 | put_user(kp->reserved2, &up->reserved2) || |
Mauro Carvalho Chehab | cc831f8 | 2012-07-05 21:48:58 -0300 | [diff] [blame] | 491 | put_user(kp->reserved, &up->reserved)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 492 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 493 | |
| 494 | if (V4L2_TYPE_IS_MULTIPLANAR(kp->type)) { |
| 495 | num_planes = kp->length; |
| 496 | if (num_planes == 0) |
| 497 | return 0; |
| 498 | |
| 499 | uplane = kp->m.planes; |
| 500 | if (get_user(p, &up->m.planes)) |
| 501 | return -EFAULT; |
| 502 | uplane32 = compat_ptr(p); |
| 503 | |
| 504 | while (--num_planes >= 0) { |
| 505 | ret = put_v4l2_plane32(uplane, uplane32, kp->memory); |
| 506 | if (ret) |
| 507 | return ret; |
| 508 | ++uplane; |
| 509 | ++uplane32; |
| 510 | } |
| 511 | } else { |
| 512 | switch (kp->memory) { |
| 513 | case V4L2_MEMORY_MMAP: |
| 514 | if (put_user(kp->length, &up->length) || |
| 515 | put_user(kp->m.offset, &up->m.offset)) |
| 516 | return -EFAULT; |
| 517 | break; |
| 518 | case V4L2_MEMORY_USERPTR: |
| 519 | if (put_user(kp->length, &up->length) || |
| 520 | put_user(kp->m.userptr, &up->m.userptr)) |
| 521 | return -EFAULT; |
| 522 | break; |
| 523 | case V4L2_MEMORY_OVERLAY: |
| 524 | if (put_user(kp->m.offset, &up->m.offset)) |
| 525 | return -EFAULT; |
| 526 | break; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 527 | case V4L2_MEMORY_DMABUF: |
| 528 | if (put_user(kp->m.fd, &up->m.fd)) |
| 529 | return -EFAULT; |
| 530 | break; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 534 | return 0; |
| 535 | } |
| 536 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 537 | struct v4l2_framebuffer32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 538 | __u32 capability; |
| 539 | __u32 flags; |
| 540 | compat_caddr_t base; |
| 541 | struct v4l2_pix_format fmt; |
| 542 | }; |
| 543 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 544 | static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 545 | { |
| 546 | u32 tmp; |
| 547 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 548 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) || |
| 549 | get_user(tmp, &up->base) || |
| 550 | get_user(kp->capability, &up->capability) || |
| 551 | get_user(kp->flags, &up->flags)) |
| 552 | return -EFAULT; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 553 | kp->base = compat_ptr(tmp); |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 554 | get_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 555 | return 0; |
| 556 | } |
| 557 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 558 | static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 559 | { |
| 560 | u32 tmp = (u32)((unsigned long)kp->base); |
| 561 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 562 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 563 | put_user(tmp, &up->base) || |
| 564 | put_user(kp->capability, &up->capability) || |
| 565 | put_user(kp->flags, &up->flags)) |
| 566 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 567 | put_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 568 | return 0; |
| 569 | } |
| 570 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 571 | struct v4l2_input32 { |
| 572 | __u32 index; /* Which input */ |
| 573 | __u8 name[32]; /* Label */ |
| 574 | __u32 type; /* Type of input */ |
| 575 | __u32 audioset; /* Associated audios (bitfield) */ |
| 576 | __u32 tuner; /* Associated tuner */ |
| 577 | v4l2_std_id std; |
| 578 | __u32 status; |
| 579 | __u32 reserved[4]; |
| 580 | } __attribute__ ((packed)); |
| 581 | |
| 582 | /* The 64-bit v4l2_input struct has extra padding at the end of the struct. |
| 583 | Otherwise it is identical to the 32-bit version. */ |
| 584 | static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 585 | { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 586 | if (copy_from_user(kp, up, sizeof(struct v4l2_input32))) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 587 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 591 | static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 592 | { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 593 | if (copy_to_user(up, kp, sizeof(struct v4l2_input32))) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 594 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 598 | struct v4l2_ext_controls32 { |
| 599 | __u32 ctrl_class; |
| 600 | __u32 count; |
| 601 | __u32 error_idx; |
| 602 | __u32 reserved[2]; |
| 603 | compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */ |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 604 | }; |
| 605 | |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 606 | struct v4l2_ext_control32 { |
| 607 | __u32 id; |
| 608 | __u32 size; |
| 609 | __u32 reserved2[1]; |
| 610 | union { |
| 611 | __s32 value; |
| 612 | __s64 value64; |
| 613 | compat_caddr_t string; /* actually char * */ |
| 614 | }; |
| 615 | } __attribute__ ((packed)); |
| 616 | |
| 617 | /* The following function really belong in v4l2-common, but that causes |
| 618 | a circular dependency between modules. We need to think about this, but |
| 619 | for now this will do. */ |
| 620 | |
| 621 | /* Return non-zero if this control is a pointer type. Currently only |
Eduardo Valentin | fdf82dc | 2009-08-11 18:49:12 -0300 | [diff] [blame] | 622 | type STRING is a pointer type. */ |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 623 | static inline int ctrl_is_pointer(u32 id) |
| 624 | { |
Eduardo Valentin | fdf82dc | 2009-08-11 18:49:12 -0300 | [diff] [blame] | 625 | switch (id) { |
| 626 | case V4L2_CID_RDS_TX_PS_NAME: |
| 627 | case V4L2_CID_RDS_TX_RADIO_TEXT: |
| 628 | return 1; |
| 629 | default: |
| 630 | return 0; |
| 631 | } |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 632 | } |
| 633 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 634 | static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up) |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 635 | { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 636 | struct v4l2_ext_control32 __user *ucontrols; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 637 | struct v4l2_ext_control __user *kcontrols; |
| 638 | int n; |
| 639 | compat_caddr_t p; |
| 640 | |
| 641 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) || |
| 642 | get_user(kp->ctrl_class, &up->ctrl_class) || |
| 643 | get_user(kp->count, &up->count) || |
| 644 | get_user(kp->error_idx, &up->error_idx) || |
| 645 | copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved))) |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 646 | return -EFAULT; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 647 | n = kp->count; |
| 648 | if (n == 0) { |
| 649 | kp->controls = NULL; |
| 650 | return 0; |
| 651 | } |
| 652 | if (get_user(p, &up->controls)) |
| 653 | return -EFAULT; |
| 654 | ucontrols = compat_ptr(p); |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 655 | if (!access_ok(VERIFY_READ, ucontrols, |
| 656 | n * sizeof(struct v4l2_ext_control32))) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 657 | return -EFAULT; |
| 658 | kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control)); |
| 659 | kp->controls = kcontrols; |
| 660 | while (--n >= 0) { |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 661 | if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols))) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 662 | return -EFAULT; |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 663 | if (ctrl_is_pointer(kcontrols->id)) { |
| 664 | void __user *s; |
| 665 | |
| 666 | if (get_user(p, &ucontrols->string)) |
| 667 | return -EFAULT; |
| 668 | s = compat_ptr(p); |
| 669 | if (put_user(s, &kcontrols->string)) |
| 670 | return -EFAULT; |
| 671 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 672 | ucontrols++; |
| 673 | kcontrols++; |
| 674 | } |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 675 | return 0; |
| 676 | } |
| 677 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 678 | static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 679 | { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 680 | struct v4l2_ext_control32 __user *ucontrols; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 681 | struct v4l2_ext_control __user *kcontrols = kp->controls; |
| 682 | int n = kp->count; |
| 683 | compat_caddr_t p; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 684 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 685 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) || |
| 686 | put_user(kp->ctrl_class, &up->ctrl_class) || |
| 687 | put_user(kp->count, &up->count) || |
| 688 | put_user(kp->error_idx, &up->error_idx) || |
| 689 | copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved))) |
| 690 | return -EFAULT; |
| 691 | if (!kp->count) |
| 692 | return 0; |
| 693 | |
| 694 | if (get_user(p, &up->controls)) |
| 695 | return -EFAULT; |
| 696 | ucontrols = compat_ptr(p); |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 697 | if (!access_ok(VERIFY_WRITE, ucontrols, |
| 698 | n * sizeof(struct v4l2_ext_control32))) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 699 | return -EFAULT; |
| 700 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 701 | while (--n >= 0) { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 702 | unsigned size = sizeof(*ucontrols); |
| 703 | |
| 704 | /* Do not modify the pointer when copying a pointer control. |
| 705 | The contents of the pointer was changed, not the pointer |
| 706 | itself. */ |
| 707 | if (ctrl_is_pointer(kcontrols->id)) |
| 708 | size -= sizeof(ucontrols->value64); |
| 709 | if (copy_in_user(ucontrols, kcontrols, size)) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 710 | return -EFAULT; |
| 711 | ucontrols++; |
| 712 | kcontrols++; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 713 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 714 | return 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 715 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 716 | |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 717 | struct v4l2_event32 { |
| 718 | __u32 type; |
| 719 | union { |
| 720 | __u8 data[64]; |
| 721 | } u; |
| 722 | __u32 pending; |
| 723 | __u32 sequence; |
| 724 | struct compat_timespec timestamp; |
| 725 | __u32 id; |
| 726 | __u32 reserved[8]; |
| 727 | }; |
| 728 | |
| 729 | static int put_v4l2_event32(struct v4l2_event *kp, struct v4l2_event32 __user *up) |
| 730 | { |
| 731 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_event32)) || |
| 732 | put_user(kp->type, &up->type) || |
| 733 | copy_to_user(&up->u, &kp->u, sizeof(kp->u)) || |
| 734 | put_user(kp->pending, &up->pending) || |
| 735 | put_user(kp->sequence, &up->sequence) || |
| 736 | put_compat_timespec(&kp->timestamp, &up->timestamp) || |
| 737 | put_user(kp->id, &up->id) || |
| 738 | copy_to_user(up->reserved, kp->reserved, 8 * sizeof(__u32))) |
| 739 | return -EFAULT; |
| 740 | return 0; |
| 741 | } |
| 742 | |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 743 | struct v4l2_subdev_edid32 { |
| 744 | __u32 pad; |
| 745 | __u32 start_block; |
| 746 | __u32 blocks; |
| 747 | __u32 reserved[5]; |
| 748 | compat_caddr_t edid; |
| 749 | }; |
| 750 | |
| 751 | static int get_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subdev_edid32 __user *up) |
| 752 | { |
| 753 | u32 tmp; |
| 754 | |
| 755 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_subdev_edid32)) || |
| 756 | get_user(kp->pad, &up->pad) || |
| 757 | get_user(kp->start_block, &up->start_block) || |
| 758 | get_user(kp->blocks, &up->blocks) || |
| 759 | get_user(tmp, &up->edid) || |
| 760 | copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved))) |
| 761 | return -EFAULT; |
| 762 | kp->edid = compat_ptr(tmp); |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subdev_edid32 __user *up) |
| 767 | { |
| 768 | u32 tmp = (u32)((unsigned long)kp->edid); |
| 769 | |
| 770 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_subdev_edid32)) || |
| 771 | put_user(kp->pad, &up->pad) || |
| 772 | put_user(kp->start_block, &up->start_block) || |
| 773 | put_user(kp->blocks, &up->blocks) || |
| 774 | put_user(tmp, &up->edid) || |
| 775 | copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved))) |
| 776 | return -EFAULT; |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 781 | #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32) |
| 782 | #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32) |
| 783 | #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32) |
| 784 | #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32) |
| 785 | #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32) |
| 786 | #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32) |
| 787 | #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32) |
| 788 | #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32) |
| 789 | #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32) |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 790 | #define VIDIOC_SUBDEV_G_EDID32 _IOWR('V', 63, struct v4l2_subdev_edid32) |
| 791 | #define VIDIOC_SUBDEV_S_EDID32 _IOWR('V', 64, struct v4l2_subdev_edid32) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 792 | #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32) |
| 793 | #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32) |
| 794 | #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32) |
| 795 | #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32) |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 796 | #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 797 | #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32) |
| 798 | #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 799 | |
| 800 | #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 801 | #define VIDIOC_STREAMON32 _IOW ('V', 18, s32) |
| 802 | #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32) |
| 803 | #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32) |
| 804 | #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32) |
| 805 | #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32) |
| 806 | #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 807 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 808 | static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 809 | { |
| 810 | union { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 811 | struct v4l2_format v2f; |
| 812 | struct v4l2_buffer v2b; |
| 813 | struct v4l2_framebuffer v2fb; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 814 | struct v4l2_input v2i; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 815 | struct v4l2_standard v2s; |
| 816 | struct v4l2_ext_controls v2ecs; |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 817 | struct v4l2_event v2ev; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 818 | struct v4l2_create_buffers v2crt; |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 819 | struct v4l2_subdev_edid v2edid; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 820 | unsigned long vx; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 821 | int vi; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 822 | } karg; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 823 | void __user *up = compat_ptr(arg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 824 | int compatible_arg = 1; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 825 | long err = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 826 | |
| 827 | /* First, convert the command. */ |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 828 | switch (cmd) { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 829 | case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; |
| 830 | case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; |
| 831 | case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; |
| 832 | case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break; |
| 833 | case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break; |
| 834 | case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break; |
| 835 | case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break; |
| 836 | case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break; |
| 837 | case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break; |
| 838 | case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break; |
| 839 | case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break; |
| 840 | case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break; |
| 841 | case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break; |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 842 | case VIDIOC_DQEVENT32: cmd = VIDIOC_DQEVENT; break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 843 | case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 844 | case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break; |
| 845 | case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break; |
| 846 | case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break; |
| 847 | case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; |
| 848 | case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break; |
| 849 | case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 850 | case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break; |
| 851 | case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break; |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 852 | case VIDIOC_SUBDEV_G_EDID32: cmd = VIDIOC_SUBDEV_G_EDID; break; |
| 853 | case VIDIOC_SUBDEV_S_EDID32: cmd = VIDIOC_SUBDEV_S_EDID; break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 854 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 855 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 856 | switch (cmd) { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 857 | case VIDIOC_OVERLAY: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 858 | case VIDIOC_STREAMON: |
| 859 | case VIDIOC_STREAMOFF: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 860 | case VIDIOC_S_INPUT: |
| 861 | case VIDIOC_S_OUTPUT: |
| 862 | err = get_user(karg.vi, (s32 __user *)up); |
| 863 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 864 | break; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 865 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 866 | case VIDIOC_G_INPUT: |
| 867 | case VIDIOC_G_OUTPUT: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 868 | compatible_arg = 0; |
| 869 | break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 870 | |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 871 | case VIDIOC_SUBDEV_G_EDID: |
| 872 | case VIDIOC_SUBDEV_S_EDID: |
| 873 | err = get_v4l2_subdev_edid32(&karg.v2edid, up); |
| 874 | compatible_arg = 0; |
| 875 | break; |
| 876 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 877 | case VIDIOC_G_FMT: |
| 878 | case VIDIOC_S_FMT: |
| 879 | case VIDIOC_TRY_FMT: |
| 880 | err = get_v4l2_format32(&karg.v2f, up); |
| 881 | compatible_arg = 0; |
| 882 | break; |
| 883 | |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 884 | case VIDIOC_CREATE_BUFS: |
| 885 | err = get_v4l2_create32(&karg.v2crt, up); |
| 886 | compatible_arg = 0; |
| 887 | break; |
| 888 | |
| 889 | case VIDIOC_PREPARE_BUF: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 890 | case VIDIOC_QUERYBUF: |
| 891 | case VIDIOC_QBUF: |
| 892 | case VIDIOC_DQBUF: |
| 893 | err = get_v4l2_buffer32(&karg.v2b, up); |
| 894 | compatible_arg = 0; |
| 895 | break; |
| 896 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 897 | case VIDIOC_S_FBUF: |
| 898 | err = get_v4l2_framebuffer32(&karg.v2fb, up); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 899 | compatible_arg = 0; |
| 900 | break; |
| 901 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 902 | case VIDIOC_G_FBUF: |
| 903 | compatible_arg = 0; |
| 904 | break; |
| 905 | |
| 906 | case VIDIOC_ENUMSTD: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 907 | err = get_v4l2_standard32(&karg.v2s, up); |
| 908 | compatible_arg = 0; |
| 909 | break; |
| 910 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 911 | case VIDIOC_ENUMINPUT: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 912 | err = get_v4l2_input32(&karg.v2i, up); |
| 913 | compatible_arg = 0; |
| 914 | break; |
| 915 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 916 | case VIDIOC_G_EXT_CTRLS: |
| 917 | case VIDIOC_S_EXT_CTRLS: |
| 918 | case VIDIOC_TRY_EXT_CTRLS: |
| 919 | err = get_v4l2_ext_controls32(&karg.v2ecs, up); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 920 | compatible_arg = 0; |
| 921 | break; |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 922 | case VIDIOC_DQEVENT: |
| 923 | compatible_arg = 0; |
| 924 | break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 925 | } |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 926 | if (err) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 927 | return err; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 928 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 929 | if (compatible_arg) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 930 | err = native_ioctl(file, cmd, (unsigned long)up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 931 | else { |
| 932 | mm_segment_t old_fs = get_fs(); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 933 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 934 | set_fs(KERNEL_DS); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 935 | err = native_ioctl(file, cmd, (unsigned long)&karg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 936 | set_fs(old_fs); |
| 937 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 938 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 939 | /* Special case: even after an error we need to put the |
| 940 | results back for these ioctls since the error_idx will |
| 941 | contain information on which control failed. */ |
| 942 | switch (cmd) { |
| 943 | case VIDIOC_G_EXT_CTRLS: |
| 944 | case VIDIOC_S_EXT_CTRLS: |
| 945 | case VIDIOC_TRY_EXT_CTRLS: |
| 946 | if (put_v4l2_ext_controls32(&karg.v2ecs, up)) |
| 947 | err = -EFAULT; |
| 948 | break; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 949 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 950 | if (err) |
| 951 | return err; |
| 952 | |
| 953 | switch (cmd) { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 954 | case VIDIOC_S_INPUT: |
| 955 | case VIDIOC_S_OUTPUT: |
| 956 | case VIDIOC_G_INPUT: |
| 957 | case VIDIOC_G_OUTPUT: |
| 958 | err = put_user(((s32)karg.vi), (s32 __user *)up); |
| 959 | break; |
| 960 | |
| 961 | case VIDIOC_G_FBUF: |
| 962 | err = put_v4l2_framebuffer32(&karg.v2fb, up); |
| 963 | break; |
| 964 | |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 965 | case VIDIOC_DQEVENT: |
| 966 | err = put_v4l2_event32(&karg.v2ev, up); |
| 967 | break; |
| 968 | |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 969 | case VIDIOC_SUBDEV_G_EDID: |
| 970 | case VIDIOC_SUBDEV_S_EDID: |
| 971 | err = put_v4l2_subdev_edid32(&karg.v2edid, up); |
| 972 | break; |
| 973 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 974 | case VIDIOC_G_FMT: |
| 975 | case VIDIOC_S_FMT: |
| 976 | case VIDIOC_TRY_FMT: |
| 977 | err = put_v4l2_format32(&karg.v2f, up); |
| 978 | break; |
| 979 | |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 980 | case VIDIOC_CREATE_BUFS: |
| 981 | err = put_v4l2_create32(&karg.v2crt, up); |
| 982 | break; |
| 983 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 984 | case VIDIOC_QUERYBUF: |
| 985 | case VIDIOC_QBUF: |
| 986 | case VIDIOC_DQBUF: |
| 987 | err = put_v4l2_buffer32(&karg.v2b, up); |
| 988 | break; |
| 989 | |
| 990 | case VIDIOC_ENUMSTD: |
| 991 | err = put_v4l2_standard32(&karg.v2s, up); |
| 992 | break; |
| 993 | |
| 994 | case VIDIOC_ENUMINPUT: |
| 995 | err = put_v4l2_input32(&karg.v2i, up); |
| 996 | break; |
| 997 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 998 | return err; |
| 999 | } |
| 1000 | |
Hans Verkuil | 9bb7cde | 2008-12-30 06:42:40 -0300 | [diff] [blame] | 1001 | long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1002 | { |
Laurent Pinchart | b9d0aa6 | 2011-12-18 20:41:19 -0300 | [diff] [blame] | 1003 | struct video_device *vdev = video_devdata(file); |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1004 | long ret = -ENOIOCTLCMD; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1005 | |
Frederic Weisbecker | c6d7ba8 | 2010-08-13 22:29:03 +0200 | [diff] [blame] | 1006 | if (!file->f_op->unlocked_ioctl) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1007 | return ret; |
| 1008 | |
| 1009 | switch (cmd) { |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1010 | case VIDIOC_QUERYCAP: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1011 | case VIDIOC_RESERVED: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1012 | case VIDIOC_ENUM_FMT: |
| 1013 | case VIDIOC_G_FMT32: |
| 1014 | case VIDIOC_S_FMT32: |
| 1015 | case VIDIOC_REQBUFS: |
| 1016 | case VIDIOC_QUERYBUF32: |
| 1017 | case VIDIOC_G_FBUF32: |
| 1018 | case VIDIOC_S_FBUF32: |
| 1019 | case VIDIOC_OVERLAY32: |
| 1020 | case VIDIOC_QBUF32: |
Tomasz Stanislawski | b799d09 | 2012-06-14 11:32:23 -0300 | [diff] [blame] | 1021 | case VIDIOC_EXPBUF: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1022 | case VIDIOC_DQBUF32: |
| 1023 | case VIDIOC_STREAMON32: |
| 1024 | case VIDIOC_STREAMOFF32: |
| 1025 | case VIDIOC_G_PARM: |
Gregor Jasny | c7f09db | 2008-10-23 09:55:22 -0300 | [diff] [blame] | 1026 | case VIDIOC_S_PARM: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1027 | case VIDIOC_G_STD: |
| 1028 | case VIDIOC_S_STD: |
| 1029 | case VIDIOC_ENUMSTD32: |
| 1030 | case VIDIOC_ENUMINPUT32: |
| 1031 | case VIDIOC_G_CTRL: |
Steven Walter | 7963fa4 | 2007-08-09 11:36:35 -0300 | [diff] [blame] | 1032 | case VIDIOC_S_CTRL: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1033 | case VIDIOC_G_TUNER: |
| 1034 | case VIDIOC_S_TUNER: |
| 1035 | case VIDIOC_G_AUDIO: |
| 1036 | case VIDIOC_S_AUDIO: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1037 | case VIDIOC_QUERYCTRL: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1038 | case VIDIOC_QUERYMENU: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1039 | case VIDIOC_G_INPUT32: |
| 1040 | case VIDIOC_S_INPUT32: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1041 | case VIDIOC_G_OUTPUT32: |
| 1042 | case VIDIOC_S_OUTPUT32: |
| 1043 | case VIDIOC_ENUMOUTPUT: |
| 1044 | case VIDIOC_G_AUDOUT: |
| 1045 | case VIDIOC_S_AUDOUT: |
| 1046 | case VIDIOC_G_MODULATOR: |
| 1047 | case VIDIOC_S_MODULATOR: |
| 1048 | case VIDIOC_S_FREQUENCY: |
| 1049 | case VIDIOC_G_FREQUENCY: |
| 1050 | case VIDIOC_CROPCAP: |
| 1051 | case VIDIOC_G_CROP: |
| 1052 | case VIDIOC_S_CROP: |
Tomasz Stanislawski | 0e8caac | 2011-08-10 10:37:47 -0300 | [diff] [blame] | 1053 | case VIDIOC_G_SELECTION: |
| 1054 | case VIDIOC_S_SELECTION: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1055 | case VIDIOC_G_JPEGCOMP: |
| 1056 | case VIDIOC_S_JPEGCOMP: |
| 1057 | case VIDIOC_QUERYSTD: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1058 | case VIDIOC_TRY_FMT32: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1059 | case VIDIOC_ENUMAUDIO: |
| 1060 | case VIDIOC_ENUMAUDOUT: |
| 1061 | case VIDIOC_G_PRIORITY: |
| 1062 | case VIDIOC_S_PRIORITY: |
| 1063 | case VIDIOC_G_SLICED_VBI_CAP: |
| 1064 | case VIDIOC_LOG_STATUS: |
| 1065 | case VIDIOC_G_EXT_CTRLS32: |
| 1066 | case VIDIOC_S_EXT_CTRLS32: |
| 1067 | case VIDIOC_TRY_EXT_CTRLS32: |
Gregor Jasny | c7f09db | 2008-10-23 09:55:22 -0300 | [diff] [blame] | 1068 | case VIDIOC_ENUM_FRAMESIZES: |
| 1069 | case VIDIOC_ENUM_FRAMEINTERVALS: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1070 | case VIDIOC_G_ENC_INDEX: |
| 1071 | case VIDIOC_ENCODER_CMD: |
| 1072 | case VIDIOC_TRY_ENCODER_CMD: |
Hans Verkuil | a45c0ad | 2011-11-24 09:53:43 -0300 | [diff] [blame] | 1073 | case VIDIOC_DECODER_CMD: |
| 1074 | case VIDIOC_TRY_DECODER_CMD: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1075 | case VIDIOC_DBG_S_REGISTER: |
| 1076 | case VIDIOC_DBG_G_REGISTER: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1077 | case VIDIOC_S_HW_FREQ_SEEK: |
Muralidharan Karicheri | b6456c0 | 2009-11-19 12:00:31 -0300 | [diff] [blame] | 1078 | case VIDIOC_S_DV_TIMINGS: |
| 1079 | case VIDIOC_G_DV_TIMINGS: |
Sakari Ailus | fda1021 | 2010-02-24 19:19:05 -0300 | [diff] [blame] | 1080 | case VIDIOC_DQEVENT: |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 1081 | case VIDIOC_DQEVENT32: |
Sakari Ailus | fda1021 | 2010-02-24 19:19:05 -0300 | [diff] [blame] | 1082 | case VIDIOC_SUBSCRIBE_EVENT: |
| 1083 | case VIDIOC_UNSUBSCRIBE_EVENT: |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 1084 | case VIDIOC_CREATE_BUFS32: |
| 1085 | case VIDIOC_PREPARE_BUF32: |
Hans Verkuil | 5d7758e | 2012-05-15 08:06:44 -0300 | [diff] [blame] | 1086 | case VIDIOC_ENUM_DV_TIMINGS: |
| 1087 | case VIDIOC_QUERY_DV_TIMINGS: |
| 1088 | case VIDIOC_DV_TIMINGS_CAP: |
Hans Verkuil | 82b655b | 2012-07-05 06:37:08 -0300 | [diff] [blame] | 1089 | case VIDIOC_ENUM_FREQ_BANDS: |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 1090 | case VIDIOC_SUBDEV_G_EDID32: |
| 1091 | case VIDIOC_SUBDEV_S_EDID32: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1092 | ret = do_video_ioctl(file, cmd, arg); |
| 1093 | break; |
| 1094 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 1095 | default: |
Laurent Pinchart | b9d0aa6 | 2011-12-18 20:41:19 -0300 | [diff] [blame] | 1096 | if (vdev->fops->compat_ioctl32) |
| 1097 | ret = vdev->fops->compat_ioctl32(file, cmd, arg); |
| 1098 | |
| 1099 | if (ret == -ENOIOCTLCMD) |
| 1100 | printk(KERN_WARNING "compat_ioctl32: " |
| 1101 | "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n", |
| 1102 | _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), |
| 1103 | cmd); |
Hans Verkuil | 7d4f0b8 | 2008-12-15 07:19:20 -0300 | [diff] [blame] | 1104 | break; |
MishalĂ… Pytasz | 97e2a01 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1105 | } |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1106 | return ret; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1107 | } |
Hans Verkuil | 9bb7cde | 2008-12-30 06:42:40 -0300 | [diff] [blame] | 1108 | EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32); |