diff options
author | Andy Lutomirski <luto@kernel.org> | 2016-05-11 20:41:27 -0400 |
---|---|---|
committer | Andy Lutomirski <luto@kernel.org> | 2016-06-10 18:11:15 -0400 |
commit | f89dec72e98b34b3be66bb1ef1be62974c0f8483 (patch) | |
tree | 17f7de7eadc9d92ee591c7f9b58bb44f4b05a88c | |
parent | a44323e2a8f342848bb77e8e04fcd85fcb91b3b4 (diff) |
uvc_v4l2: Simplify compat ioctl implementation
The uvc compat ioctl implementation seems to have copied user data
for no good reason. Remove a bunch of copies.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
-rw-r--r-- | drivers/media/usb/uvc/uvc_v4l2.c | 58 |
1 files changed, 2 insertions, 56 deletions
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 12690c1ea8f8..c04bc6afb965 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c | |||
@@ -1274,8 +1274,6 @@ struct uvc_xu_control_mapping32 { | |||
1274 | static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp, | 1274 | static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp, |
1275 | const struct uvc_xu_control_mapping32 __user *up) | 1275 | const struct uvc_xu_control_mapping32 __user *up) |
1276 | { | 1276 | { |
1277 | struct uvc_menu_info __user *umenus; | ||
1278 | struct uvc_menu_info __user *kmenus; | ||
1279 | compat_caddr_t p; | 1277 | compat_caddr_t p; |
1280 | 1278 | ||
1281 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || | 1279 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
@@ -1292,17 +1290,7 @@ static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp, | |||
1292 | 1290 | ||
1293 | if (__get_user(p, &up->menu_info)) | 1291 | if (__get_user(p, &up->menu_info)) |
1294 | return -EFAULT; | 1292 | return -EFAULT; |
1295 | umenus = compat_ptr(p); | 1293 | kp->menu_info = compat_ptr(p); |
1296 | if (!access_ok(VERIFY_READ, umenus, kp->menu_count * sizeof(*umenus))) | ||
1297 | return -EFAULT; | ||
1298 | |||
1299 | kmenus = compat_alloc_user_space(kp->menu_count * sizeof(*kmenus)); | ||
1300 | if (kmenus == NULL) | ||
1301 | return -EFAULT; | ||
1302 | kp->menu_info = kmenus; | ||
1303 | |||
1304 | if (copy_in_user(kmenus, umenus, kp->menu_count * sizeof(*umenus))) | ||
1305 | return -EFAULT; | ||
1306 | 1294 | ||
1307 | return 0; | 1295 | return 0; |
1308 | } | 1296 | } |
@@ -1310,10 +1298,6 @@ static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp, | |||
1310 | static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp, | 1298 | static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp, |
1311 | struct uvc_xu_control_mapping32 __user *up) | 1299 | struct uvc_xu_control_mapping32 __user *up) |
1312 | { | 1300 | { |
1313 | struct uvc_menu_info __user *umenus; | ||
1314 | struct uvc_menu_info __user *kmenus = kp->menu_info; | ||
1315 | compat_caddr_t p; | ||
1316 | |||
1317 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || | 1301 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
1318 | __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) || | 1302 | __copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) || |
1319 | __put_user(kp->menu_count, &up->menu_count)) | 1303 | __put_user(kp->menu_count, &up->menu_count)) |
@@ -1322,16 +1306,6 @@ static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp, | |||
1322 | if (__clear_user(up->reserved, sizeof(up->reserved))) | 1306 | if (__clear_user(up->reserved, sizeof(up->reserved))) |
1323 | return -EFAULT; | 1307 | return -EFAULT; |
1324 | 1308 | ||
1325 | if (kp->menu_count == 0) | ||
1326 | return 0; | ||
1327 | |||
1328 | if (get_user(p, &up->menu_info)) | ||
1329 | return -EFAULT; | ||
1330 | umenus = compat_ptr(p); | ||
1331 | |||
1332 | if (copy_in_user(umenus, kmenus, kp->menu_count * sizeof(*umenus))) | ||
1333 | return -EFAULT; | ||
1334 | |||
1335 | return 0; | 1309 | return 0; |
1336 | } | 1310 | } |
1337 | 1311 | ||
@@ -1346,8 +1320,6 @@ struct uvc_xu_control_query32 { | |||
1346 | static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp, | 1320 | static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp, |
1347 | const struct uvc_xu_control_query32 __user *up) | 1321 | const struct uvc_xu_control_query32 __user *up) |
1348 | { | 1322 | { |
1349 | u8 __user *udata; | ||
1350 | u8 __user *kdata; | ||
1351 | compat_caddr_t p; | 1323 | compat_caddr_t p; |
1352 | 1324 | ||
1353 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || | 1325 | if (!access_ok(VERIFY_READ, up, sizeof(*up)) || |
@@ -1361,17 +1333,7 @@ static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp, | |||
1361 | 1333 | ||
1362 | if (__get_user(p, &up->data)) | 1334 | if (__get_user(p, &up->data)) |
1363 | return -EFAULT; | 1335 | return -EFAULT; |
1364 | udata = compat_ptr(p); | 1336 | kp->data = compat_ptr(p); |
1365 | if (!access_ok(VERIFY_READ, udata, kp->size)) | ||
1366 | return -EFAULT; | ||
1367 | |||
1368 | kdata = compat_alloc_user_space(kp->size); | ||
1369 | if (kdata == NULL) | ||
1370 | return -EFAULT; | ||
1371 | kp->data = kdata; | ||
1372 | |||
1373 | if (copy_in_user(kdata, udata, kp->size)) | ||
1374 | return -EFAULT; | ||
1375 | 1337 | ||
1376 | return 0; | 1338 | return 0; |
1377 | } | 1339 | } |
@@ -1379,26 +1341,10 @@ static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp, | |||
1379 | static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp, | 1341 | static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp, |
1380 | struct uvc_xu_control_query32 __user *up) | 1342 | struct uvc_xu_control_query32 __user *up) |
1381 | { | 1343 | { |
1382 | u8 __user *udata; | ||
1383 | u8 __user *kdata = kp->data; | ||
1384 | compat_caddr_t p; | ||
1385 | |||
1386 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || | 1344 | if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || |
1387 | __copy_to_user(up, kp, offsetof(typeof(*up), data))) | 1345 | __copy_to_user(up, kp, offsetof(typeof(*up), data))) |
1388 | return -EFAULT; | 1346 | return -EFAULT; |
1389 | 1347 | ||
1390 | if (kp->size == 0) | ||
1391 | return 0; | ||
1392 | |||
1393 | if (get_user(p, &up->data)) | ||
1394 | return -EFAULT; | ||
1395 | udata = compat_ptr(p); | ||
1396 | if (!access_ok(VERIFY_READ, udata, kp->size)) | ||
1397 | return -EFAULT; | ||
1398 | |||
1399 | if (copy_in_user(udata, kdata, kp->size)) | ||
1400 | return -EFAULT; | ||
1401 | |||
1402 | return 0; | 1348 | return 0; |
1403 | } | 1349 | } |
1404 | 1350 | ||