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> |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 21 | #include <media/v4l2-fh.h> |
| 22 | #include <media/v4l2-ctrls.h> |
Mauro Carvalho Chehab | 2864462 | 2008-07-20 20:26:54 -0300 | [diff] [blame] | 23 | #include <media/v4l2-ioctl.h> |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 24 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 25 | /* Use the same argument order as copy_in_user */ |
| 26 | #define assign_in_user(to, from) \ |
| 27 | ({ \ |
| 28 | typeof(*from) __assign_tmp; \ |
| 29 | \ |
| 30 | get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \ |
| 31 | }) |
| 32 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 33 | 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] | 34 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 35 | long ret = -ENOIOCTLCMD; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 36 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 37 | if (file->f_op->unlocked_ioctl) |
| 38 | ret = file->f_op->unlocked_ioctl(file, cmd, arg); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 39 | |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 44 | struct v4l2_clip32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 45 | struct v4l2_rect c; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 46 | compat_caddr_t next; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 47 | }; |
| 48 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 49 | struct v4l2_window32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 50 | struct v4l2_rect w; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 51 | __u32 field; /* enum v4l2_field */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 52 | __u32 chromakey; |
| 53 | compat_caddr_t clips; /* actually struct v4l2_clip32 * */ |
| 54 | __u32 clipcount; |
| 55 | compat_caddr_t bitmap; |
Daniel Mentz | 55e3f3e | 2018-02-14 12:48:26 +0100 | [diff] [blame] | 56 | __u8 global_alpha; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 57 | }; |
| 58 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 59 | static int get_v4l2_window32(struct v4l2_window __user *kp, |
| 60 | struct v4l2_window32 __user *up, |
| 61 | void __user *aux_buf, u32 aux_space) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 62 | { |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 63 | struct v4l2_clip32 __user *uclips; |
| 64 | struct v4l2_clip __user *kclips; |
| 65 | compat_caddr_t p; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 66 | u32 clipcount; |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 67 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 68 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 69 | copy_in_user(&kp->w, &up->w, sizeof(up->w)) || |
| 70 | assign_in_user(&kp->field, &up->field) || |
| 71 | assign_in_user(&kp->chromakey, &up->chromakey) || |
| 72 | assign_in_user(&kp->global_alpha, &up->global_alpha) || |
| 73 | get_user(clipcount, &up->clipcount) || |
| 74 | put_user(clipcount, &kp->clipcount)) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 75 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 76 | if (clipcount > 2048) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 77 | return -EINVAL; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 78 | if (!clipcount) |
| 79 | return put_user(NULL, &kp->clips); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 80 | |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 81 | if (get_user(p, &up->clips)) |
| 82 | return -EFAULT; |
| 83 | uclips = compat_ptr(p); |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 84 | if (aux_space < clipcount * sizeof(*kclips)) |
| 85 | return -EFAULT; |
| 86 | kclips = aux_buf; |
| 87 | if (put_user(kclips, &kp->clips)) |
| 88 | return -EFAULT; |
| 89 | |
| 90 | while (clipcount--) { |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 91 | if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c))) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 92 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 93 | if (put_user(clipcount ? kclips + 1 : NULL, &kclips->next)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 94 | return -EFAULT; |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 95 | uclips++; |
| 96 | kclips++; |
| 97 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 101 | static int put_v4l2_window32(struct v4l2_window __user *kp, |
| 102 | struct v4l2_window32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 103 | { |
Mauro Carvalho Chehab | 394a9a7 | 2018-03-28 13:59:22 -0400 | [diff] [blame] | 104 | struct v4l2_clip __user *kclips; |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 105 | struct v4l2_clip32 __user *uclips; |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 106 | compat_caddr_t p; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 107 | u32 clipcount; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 108 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 109 | if (copy_in_user(&up->w, &kp->w, sizeof(kp->w)) || |
| 110 | assign_in_user(&up->field, &kp->field) || |
| 111 | assign_in_user(&up->chromakey, &kp->chromakey) || |
| 112 | assign_in_user(&up->global_alpha, &kp->global_alpha) || |
| 113 | get_user(clipcount, &kp->clipcount) || |
| 114 | put_user(clipcount, &up->clipcount)) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 115 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 116 | if (!clipcount) |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 117 | return 0; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 118 | |
Mauro Carvalho Chehab | 394a9a7 | 2018-03-28 13:59:22 -0400 | [diff] [blame] | 119 | if (get_user(kclips, &kp->clips)) |
| 120 | return -EFAULT; |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 121 | if (get_user(p, &up->clips)) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 122 | return -EFAULT; |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 123 | uclips = compat_ptr(p); |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 124 | while (clipcount--) { |
Hans Verkuil | 30ac343c | 2018-02-14 12:48:27 +0100 | [diff] [blame] | 125 | if (copy_in_user(&uclips->c, &kclips->c, sizeof(uclips->c))) |
| 126 | return -EFAULT; |
| 127 | uclips++; |
| 128 | kclips++; |
| 129 | } |
Hans Verkuil | d5beb67 | 2015-09-17 06:46:04 -0300 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 133 | struct v4l2_format32 { |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 134 | __u32 type; /* enum v4l2_buf_type */ |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 135 | union { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 136 | struct v4l2_pix_format pix; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 137 | struct v4l2_pix_format_mplane pix_mp; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 138 | struct v4l2_window32 win; |
| 139 | struct v4l2_vbi_format vbi; |
| 140 | struct v4l2_sliced_vbi_format sliced; |
Hans Verkuil | d5beb67 | 2015-09-17 06:46:04 -0300 | [diff] [blame] | 141 | struct v4l2_sdr_format sdr; |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 142 | __u8 raw_data[200]; /* user-defined */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 143 | } fmt; |
| 144 | }; |
| 145 | |
Guennadi Liakhovetski | 09362ec | 2011-09-07 18:07:23 -0300 | [diff] [blame] | 146 | /** |
| 147 | * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument |
| 148 | * @index: on return, index of the first created buffer |
| 149 | * @count: entry: number of requested buffers, |
| 150 | * return: number of created buffers |
| 151 | * @memory: buffer memory type |
| 152 | * @format: frame format, for which buffers are requested |
| 153 | * @reserved: future extensions |
| 154 | */ |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 155 | struct v4l2_create_buffers32 { |
Guennadi Liakhovetski | 09362ec | 2011-09-07 18:07:23 -0300 | [diff] [blame] | 156 | __u32 index; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 157 | __u32 count; |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 158 | __u32 memory; /* enum v4l2_memory */ |
Guennadi Liakhovetski | 09362ec | 2011-09-07 18:07:23 -0300 | [diff] [blame] | 159 | struct v4l2_format32 format; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 160 | __u32 reserved[8]; |
| 161 | }; |
| 162 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 163 | static int __bufsize_v4l2_format(struct v4l2_format32 __user *up, u32 *size) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 164 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 165 | u32 type; |
| 166 | |
| 167 | if (get_user(type, &up->type)) |
Guennadi Liakhovetski | ec77581 | 2014-04-26 12:51:31 -0300 | [diff] [blame] | 168 | return -EFAULT; |
| 169 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 170 | switch (type) { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 171 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 172 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: { |
| 173 | u32 clipcount; |
| 174 | |
| 175 | if (get_user(clipcount, &up->fmt.win.clipcount)) |
| 176 | return -EFAULT; |
| 177 | if (clipcount > 2048) |
| 178 | return -EINVAL; |
| 179 | *size = clipcount * sizeof(struct v4l2_clip); |
| 180 | return 0; |
| 181 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 182 | default: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 183 | *size = 0; |
| 184 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 188 | static int bufsize_v4l2_format(struct v4l2_format32 __user *up, u32 *size) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 189 | { |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 190 | if (!access_ok(VERIFY_READ, up, sizeof(*up))) |
Guennadi Liakhovetski | ec77581 | 2014-04-26 12:51:31 -0300 | [diff] [blame] | 191 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 192 | return __bufsize_v4l2_format(up, size); |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 193 | } |
| 194 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 195 | static int __get_v4l2_format32(struct v4l2_format __user *kp, |
| 196 | struct v4l2_format32 __user *up, |
| 197 | void __user *aux_buf, u32 aux_space) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 198 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 199 | u32 type; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 200 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 201 | if (get_user(type, &up->type) || put_user(type, &kp->type)) |
Guennadi Liakhovetski | 6ed9b28 | 2014-05-30 20:26:38 -0300 | [diff] [blame] | 202 | return -EFAULT; |
| 203 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 204 | switch (type) { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 205 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 206 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 207 | return copy_in_user(&kp->fmt.pix, &up->fmt.pix, |
Hans Verkuil | 81e0acf | 2018-02-14 12:48:21 +0100 | [diff] [blame] | 208 | sizeof(kp->fmt.pix)) ? -EFAULT : 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 209 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
| 210 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 211 | return copy_in_user(&kp->fmt.pix_mp, &up->fmt.pix_mp, |
Hans Verkuil | 81e0acf | 2018-02-14 12:48:21 +0100 | [diff] [blame] | 212 | sizeof(kp->fmt.pix_mp)) ? -EFAULT : 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 213 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 214 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 215 | return get_v4l2_window32(&kp->fmt.win, &up->fmt.win, |
| 216 | aux_buf, aux_space); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 217 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 218 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 219 | return copy_in_user(&kp->fmt.vbi, &up->fmt.vbi, |
Hans Verkuil | 81e0acf | 2018-02-14 12:48:21 +0100 | [diff] [blame] | 220 | sizeof(kp->fmt.vbi)) ? -EFAULT : 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 221 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 222 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 223 | return copy_in_user(&kp->fmt.sliced, &up->fmt.sliced, |
Hans Verkuil | 81e0acf | 2018-02-14 12:48:21 +0100 | [diff] [blame] | 224 | sizeof(kp->fmt.sliced)) ? -EFAULT : 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 225 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
| 226 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 227 | return copy_in_user(&kp->fmt.sdr, &up->fmt.sdr, |
Hans Verkuil | 81e0acf | 2018-02-14 12:48:21 +0100 | [diff] [blame] | 228 | sizeof(kp->fmt.sdr)) ? -EFAULT : 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 229 | default: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 230 | return -EINVAL; |
| 231 | } |
| 232 | } |
| 233 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 234 | static int get_v4l2_format32(struct v4l2_format __user *kp, |
| 235 | struct v4l2_format32 __user *up, |
| 236 | void __user *aux_buf, u32 aux_space) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 237 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 238 | if (!access_ok(VERIFY_READ, up, sizeof(*up))) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 239 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 240 | return __get_v4l2_format32(kp, up, aux_buf, aux_space); |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 241 | } |
| 242 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 243 | static int bufsize_v4l2_create(struct v4l2_create_buffers32 __user *up, |
| 244 | u32 *size) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 245 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 246 | if (!access_ok(VERIFY_READ, up, sizeof(*up))) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 247 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 248 | return __bufsize_v4l2_format(&up->format, size); |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 249 | } |
| 250 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 251 | static int get_v4l2_create32(struct v4l2_create_buffers __user *kp, |
| 252 | struct v4l2_create_buffers32 __user *up, |
| 253 | void __user *aux_buf, u32 aux_space) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 254 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 255 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
| 256 | copy_in_user(kp, up, |
| 257 | offsetof(struct v4l2_create_buffers32, format))) |
| 258 | return -EFAULT; |
| 259 | return __get_v4l2_format32(&kp->format, &up->format, |
| 260 | aux_buf, aux_space); |
| 261 | } |
| 262 | |
| 263 | static int __put_v4l2_format32(struct v4l2_format __user *kp, |
| 264 | struct v4l2_format32 __user *up) |
| 265 | { |
| 266 | u32 type; |
| 267 | |
| 268 | if (get_user(type, &kp->type)) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 269 | return -EFAULT; |
| 270 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 271 | switch (type) { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 272 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 273 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 274 | return copy_in_user(&up->fmt.pix, &kp->fmt.pix, |
| 275 | sizeof(kp->fmt.pix)) ? -EFAULT : 0; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 276 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
| 277 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 278 | return copy_in_user(&up->fmt.pix_mp, &kp->fmt.pix_mp, |
| 279 | sizeof(kp->fmt.pix_mp)) ? -EFAULT : 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 280 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 281 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 282 | return put_v4l2_window32(&kp->fmt.win, &up->fmt.win); |
| 283 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 284 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 285 | return copy_in_user(&up->fmt.vbi, &kp->fmt.vbi, |
| 286 | sizeof(kp->fmt.vbi)) ? -EFAULT : 0; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 287 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 288 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 289 | return copy_in_user(&up->fmt.sliced, &kp->fmt.sliced, |
| 290 | sizeof(kp->fmt.sliced)) ? -EFAULT : 0; |
Hans Verkuil | d5beb67 | 2015-09-17 06:46:04 -0300 | [diff] [blame] | 291 | case V4L2_BUF_TYPE_SDR_CAPTURE: |
Antti Palosaari | 9effc72 | 2015-10-10 13:51:00 -0300 | [diff] [blame] | 292 | case V4L2_BUF_TYPE_SDR_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 293 | return copy_in_user(&up->fmt.sdr, &kp->fmt.sdr, |
| 294 | sizeof(kp->fmt.sdr)) ? -EFAULT : 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 295 | default: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 296 | return -EINVAL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 300 | static int put_v4l2_format32(struct v4l2_format __user *kp, |
| 301 | struct v4l2_format32 __user *up) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 302 | { |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 303 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up))) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 304 | return -EFAULT; |
| 305 | return __put_v4l2_format32(kp, up); |
| 306 | } |
| 307 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 308 | static int put_v4l2_create32(struct v4l2_create_buffers __user *kp, |
| 309 | struct v4l2_create_buffers32 __user *up) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 310 | { |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 311 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 312 | copy_in_user(up, kp, |
| 313 | offsetof(struct v4l2_create_buffers32, format)) || |
| 314 | copy_in_user(up->reserved, kp->reserved, sizeof(kp->reserved))) |
Guennadi Liakhovetski | 6ed9b28 | 2014-05-30 20:26:38 -0300 | [diff] [blame] | 315 | return -EFAULT; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 316 | return __put_v4l2_format32(&kp->format, &up->format); |
| 317 | } |
| 318 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 319 | struct v4l2_standard32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 320 | __u32 index; |
Andrzej Hajda | 655e978 | 2015-08-31 08:56:15 -0300 | [diff] [blame] | 321 | compat_u64 id; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 322 | __u8 name[24]; |
| 323 | struct v4l2_fract frameperiod; /* Frames, not fields */ |
| 324 | __u32 framelines; |
| 325 | __u32 reserved[4]; |
| 326 | }; |
| 327 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 328 | static int get_v4l2_standard32(struct v4l2_standard __user *kp, |
| 329 | struct v4l2_standard32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 330 | { |
| 331 | /* other fields are not set by the user, nor used by the driver */ |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 332 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 333 | assign_in_user(&kp->index, &up->index)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 334 | return -EFAULT; |
| 335 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 336 | } |
| 337 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 338 | static int put_v4l2_standard32(struct v4l2_standard __user *kp, |
| 339 | struct v4l2_standard32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 340 | { |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 341 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 342 | assign_in_user(&up->index, &kp->index) || |
| 343 | assign_in_user(&up->id, &kp->id) || |
| 344 | copy_in_user(up->name, kp->name, sizeof(up->name)) || |
| 345 | copy_in_user(&up->frameperiod, &kp->frameperiod, |
| 346 | sizeof(up->frameperiod)) || |
| 347 | assign_in_user(&up->framelines, &kp->framelines) || |
| 348 | copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved))) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 349 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 353 | struct v4l2_plane32 { |
| 354 | __u32 bytesused; |
| 355 | __u32 length; |
| 356 | union { |
| 357 | __u32 mem_offset; |
| 358 | compat_long_t userptr; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 359 | __s32 fd; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 360 | } m; |
| 361 | __u32 data_offset; |
| 362 | __u32 reserved[11]; |
| 363 | }; |
| 364 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 365 | struct v4l2_buffer32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 366 | __u32 index; |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 367 | __u32 type; /* enum v4l2_buf_type */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 368 | __u32 bytesused; |
| 369 | __u32 flags; |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 370 | __u32 field; /* enum v4l2_field */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 371 | struct compat_timeval timestamp; |
| 372 | struct v4l2_timecode timecode; |
| 373 | __u32 sequence; |
| 374 | |
| 375 | /* memory location */ |
Sakari Ailus | 6016af8 | 2012-05-10 02:02:07 -0300 | [diff] [blame] | 376 | __u32 memory; /* enum v4l2_memory */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 377 | union { |
| 378 | __u32 offset; |
| 379 | compat_long_t userptr; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 380 | compat_caddr_t planes; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 381 | __s32 fd; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 382 | } m; |
| 383 | __u32 length; |
Sakari Ailus | 2b719d7 | 2012-05-02 09:40:03 -0300 | [diff] [blame] | 384 | __u32 reserved2; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 385 | __u32 reserved; |
| 386 | }; |
| 387 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 388 | static int get_v4l2_plane32(struct v4l2_plane __user *up, |
| 389 | struct v4l2_plane32 __user *up32, |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 390 | enum v4l2_memory memory) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 391 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 392 | compat_ulong_t p; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 393 | |
| 394 | if (copy_in_user(up, up32, 2 * sizeof(__u32)) || |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 395 | copy_in_user(&up->data_offset, &up32->data_offset, |
Blagovest Kolenichev | 82ccf83 | 2018-02-22 03:25:47 -0800 | [diff] [blame] | 396 | sizeof(up->data_offset)) || |
| 397 | copy_in_user(up->reserved, up32->reserved, |
| 398 | sizeof(up->reserved)) || |
| 399 | copy_in_user(&up->length, &up32->length, |
| 400 | sizeof(up->length))) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 401 | return -EFAULT; |
| 402 | |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 403 | switch (memory) { |
| 404 | case V4L2_MEMORY_MMAP: |
| 405 | case V4L2_MEMORY_OVERLAY: |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 406 | if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset, |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 407 | sizeof(up32->m.mem_offset))) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 408 | return -EFAULT; |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 409 | break; |
| 410 | case V4L2_MEMORY_USERPTR: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 411 | if (get_user(p, &up32->m.userptr) || |
| 412 | put_user((unsigned long)compat_ptr(p), &up->m.userptr)) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 413 | return -EFAULT; |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 414 | break; |
| 415 | case V4L2_MEMORY_DMABUF: |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 416 | if (copy_in_user(&up->m.fd, &up32->m.fd, sizeof(up32->m.fd))) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 417 | return -EFAULT; |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 418 | break; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 424 | static int put_v4l2_plane32(struct v4l2_plane __user *up, |
| 425 | struct v4l2_plane32 __user *up32, |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 426 | enum v4l2_memory memory) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 427 | { |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 428 | unsigned long p; |
| 429 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 430 | if (copy_in_user(up32, up, 2 * sizeof(__u32)) || |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 431 | copy_in_user(&up32->data_offset, &up->data_offset, |
Blagovest Kolenichev | 82ccf83 | 2018-02-22 03:25:47 -0800 | [diff] [blame] | 432 | sizeof(up->data_offset)) || |
| 433 | copy_in_user(up32->reserved, up->reserved, |
| 434 | sizeof(up32->reserved))) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 435 | return -EFAULT; |
| 436 | |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 437 | switch (memory) { |
| 438 | case V4L2_MEMORY_MMAP: |
| 439 | case V4L2_MEMORY_OVERLAY: |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 440 | if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset, |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 441 | sizeof(up->m.mem_offset))) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 442 | return -EFAULT; |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 443 | break; |
| 444 | case V4L2_MEMORY_USERPTR: |
| 445 | if (get_user(p, &up->m.userptr) || |
| 446 | put_user((compat_ulong_t)ptr_to_compat((__force void *)p), |
| 447 | &up32->m.userptr)) |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 448 | return -EFAULT; |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 449 | break; |
| 450 | case V4L2_MEMORY_DMABUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 451 | if (copy_in_user(&up32->m.fd, &up->m.fd, sizeof(up->m.fd))) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 452 | return -EFAULT; |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 453 | break; |
| 454 | } |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 459 | static int bufsize_v4l2_buffer(struct v4l2_buffer32 __user *up, u32 *size) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 460 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 461 | u32 type; |
| 462 | u32 length; |
| 463 | |
| 464 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
| 465 | get_user(type, &up->type) || |
| 466 | get_user(length, &up->length)) |
| 467 | return -EFAULT; |
| 468 | |
| 469 | if (V4L2_TYPE_IS_MULTIPLANAR(type)) { |
| 470 | if (length > VIDEO_MAX_PLANES) |
| 471 | return -EINVAL; |
| 472 | |
| 473 | /* |
| 474 | * We don't really care if userspace decides to kill itself |
| 475 | * by passing a very big length value |
| 476 | */ |
| 477 | *size = length * sizeof(struct v4l2_plane); |
| 478 | } else { |
| 479 | *size = 0; |
| 480 | } |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, |
| 485 | struct v4l2_buffer32 __user *up, |
| 486 | void __user *aux_buf, u32 aux_space) |
| 487 | { |
| 488 | u32 type; |
| 489 | u32 length; |
| 490 | enum v4l2_memory memory; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 491 | struct v4l2_plane32 __user *uplane32; |
| 492 | struct v4l2_plane __user *uplane; |
| 493 | compat_caddr_t p; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 494 | int ret; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 495 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 496 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 497 | assign_in_user(&kp->index, &up->index) || |
| 498 | get_user(type, &up->type) || |
| 499 | put_user(type, &kp->type) || |
| 500 | assign_in_user(&kp->flags, &up->flags) || |
| 501 | get_user(memory, &up->memory) || |
| 502 | put_user(memory, &kp->memory) || |
| 503 | get_user(length, &up->length) || |
| 504 | put_user(length, &kp->length)) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 505 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 506 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 507 | if (V4L2_TYPE_IS_OUTPUT(type)) |
| 508 | if (assign_in_user(&kp->bytesused, &up->bytesused) || |
| 509 | assign_in_user(&kp->field, &up->field) || |
| 510 | assign_in_user(&kp->timestamp.tv_sec, |
| 511 | &up->timestamp.tv_sec) || |
| 512 | assign_in_user(&kp->timestamp.tv_usec, |
| 513 | &up->timestamp.tv_usec)) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 514 | return -EFAULT; |
| 515 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 516 | if (V4L2_TYPE_IS_MULTIPLANAR(type)) { |
| 517 | u32 num_planes = length; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 518 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 519 | if (num_planes == 0) { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 520 | /* |
| 521 | * num_planes == 0 is legal, e.g. when userspace doesn't |
| 522 | * need planes array on DQBUF |
| 523 | */ |
| 524 | return put_user(NULL, &kp->m.planes); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 525 | } |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 526 | if (num_planes > VIDEO_MAX_PLANES) |
| 527 | return -EINVAL; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 528 | |
| 529 | if (get_user(p, &up->m.planes)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 530 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 531 | |
| 532 | uplane32 = compat_ptr(p); |
| 533 | if (!access_ok(VERIFY_READ, uplane32, |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 534 | num_planes * sizeof(*uplane32))) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 535 | return -EFAULT; |
| 536 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 537 | /* |
| 538 | * We don't really care if userspace decides to kill itself |
| 539 | * by passing a very big num_planes value |
| 540 | */ |
| 541 | if (aux_space < num_planes * sizeof(*uplane)) |
| 542 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 543 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 544 | uplane = aux_buf; |
| 545 | if (put_user((__force struct v4l2_plane *)uplane, |
| 546 | &kp->m.planes)) |
| 547 | return -EFAULT; |
| 548 | |
| 549 | while (num_planes--) { |
| 550 | ret = get_v4l2_plane32(uplane, uplane32, memory); |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 551 | if (ret) |
| 552 | return ret; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 553 | uplane++; |
| 554 | uplane32++; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 555 | } |
| 556 | } else { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 557 | switch (memory) { |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 558 | case V4L2_MEMORY_MMAP: |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 559 | case V4L2_MEMORY_OVERLAY: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 560 | if (assign_in_user(&kp->m.offset, &up->m.offset)) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 561 | return -EFAULT; |
| 562 | break; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 563 | case V4L2_MEMORY_USERPTR: { |
| 564 | compat_ulong_t userptr; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 565 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 566 | if (get_user(userptr, &up->m.userptr) || |
| 567 | put_user((unsigned long)compat_ptr(userptr), |
| 568 | &kp->m.userptr)) |
| 569 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 570 | break; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 571 | } |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 572 | case V4L2_MEMORY_DMABUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 573 | if (assign_in_user(&kp->m.fd, &up->m.fd)) |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 574 | return -EFAULT; |
| 575 | break; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 576 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 577 | } |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 578 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 579 | return 0; |
| 580 | } |
| 581 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 582 | static int put_v4l2_buffer32(struct v4l2_buffer __user *kp, |
| 583 | struct v4l2_buffer32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 584 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 585 | u32 type; |
| 586 | u32 length; |
| 587 | enum v4l2_memory memory; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 588 | struct v4l2_plane32 __user *uplane32; |
| 589 | struct v4l2_plane __user *uplane; |
| 590 | compat_caddr_t p; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 591 | int ret; |
| 592 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 593 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 594 | assign_in_user(&up->index, &kp->index) || |
| 595 | get_user(type, &kp->type) || |
| 596 | put_user(type, &up->type) || |
| 597 | assign_in_user(&up->flags, &kp->flags) || |
| 598 | get_user(memory, &kp->memory) || |
| 599 | put_user(memory, &up->memory)) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 600 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 601 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 602 | if (assign_in_user(&up->bytesused, &kp->bytesused) || |
| 603 | assign_in_user(&up->field, &kp->field) || |
| 604 | assign_in_user(&up->timestamp.tv_sec, &kp->timestamp.tv_sec) || |
| 605 | assign_in_user(&up->timestamp.tv_usec, &kp->timestamp.tv_usec) || |
| 606 | copy_in_user(&up->timecode, &kp->timecode, sizeof(kp->timecode)) || |
| 607 | assign_in_user(&up->sequence, &kp->sequence) || |
| 608 | assign_in_user(&up->reserved2, &kp->reserved2) || |
| 609 | assign_in_user(&up->reserved, &kp->reserved) || |
| 610 | get_user(length, &kp->length) || |
| 611 | put_user(length, &up->length)) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 612 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 613 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 614 | if (V4L2_TYPE_IS_MULTIPLANAR(type)) { |
| 615 | u32 num_planes = length; |
| 616 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 617 | if (num_planes == 0) |
| 618 | return 0; |
| 619 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 620 | if (get_user(uplane, ((__force struct v4l2_plane __user **)&kp->m.planes))) |
| 621 | return -EFAULT; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 622 | if (get_user(p, &up->m.planes)) |
| 623 | return -EFAULT; |
| 624 | uplane32 = compat_ptr(p); |
| 625 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 626 | while (num_planes--) { |
| 627 | ret = put_v4l2_plane32(uplane, uplane32, memory); |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 628 | if (ret) |
| 629 | return ret; |
| 630 | ++uplane; |
| 631 | ++uplane32; |
| 632 | } |
| 633 | } else { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 634 | switch (memory) { |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 635 | case V4L2_MEMORY_MMAP: |
Hans Verkuil | eec9554 | 2018-02-14 12:48:23 +0100 | [diff] [blame] | 636 | case V4L2_MEMORY_OVERLAY: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 637 | if (assign_in_user(&up->m.offset, &kp->m.offset)) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 638 | return -EFAULT; |
| 639 | break; |
| 640 | case V4L2_MEMORY_USERPTR: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 641 | if (assign_in_user(&up->m.userptr, &kp->m.userptr)) |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 642 | return -EFAULT; |
| 643 | break; |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 644 | case V4L2_MEMORY_DMABUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 645 | if (assign_in_user(&up->m.fd, &kp->m.fd)) |
Sumit Semwal | 051c778 | 2012-06-14 10:37:35 -0300 | [diff] [blame] | 646 | return -EFAULT; |
| 647 | break; |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 654 | struct v4l2_framebuffer32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 655 | __u32 capability; |
| 656 | __u32 flags; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 657 | compat_caddr_t base; |
Laurent Pinchart | d52e238 | 2014-05-27 09:41:05 -0300 | [diff] [blame] | 658 | struct { |
| 659 | __u32 width; |
| 660 | __u32 height; |
| 661 | __u32 pixelformat; |
| 662 | __u32 field; |
| 663 | __u32 bytesperline; |
| 664 | __u32 sizeimage; |
| 665 | __u32 colorspace; |
| 666 | __u32 priv; |
| 667 | } fmt; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 668 | }; |
| 669 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 670 | static int get_v4l2_framebuffer32(struct v4l2_framebuffer __user *kp, |
| 671 | struct v4l2_framebuffer32 __user *up) |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 672 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 673 | compat_caddr_t tmp; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 674 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 675 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 676 | get_user(tmp, &up->base) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 677 | put_user((__force void *)compat_ptr(tmp), &kp->base) || |
| 678 | assign_in_user(&kp->capability, &up->capability) || |
| 679 | assign_in_user(&kp->flags, &up->flags) || |
| 680 | copy_in_user(&kp->fmt, &up->fmt, sizeof(kp->fmt))) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 681 | return -EFAULT; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 685 | static int put_v4l2_framebuffer32(struct v4l2_framebuffer __user *kp, |
| 686 | struct v4l2_framebuffer32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 687 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 688 | void *base; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 689 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 690 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 691 | get_user(base, &kp->base) || |
| 692 | put_user(ptr_to_compat(base), &up->base) || |
| 693 | assign_in_user(&up->capability, &kp->capability) || |
| 694 | assign_in_user(&up->flags, &kp->flags) || |
| 695 | copy_in_user(&up->fmt, &kp->fmt, sizeof(kp->fmt))) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 696 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 697 | return 0; |
| 698 | } |
| 699 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 700 | struct v4l2_input32 { |
| 701 | __u32 index; /* Which input */ |
| 702 | __u8 name[32]; /* Label */ |
| 703 | __u32 type; /* Type of input */ |
| 704 | __u32 audioset; /* Associated audios (bitfield) */ |
| 705 | __u32 tuner; /* Associated tuner */ |
Andrzej Hajda | 655e978 | 2015-08-31 08:56:15 -0300 | [diff] [blame] | 706 | compat_u64 std; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 707 | __u32 status; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 708 | __u32 capabilities; |
| 709 | __u32 reserved[3]; |
Andrzej Hajda | 655e978 | 2015-08-31 08:56:15 -0300 | [diff] [blame] | 710 | }; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 711 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 712 | /* |
| 713 | * The 64-bit v4l2_input struct has extra padding at the end of the struct. |
| 714 | * Otherwise it is identical to the 32-bit version. |
| 715 | */ |
| 716 | static inline int get_v4l2_input32(struct v4l2_input __user *kp, |
| 717 | struct v4l2_input32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 718 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 719 | if (copy_in_user(kp, up, sizeof(*up))) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 720 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 721 | return 0; |
| 722 | } |
| 723 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 724 | static inline int put_v4l2_input32(struct v4l2_input __user *kp, |
| 725 | struct v4l2_input32 __user *up) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 726 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 727 | if (copy_in_user(up, kp, sizeof(*up))) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 728 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 732 | struct v4l2_ext_controls32 { |
Ricardo Ribalda | 0f8017b | 2015-10-29 08:10:28 -0200 | [diff] [blame] | 733 | __u32 which; |
Ricardo Ribalda | 28c5029 | 2015-08-21 10:19:22 -0300 | [diff] [blame] | 734 | __u32 count; |
| 735 | __u32 error_idx; |
| 736 | __u32 reserved[2]; |
| 737 | compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */ |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 738 | }; |
| 739 | |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 740 | struct v4l2_ext_control32 { |
| 741 | __u32 id; |
| 742 | __u32 size; |
| 743 | __u32 reserved2[1]; |
| 744 | union { |
| 745 | __s32 value; |
| 746 | __s64 value64; |
| 747 | compat_caddr_t string; /* actually char * */ |
| 748 | }; |
| 749 | } __attribute__ ((packed)); |
| 750 | |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 751 | /* Return true if this control is a pointer type. */ |
| 752 | static inline bool ctrl_is_pointer(struct file *file, u32 id) |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 753 | { |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 754 | struct video_device *vdev = video_devdata(file); |
| 755 | struct v4l2_fh *fh = NULL; |
| 756 | struct v4l2_ctrl_handler *hdl = NULL; |
| 757 | struct v4l2_query_ext_ctrl qec = { id }; |
| 758 | const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops; |
| 759 | |
| 760 | if (test_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags)) |
| 761 | fh = file->private_data; |
| 762 | |
| 763 | if (fh && fh->ctrl_handler) |
| 764 | hdl = fh->ctrl_handler; |
| 765 | else if (vdev->ctrl_handler) |
| 766 | hdl = vdev->ctrl_handler; |
| 767 | |
| 768 | if (hdl) { |
| 769 | struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, id); |
| 770 | |
| 771 | return ctrl && ctrl->is_ptr; |
Eduardo Valentin | fdf82dc | 2009-08-11 18:49:12 -0300 | [diff] [blame] | 772 | } |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 773 | |
Hans Verkuil | 8465657 | 2018-02-14 12:48:25 +0100 | [diff] [blame] | 774 | if (!ops || !ops->vidioc_query_ext_ctrl) |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 775 | return false; |
| 776 | |
| 777 | return !ops->vidioc_query_ext_ctrl(file, fh, &qec) && |
| 778 | (qec.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD); |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 779 | } |
| 780 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 781 | static int bufsize_v4l2_ext_controls(struct v4l2_ext_controls32 __user *up, |
| 782 | u32 *size) |
| 783 | { |
| 784 | u32 count; |
| 785 | |
| 786 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
| 787 | get_user(count, &up->count)) |
| 788 | return -EFAULT; |
| 789 | if (count > V4L2_CID_MAX_CTRLS) |
| 790 | return -EINVAL; |
| 791 | *size = count * sizeof(struct v4l2_ext_control); |
| 792 | return 0; |
| 793 | } |
| 794 | |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 795 | static int get_v4l2_ext_controls32(struct file *file, |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 796 | struct v4l2_ext_controls __user *kp, |
| 797 | struct v4l2_ext_controls32 __user *up, |
| 798 | void __user *aux_buf, u32 aux_space) |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 799 | { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 800 | struct v4l2_ext_control32 __user *ucontrols; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 801 | struct v4l2_ext_control __user *kcontrols; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 802 | u32 count; |
| 803 | u32 n; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 804 | compat_caddr_t p; |
| 805 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 806 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 807 | assign_in_user(&kp->which, &up->which) || |
| 808 | get_user(count, &up->count) || |
| 809 | put_user(count, &kp->count) || |
| 810 | assign_in_user(&kp->error_idx, &up->error_idx) || |
| 811 | copy_in_user(kp->reserved, up->reserved, sizeof(kp->reserved))) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 812 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 813 | |
| 814 | if (count == 0) |
| 815 | return put_user(NULL, &kp->controls); |
| 816 | if (count > V4L2_CID_MAX_CTRLS) |
| 817 | return -EINVAL; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 818 | if (get_user(p, &up->controls)) |
| 819 | return -EFAULT; |
| 820 | ucontrols = compat_ptr(p); |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 821 | if (!access_ok(VERIFY_READ, ucontrols, count * sizeof(*ucontrols))) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 822 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 823 | if (aux_space < count * sizeof(*kcontrols)) |
| 824 | return -EFAULT; |
| 825 | kcontrols = aux_buf; |
| 826 | if (put_user((__force struct v4l2_ext_control *)kcontrols, |
| 827 | &kp->controls)) |
| 828 | return -EFAULT; |
| 829 | |
| 830 | for (n = 0; n < count; n++) { |
Hans Verkuil | 8ae632b | 2014-08-21 17:07:21 -0300 | [diff] [blame] | 831 | u32 id; |
| 832 | |
Pawel Osciak | 52a3082 | 2010-07-29 14:56:47 -0300 | [diff] [blame] | 833 | if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols))) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 834 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 835 | |
Hans Verkuil | 8ae632b | 2014-08-21 17:07:21 -0300 | [diff] [blame] | 836 | if (get_user(id, &kcontrols->id)) |
| 837 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 838 | |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 839 | if (ctrl_is_pointer(file, id)) { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 840 | void __user *s; |
| 841 | |
| 842 | if (get_user(p, &ucontrols->string)) |
| 843 | return -EFAULT; |
| 844 | s = compat_ptr(p); |
| 845 | if (put_user(s, &kcontrols->string)) |
| 846 | return -EFAULT; |
| 847 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 848 | ucontrols++; |
| 849 | kcontrols++; |
| 850 | } |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 851 | return 0; |
| 852 | } |
| 853 | |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 854 | static int put_v4l2_ext_controls32(struct file *file, |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 855 | struct v4l2_ext_controls __user *kp, |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 856 | struct v4l2_ext_controls32 __user *up) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 857 | { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 858 | struct v4l2_ext_control32 __user *ucontrols; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 859 | struct v4l2_ext_control __user *kcontrols; |
| 860 | u32 count; |
| 861 | u32 n; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 862 | compat_caddr_t p; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 863 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 864 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 865 | assign_in_user(&up->which, &kp->which) || |
| 866 | get_user(count, &kp->count) || |
| 867 | put_user(count, &up->count) || |
| 868 | assign_in_user(&up->error_idx, &kp->error_idx) || |
| 869 | copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved)) || |
| 870 | get_user(kcontrols, &kp->controls)) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 871 | return -EFAULT; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 872 | |
Mauro Carvalho Chehab | 1e6b50b | 2018-04-11 11:47:32 -0400 | [diff] [blame] | 873 | if (!count || count > (U32_MAX/sizeof(*ucontrols))) |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 874 | return 0; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 875 | if (get_user(p, &up->controls)) |
| 876 | return -EFAULT; |
| 877 | ucontrols = compat_ptr(p); |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 878 | if (!access_ok(VERIFY_WRITE, ucontrols, count * sizeof(*ucontrols))) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 879 | return -EFAULT; |
| 880 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 881 | for (n = 0; n < count; n++) { |
| 882 | unsigned int size = sizeof(*ucontrols); |
Hans Verkuil | 8ae632b | 2014-08-21 17:07:21 -0300 | [diff] [blame] | 883 | u32 id; |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 884 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 885 | if (get_user(id, &kcontrols->id) || |
| 886 | put_user(id, &ucontrols->id) || |
| 887 | assign_in_user(&ucontrols->size, &kcontrols->size) || |
| 888 | copy_in_user(&ucontrols->reserved2, &kcontrols->reserved2, |
| 889 | sizeof(ucontrols->reserved2))) |
Hans Verkuil | 8ae632b | 2014-08-21 17:07:21 -0300 | [diff] [blame] | 890 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 891 | |
| 892 | /* |
| 893 | * Do not modify the pointer when copying a pointer control. |
| 894 | * The contents of the pointer was changed, not the pointer |
| 895 | * itself. |
| 896 | */ |
Hans Verkuil | 9a7cd41 | 2018-02-14 12:48:24 +0100 | [diff] [blame] | 897 | if (ctrl_is_pointer(file, id)) |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 898 | size -= sizeof(ucontrols->value64); |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 899 | |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 900 | if (copy_in_user(ucontrols, kcontrols, size)) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 901 | return -EFAULT; |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 902 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 903 | ucontrols++; |
| 904 | kcontrols++; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 905 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 906 | return 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 907 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 908 | |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 909 | struct v4l2_event32 { |
| 910 | __u32 type; |
| 911 | union { |
Andrzej Hajda | 655e978 | 2015-08-31 08:56:15 -0300 | [diff] [blame] | 912 | compat_s64 value64; |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 913 | __u8 data[64]; |
| 914 | } u; |
| 915 | __u32 pending; |
| 916 | __u32 sequence; |
| 917 | struct compat_timespec timestamp; |
| 918 | __u32 id; |
| 919 | __u32 reserved[8]; |
| 920 | }; |
| 921 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 922 | static int put_v4l2_event32(struct v4l2_event __user *kp, |
| 923 | struct v4l2_event32 __user *up) |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 924 | { |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 925 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 926 | assign_in_user(&up->type, &kp->type) || |
| 927 | copy_in_user(&up->u, &kp->u, sizeof(kp->u)) || |
| 928 | assign_in_user(&up->pending, &kp->pending) || |
| 929 | assign_in_user(&up->sequence, &kp->sequence) || |
| 930 | assign_in_user(&up->timestamp.tv_sec, &kp->timestamp.tv_sec) || |
| 931 | assign_in_user(&up->timestamp.tv_nsec, &kp->timestamp.tv_nsec) || |
| 932 | assign_in_user(&up->id, &kp->id) || |
| 933 | copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved))) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 934 | return -EFAULT; |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
Hans Verkuil | dd519bb | 2014-03-07 07:18:37 -0300 | [diff] [blame] | 938 | struct v4l2_edid32 { |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 939 | __u32 pad; |
| 940 | __u32 start_block; |
| 941 | __u32 blocks; |
| 942 | __u32 reserved[5]; |
| 943 | compat_caddr_t edid; |
| 944 | }; |
| 945 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 946 | static int get_v4l2_edid32(struct v4l2_edid __user *kp, |
| 947 | struct v4l2_edid32 __user *up) |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 948 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 949 | compat_uptr_t tmp; |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 950 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 951 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 952 | assign_in_user(&kp->pad, &up->pad) || |
| 953 | assign_in_user(&kp->start_block, &up->start_block) || |
| 954 | assign_in_user(&kp->blocks, &up->blocks) || |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 955 | get_user(tmp, &up->edid) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 956 | put_user(compat_ptr(tmp), &kp->edid) || |
| 957 | copy_in_user(kp->reserved, up->reserved, sizeof(kp->reserved))) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 958 | return -EFAULT; |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 959 | return 0; |
| 960 | } |
| 961 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 962 | static int put_v4l2_edid32(struct v4l2_edid __user *kp, |
| 963 | struct v4l2_edid32 __user *up) |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 964 | { |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 965 | void *edid; |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 966 | |
Hans Verkuil | daff4d0 | 2018-02-14 12:48:22 +0100 | [diff] [blame] | 967 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 968 | assign_in_user(&up->pad, &kp->pad) || |
| 969 | assign_in_user(&up->start_block, &kp->start_block) || |
| 970 | assign_in_user(&up->blocks, &kp->blocks) || |
| 971 | get_user(edid, &kp->edid) || |
| 972 | put_user(ptr_to_compat(edid), &up->edid) || |
| 973 | copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved))) |
Hans Verkuil | 02129c9 | 2018-02-14 12:48:20 +0100 | [diff] [blame] | 974 | return -EFAULT; |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 979 | #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32) |
| 980 | #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32) |
| 981 | #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32) |
| 982 | #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32) |
| 983 | #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32) |
| 984 | #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32) |
| 985 | #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32) |
| 986 | #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32) |
| 987 | #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32) |
Hans Verkuil | dd519bb | 2014-03-07 07:18:37 -0300 | [diff] [blame] | 988 | #define VIDIOC_G_EDID32 _IOWR('V', 40, struct v4l2_edid32) |
| 989 | #define VIDIOC_S_EDID32 _IOWR('V', 41, struct v4l2_edid32) |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 990 | #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 991 | #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32) |
| 992 | #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32) |
| 993 | #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32) |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 994 | #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32) |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 995 | #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32) |
| 996 | #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 997 | |
| 998 | #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 999 | #define VIDIOC_STREAMON32 _IOW ('V', 18, s32) |
| 1000 | #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32) |
| 1001 | #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32) |
| 1002 | #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32) |
| 1003 | #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32) |
| 1004 | #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1005 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1006 | static int alloc_userspace(unsigned int size, u32 aux_space, |
| 1007 | void __user **up_native) |
| 1008 | { |
| 1009 | *up_native = compat_alloc_user_space(size + aux_space); |
| 1010 | if (!*up_native) |
| 1011 | return -ENOMEM; |
| 1012 | if (clear_user(*up_native, size)) |
| 1013 | return -EFAULT; |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1017 | 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] | 1018 | { |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1019 | void __user *up = compat_ptr(arg); |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1020 | void __user *up_native = NULL; |
| 1021 | void __user *aux_buf; |
| 1022 | u32 aux_space; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1023 | int compatible_arg = 1; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1024 | long err = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1025 | |
| 1026 | /* First, convert the command. */ |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 1027 | switch (cmd) { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1028 | case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; |
| 1029 | case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; |
| 1030 | case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; |
| 1031 | case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break; |
| 1032 | case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break; |
| 1033 | case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break; |
| 1034 | case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break; |
| 1035 | case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break; |
| 1036 | case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break; |
| 1037 | case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break; |
| 1038 | case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break; |
| 1039 | case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break; |
| 1040 | case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break; |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 1041 | case VIDIOC_DQEVENT32: cmd = VIDIOC_DQEVENT; break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1042 | case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1043 | case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break; |
| 1044 | case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break; |
| 1045 | case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break; |
| 1046 | case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; |
| 1047 | case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break; |
| 1048 | case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break; |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 1049 | case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break; |
| 1050 | case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break; |
Hans Verkuil | dd519bb | 2014-03-07 07:18:37 -0300 | [diff] [blame] | 1051 | case VIDIOC_G_EDID32: cmd = VIDIOC_G_EDID; break; |
| 1052 | case VIDIOC_S_EDID32: cmd = VIDIOC_S_EDID; break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1053 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1054 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 1055 | switch (cmd) { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1056 | case VIDIOC_OVERLAY: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1057 | case VIDIOC_STREAMON: |
| 1058 | case VIDIOC_STREAMOFF: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1059 | case VIDIOC_S_INPUT: |
| 1060 | case VIDIOC_S_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1061 | err = alloc_userspace(sizeof(unsigned int), 0, &up_native); |
| 1062 | if (!err && assign_in_user((unsigned int __user *)up_native, |
| 1063 | (compat_uint_t __user *)up)) |
| 1064 | err = -EFAULT; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1065 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1066 | break; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1067 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1068 | case VIDIOC_G_INPUT: |
| 1069 | case VIDIOC_G_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1070 | err = alloc_userspace(sizeof(unsigned int), 0, &up_native); |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1071 | compatible_arg = 0; |
| 1072 | break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1073 | |
Hans Verkuil | dd519bb | 2014-03-07 07:18:37 -0300 | [diff] [blame] | 1074 | case VIDIOC_G_EDID: |
| 1075 | case VIDIOC_S_EDID: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1076 | err = alloc_userspace(sizeof(struct v4l2_edid), 0, &up_native); |
| 1077 | if (!err) |
| 1078 | err = get_v4l2_edid32(up_native, up); |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 1079 | compatible_arg = 0; |
| 1080 | break; |
| 1081 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1082 | case VIDIOC_G_FMT: |
| 1083 | case VIDIOC_S_FMT: |
| 1084 | case VIDIOC_TRY_FMT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1085 | err = bufsize_v4l2_format(up, &aux_space); |
| 1086 | if (!err) |
| 1087 | err = alloc_userspace(sizeof(struct v4l2_format), |
| 1088 | aux_space, &up_native); |
| 1089 | if (!err) { |
| 1090 | aux_buf = up_native + sizeof(struct v4l2_format); |
| 1091 | err = get_v4l2_format32(up_native, up, |
| 1092 | aux_buf, aux_space); |
| 1093 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1094 | compatible_arg = 0; |
| 1095 | break; |
| 1096 | |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 1097 | case VIDIOC_CREATE_BUFS: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1098 | err = bufsize_v4l2_create(up, &aux_space); |
| 1099 | if (!err) |
| 1100 | err = alloc_userspace(sizeof(struct v4l2_create_buffers), |
| 1101 | aux_space, &up_native); |
| 1102 | if (!err) { |
| 1103 | aux_buf = up_native + sizeof(struct v4l2_create_buffers); |
| 1104 | err = get_v4l2_create32(up_native, up, |
| 1105 | aux_buf, aux_space); |
| 1106 | } |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 1107 | compatible_arg = 0; |
| 1108 | break; |
| 1109 | |
| 1110 | case VIDIOC_PREPARE_BUF: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1111 | case VIDIOC_QUERYBUF: |
| 1112 | case VIDIOC_QBUF: |
| 1113 | case VIDIOC_DQBUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1114 | err = bufsize_v4l2_buffer(up, &aux_space); |
| 1115 | if (!err) |
| 1116 | err = alloc_userspace(sizeof(struct v4l2_buffer), |
| 1117 | aux_space, &up_native); |
| 1118 | if (!err) { |
| 1119 | aux_buf = up_native + sizeof(struct v4l2_buffer); |
| 1120 | err = get_v4l2_buffer32(up_native, up, |
| 1121 | aux_buf, aux_space); |
| 1122 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1123 | compatible_arg = 0; |
| 1124 | break; |
| 1125 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1126 | case VIDIOC_S_FBUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1127 | err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0, |
| 1128 | &up_native); |
| 1129 | if (!err) |
| 1130 | err = get_v4l2_framebuffer32(up_native, up); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 1131 | compatible_arg = 0; |
| 1132 | break; |
| 1133 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1134 | case VIDIOC_G_FBUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1135 | err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0, |
| 1136 | &up_native); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1137 | compatible_arg = 0; |
| 1138 | break; |
| 1139 | |
| 1140 | case VIDIOC_ENUMSTD: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1141 | err = alloc_userspace(sizeof(struct v4l2_standard), 0, |
| 1142 | &up_native); |
| 1143 | if (!err) |
| 1144 | err = get_v4l2_standard32(up_native, up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1145 | compatible_arg = 0; |
| 1146 | break; |
| 1147 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 1148 | case VIDIOC_ENUMINPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1149 | err = alloc_userspace(sizeof(struct v4l2_input), 0, &up_native); |
| 1150 | if (!err) |
| 1151 | err = get_v4l2_input32(up_native, up); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 1152 | compatible_arg = 0; |
| 1153 | break; |
| 1154 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1155 | case VIDIOC_G_EXT_CTRLS: |
| 1156 | case VIDIOC_S_EXT_CTRLS: |
| 1157 | case VIDIOC_TRY_EXT_CTRLS: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1158 | err = bufsize_v4l2_ext_controls(up, &aux_space); |
| 1159 | if (!err) |
| 1160 | err = alloc_userspace(sizeof(struct v4l2_ext_controls), |
| 1161 | aux_space, &up_native); |
| 1162 | if (!err) { |
| 1163 | aux_buf = up_native + sizeof(struct v4l2_ext_controls); |
| 1164 | err = get_v4l2_ext_controls32(file, up_native, up, |
| 1165 | aux_buf, aux_space); |
| 1166 | } |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 1167 | compatible_arg = 0; |
| 1168 | break; |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 1169 | case VIDIOC_DQEVENT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1170 | err = alloc_userspace(sizeof(struct v4l2_event), 0, &up_native); |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 1171 | compatible_arg = 0; |
| 1172 | break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1173 | } |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 1174 | if (err) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1175 | return err; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1176 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 1177 | if (compatible_arg) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1178 | err = native_ioctl(file, cmd, (unsigned long)up); |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1179 | else |
| 1180 | err = native_ioctl(file, cmd, (unsigned long)up_native); |
Blagovest Kolenichev | 8c74543 | 2018-02-26 04:59:56 -0800 | [diff] [blame] | 1181 | |
Hans Verkuil | 437c4ec | 2018-02-14 12:48:29 +0100 | [diff] [blame] | 1182 | if (err == -ENOTTY) |
| 1183 | return err; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1184 | |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1185 | /* |
| 1186 | * Special case: even after an error we need to put the |
| 1187 | * results back for these ioctls since the error_idx will |
| 1188 | * contain information on which control failed. |
| 1189 | */ |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1190 | switch (cmd) { |
| 1191 | case VIDIOC_G_EXT_CTRLS: |
| 1192 | case VIDIOC_S_EXT_CTRLS: |
| 1193 | case VIDIOC_TRY_EXT_CTRLS: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1194 | if (put_v4l2_ext_controls32(file, up_native, up)) |
| 1195 | err = -EFAULT; |
| 1196 | break; |
| 1197 | case VIDIOC_S_EDID: |
| 1198 | if (put_v4l2_edid32(up_native, up)) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1199 | err = -EFAULT; |
| 1200 | break; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1201 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1202 | if (err) |
| 1203 | return err; |
| 1204 | |
| 1205 | switch (cmd) { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1206 | case VIDIOC_S_INPUT: |
| 1207 | case VIDIOC_S_OUTPUT: |
| 1208 | case VIDIOC_G_INPUT: |
| 1209 | case VIDIOC_G_OUTPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1210 | if (assign_in_user((compat_uint_t __user *)up, |
| 1211 | ((unsigned int __user *)up_native))) |
| 1212 | err = -EFAULT; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1213 | break; |
| 1214 | |
| 1215 | case VIDIOC_G_FBUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1216 | err = put_v4l2_framebuffer32(up_native, up); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1217 | break; |
| 1218 | |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 1219 | case VIDIOC_DQEVENT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1220 | err = put_v4l2_event32(up_native, up); |
Hans Verkuil | 2330fb8 | 2011-06-07 11:43:57 -0300 | [diff] [blame] | 1221 | break; |
| 1222 | |
Hans Verkuil | dd519bb | 2014-03-07 07:18:37 -0300 | [diff] [blame] | 1223 | case VIDIOC_G_EDID: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1224 | err = put_v4l2_edid32(up_native, up); |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 1225 | break; |
| 1226 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1227 | case VIDIOC_G_FMT: |
| 1228 | case VIDIOC_S_FMT: |
| 1229 | case VIDIOC_TRY_FMT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1230 | err = put_v4l2_format32(up_native, up); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1231 | break; |
| 1232 | |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 1233 | case VIDIOC_CREATE_BUFS: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1234 | err = put_v4l2_create32(up_native, up); |
Guennadi Liakhovetski | 2150158 | 2011-09-28 11:34:06 -0300 | [diff] [blame] | 1235 | break; |
| 1236 | |
Hans Verkuil | f294548 | 2018-02-14 12:48:19 +0100 | [diff] [blame] | 1237 | case VIDIOC_PREPARE_BUF: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1238 | case VIDIOC_QUERYBUF: |
| 1239 | case VIDIOC_QBUF: |
| 1240 | case VIDIOC_DQBUF: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1241 | err = put_v4l2_buffer32(up_native, up); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1242 | break; |
| 1243 | |
| 1244 | case VIDIOC_ENUMSTD: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1245 | err = put_v4l2_standard32(up_native, up); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1246 | break; |
| 1247 | |
| 1248 | case VIDIOC_ENUMINPUT: |
Daniel Mentz | f2d4bed | 2018-02-14 12:48:30 +0100 | [diff] [blame] | 1249 | err = put_v4l2_input32(up_native, up); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1250 | break; |
| 1251 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1252 | return err; |
| 1253 | } |
| 1254 | |
Hans Verkuil | 9bb7cde | 2008-12-30 06:42:40 -0300 | [diff] [blame] | 1255 | 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] | 1256 | { |
Laurent Pinchart | b9d0aa6 | 2011-12-18 20:41:19 -0300 | [diff] [blame] | 1257 | struct video_device *vdev = video_devdata(file); |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 1258 | long ret = -ENOIOCTLCMD; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1259 | |
Frederic Weisbecker | c6d7ba8 | 2010-08-13 22:29:03 +0200 | [diff] [blame] | 1260 | if (!file->f_op->unlocked_ioctl) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1261 | return ret; |
| 1262 | |
Hans Verkuil | ab58a30 | 2014-02-10 08:08:44 -0300 | [diff] [blame] | 1263 | if (_IOC_TYPE(cmd) == 'V' && _IOC_NR(cmd) < BASE_VIDIOC_PRIVATE) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1264 | ret = do_video_ioctl(file, cmd, arg); |
Hans Verkuil | ab58a30 | 2014-02-10 08:08:44 -0300 | [diff] [blame] | 1265 | else if (vdev->fops->compat_ioctl32) |
| 1266 | ret = vdev->fops->compat_ioctl32(file, cmd, arg); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1267 | |
Hans Verkuil | ab58a30 | 2014-02-10 08:08:44 -0300 | [diff] [blame] | 1268 | if (ret == -ENOIOCTLCMD) |
Hans Verkuil | 9ec32cc | 2015-09-09 03:40:39 -0300 | [diff] [blame] | 1269 | pr_debug("compat_ioctl32: unknown ioctl '%c', dir=%d, #%d (0x%08x)\n", |
| 1270 | _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), cmd); |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1271 | return ret; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1272 | } |
Hans Verkuil | 9bb7cde | 2008-12-30 06:42:40 -0300 | [diff] [blame] | 1273 | EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32); |