Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'media/v4.6-4' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media

Pull media fixes from Mauro Carvalho Chehab:
"Some regression fixes:

- videobuf2 core: avoid the risk of going past buffer on multi-planes
and fix rw mode

- fix support for 4K formats at V4L2 core

- fix a trouble at davinci_fpe, caused by a bad patch

- usbvision: revert a patch with a partial fixup. The fixup patch
was merged already, and this one has some issues"

* tag 'media/v4.6-4' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media:
[media] vb2-memops: Fix over allocation of frame vectors
[media] media: vb2: Fix regression on poll() for RW mode
[media] v4l2-dv-timings.h: fix polarity for 4k formats
[media] davinci_vpfe: Revert "staging: media: davinci_vpfe: remove,unnecessary ret variable"
[media] usbvision: revert commit 588afcc1
[media] videobuf2-v4l2: Verify planes array in buffer dequeueing
[media] videobuf2-core: Check user space planes array in dqbuf

+90 -51
-7
drivers/media/usb/usbvision/usbvision-video.c
··· 1452 1452 printk(KERN_INFO "%s: %s found\n", __func__, 1453 1453 usbvision_device_data[model].model_string); 1454 1454 1455 - /* 1456 - * this is a security check. 1457 - * an exploit using an incorrect bInterfaceNumber is known 1458 - */ 1459 - if (ifnum >= USB_MAXINTERFACES || !dev->actconfig->interface[ifnum]) 1460 - return -ENODEV; 1461 - 1462 1455 if (usbvision_device_data[model].interface >= 0) 1463 1456 interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0]; 1464 1457 else if (ifnum < dev->actconfig->desc.bNumInterfaces)
+15 -5
drivers/media/v4l2-core/videobuf2-core.c
··· 1645 1645 * Will sleep if required for nonblocking == false. 1646 1646 */ 1647 1647 static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb, 1648 - int nonblocking) 1648 + void *pb, int nonblocking) 1649 1649 { 1650 1650 unsigned long flags; 1651 1651 int ret; ··· 1666 1666 /* 1667 1667 * Only remove the buffer from done_list if v4l2_buffer can handle all 1668 1668 * the planes. 1669 - * Verifying planes is NOT necessary since it already has been checked 1670 - * before the buffer is queued/prepared. So it can never fail. 1671 1669 */ 1672 - list_del(&(*vb)->done_entry); 1670 + ret = call_bufop(q, verify_planes_array, *vb, pb); 1671 + if (!ret) 1672 + list_del(&(*vb)->done_entry); 1673 1673 spin_unlock_irqrestore(&q->done_lock, flags); 1674 1674 1675 1675 return ret; ··· 1748 1748 struct vb2_buffer *vb = NULL; 1749 1749 int ret; 1750 1750 1751 - ret = __vb2_get_done_vb(q, &vb, nonblocking); 1751 + ret = __vb2_get_done_vb(q, &vb, pb, nonblocking); 1752 1752 if (ret < 0) 1753 1753 return ret; 1754 1754 ··· 2295 2295 * error flag is set. 2296 2296 */ 2297 2297 if (!vb2_is_streaming(q) || q->error) 2298 + return POLLERR; 2299 + 2300 + /* 2301 + * If this quirk is set and QBUF hasn't been called yet then 2302 + * return POLLERR as well. This only affects capture queues, output 2303 + * queues will always initialize waiting_for_buffers to false. 2304 + * This quirk is set by V4L2 for backwards compatibility reasons. 2305 + */ 2306 + if (q->quirk_poll_must_check_waiting_for_buffers && 2307 + q->waiting_for_buffers && (req_events & (POLLIN | POLLRDNORM))) 2298 2308 return POLLERR; 2299 2309 2300 2310 /*
+1 -1
drivers/media/v4l2-core/videobuf2-memops.c
··· 49 49 vec = frame_vector_create(nr); 50 50 if (!vec) 51 51 return ERR_PTR(-ENOMEM); 52 - ret = get_vaddr_frames(start, nr, write, 1, vec); 52 + ret = get_vaddr_frames(start & PAGE_MASK, nr, write, true, vec); 53 53 if (ret < 0) 54 54 goto out_destroy; 55 55 /* We accept only complete set of PFNs */
+12 -8
drivers/media/v4l2-core/videobuf2-v4l2.c
··· 74 74 return 0; 75 75 } 76 76 77 + static int __verify_planes_array_core(struct vb2_buffer *vb, const void *pb) 78 + { 79 + return __verify_planes_array(vb, pb); 80 + } 81 + 77 82 /** 78 83 * __verify_length() - Verify that the bytesused value for each plane fits in 79 84 * the plane length and that the data offset doesn't exceed the bytesused value. ··· 442 437 } 443 438 444 439 static const struct vb2_buf_ops v4l2_buf_ops = { 440 + .verify_planes_array = __verify_planes_array_core, 445 441 .fill_user_buffer = __fill_v4l2_buffer, 446 442 .fill_vb2_buffer = __fill_vb2_buffer, 447 443 .copy_timestamp = __copy_timestamp, ··· 771 765 q->is_output = V4L2_TYPE_IS_OUTPUT(q->type); 772 766 q->copy_timestamp = (q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) 773 767 == V4L2_BUF_FLAG_TIMESTAMP_COPY; 768 + /* 769 + * For compatibility with vb1: if QBUF hasn't been called yet, then 770 + * return POLLERR as well. This only affects capture queues, output 771 + * queues will always initialize waiting_for_buffers to false. 772 + */ 773 + q->quirk_poll_must_check_waiting_for_buffers = true; 774 774 775 775 return vb2_core_queue_init(q); 776 776 } ··· 829 817 else if (req_events & POLLPRI) 830 818 poll_wait(file, &fh->wait, wait); 831 819 } 832 - 833 - /* 834 - * For compatibility with vb1: if QBUF hasn't been called yet, then 835 - * return POLLERR as well. This only affects capture queues, output 836 - * queues will always initialize waiting_for_buffers to false. 837 - */ 838 - if (q->waiting_for_buffers && (req_events & (POLLIN | POLLRDNORM))) 839 - return POLLERR; 840 820 841 821 return res | vb2_core_poll(q, file, wait); 842 822 }
+34 -20
drivers/staging/media/davinci_vpfe/vpfe_video.c
··· 172 172 static int vpfe_update_pipe_state(struct vpfe_video_device *video) 173 173 { 174 174 struct vpfe_pipeline *pipe = &video->pipe; 175 + int ret; 175 176 176 - if (vpfe_prepare_pipeline(video)) 177 - return vpfe_prepare_pipeline(video); 177 + ret = vpfe_prepare_pipeline(video); 178 + if (ret) 179 + return ret; 178 180 179 181 /* 180 182 * Find out if there is any input video ··· 184 182 */ 185 183 if (pipe->input_num == 0) { 186 184 pipe->state = VPFE_PIPELINE_STREAM_CONTINUOUS; 187 - if (vpfe_update_current_ext_subdev(video)) { 185 + ret = vpfe_update_current_ext_subdev(video); 186 + if (ret) { 188 187 pr_err("Invalid external subdev\n"); 189 - return vpfe_update_current_ext_subdev(video); 188 + return ret; 190 189 } 191 190 } else { 192 191 pipe->state = VPFE_PIPELINE_STREAM_SINGLESHOT; ··· 670 667 struct v4l2_subdev *subdev; 671 668 struct v4l2_format format; 672 669 struct media_pad *remote; 670 + int ret; 673 671 674 672 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_enum_fmt\n"); 675 673 ··· 699 695 sd_fmt.pad = remote->index; 700 696 sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; 701 697 /* get output format of remote subdev */ 702 - if (v4l2_subdev_call(subdev, pad, get_fmt, NULL, &sd_fmt)) { 698 + ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &sd_fmt); 699 + if (ret) { 703 700 v4l2_err(&vpfe_dev->v4l2_dev, 704 701 "invalid remote subdev for video node\n"); 705 - return v4l2_subdev_call(subdev, pad, get_fmt, NULL, &sd_fmt); 702 + return ret; 706 703 } 707 704 /* convert to pix format */ 708 705 mbus.code = sd_fmt.format.code; ··· 730 725 struct vpfe_video_device *video = video_drvdata(file); 731 726 struct vpfe_device *vpfe_dev = video->vpfe_dev; 732 727 struct v4l2_format format; 728 + int ret; 733 729 734 730 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_fmt\n"); 735 731 /* If streaming is started, return error */ ··· 739 733 return -EBUSY; 740 734 } 741 735 /* get adjacent subdev's output pad format */ 742 - if (__vpfe_video_get_format(video, &format)) 743 - return __vpfe_video_get_format(video, &format); 736 + ret = __vpfe_video_get_format(video, &format); 737 + if (ret) 738 + return ret; 744 739 *fmt = format; 745 740 video->fmt = *fmt; 746 741 return 0; ··· 764 757 struct vpfe_video_device *video = video_drvdata(file); 765 758 struct vpfe_device *vpfe_dev = video->vpfe_dev; 766 759 struct v4l2_format format; 760 + int ret; 767 761 768 762 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_try_fmt\n"); 769 763 /* get adjacent subdev's output pad format */ 770 - if (__vpfe_video_get_format(video, &format)) 771 - return __vpfe_video_get_format(video, &format); 764 + ret = __vpfe_video_get_format(video, &format); 765 + if (ret) 766 + return ret; 772 767 773 768 *fmt = format; 774 769 return 0; ··· 847 838 848 839 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_input\n"); 849 840 850 - if (mutex_lock_interruptible(&video->lock)) 851 - return mutex_lock_interruptible(&video->lock); 841 + ret = mutex_lock_interruptible(&video->lock); 842 + if (ret) 843 + return ret; 852 844 /* 853 845 * If streaming is started return device busy 854 846 * error ··· 950 940 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_std\n"); 951 941 952 942 /* Call decoder driver function to set the standard */ 953 - if (mutex_lock_interruptible(&video->lock)) 954 - return mutex_lock_interruptible(&video->lock); 943 + ret = mutex_lock_interruptible(&video->lock); 944 + if (ret) 945 + return ret; 955 946 sdinfo = video->current_ext_subdev; 956 947 /* If streaming is started, return device busy error */ 957 948 if (video->started) { ··· 1338 1327 return -EINVAL; 1339 1328 } 1340 1329 1341 - if (mutex_lock_interruptible(&video->lock)) 1342 - return mutex_lock_interruptible(&video->lock); 1330 + ret = mutex_lock_interruptible(&video->lock); 1331 + if (ret) 1332 + return ret; 1343 1333 1344 1334 if (video->io_usrs != 0) { 1345 1335 v4l2_err(&vpfe_dev->v4l2_dev, "Only one IO user allowed\n"); ··· 1366 1354 q->buf_struct_size = sizeof(struct vpfe_cap_buffer); 1367 1355 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1368 1356 1369 - if (vb2_queue_init(q)) { 1357 + ret = vb2_queue_init(q); 1358 + if (ret) { 1370 1359 v4l2_err(&vpfe_dev->v4l2_dev, "vb2_queue_init() failed\n"); 1371 1360 vb2_dma_contig_cleanup_ctx(vpfe_dev->pdev); 1372 - return vb2_queue_init(q); 1361 + return ret; 1373 1362 } 1374 1363 1375 1364 fh->io_allowed = 1; ··· 1546 1533 return -EINVAL; 1547 1534 } 1548 1535 1549 - if (mutex_lock_interruptible(&video->lock)) 1550 - return mutex_lock_interruptible(&video->lock); 1536 + ret = mutex_lock_interruptible(&video->lock); 1537 + if (ret) 1538 + return ret; 1551 1539 1552 1540 vpfe_stop_capture(video); 1553 1541 ret = vb2_streamoff(&video->buffer_queue, buf_type);
+8
include/media/videobuf2-core.h
··· 375 375 /** 376 376 * struct vb2_ops - driver-specific callbacks 377 377 * 378 + * @verify_planes_array: Verify that a given user space structure contains 379 + * enough planes for the buffer. This is called 380 + * for each dequeued buffer. 378 381 * @fill_user_buffer: given a vb2_buffer fill in the userspace structure. 379 382 * For V4L2 this is a struct v4l2_buffer. 380 383 * @fill_vb2_buffer: given a userspace structure, fill in the vb2_buffer. ··· 387 384 * the vb2_buffer struct. 388 385 */ 389 386 struct vb2_buf_ops { 387 + int (*verify_planes_array)(struct vb2_buffer *vb, const void *pb); 390 388 void (*fill_user_buffer)(struct vb2_buffer *vb, void *pb); 391 389 int (*fill_vb2_buffer)(struct vb2_buffer *vb, const void *pb, 392 390 struct vb2_plane *planes); ··· 404 400 * @fileio_read_once: report EOF after reading the first buffer 405 401 * @fileio_write_immediately: queue buffer after each write() call 406 402 * @allow_zero_bytesused: allow bytesused == 0 to be passed to the driver 403 + * @quirk_poll_must_check_waiting_for_buffers: Return POLLERR at poll when QBUF 404 + * has not been called. This is a vb1 idiom that has been adopted 405 + * also by vb2. 407 406 * @lock: pointer to a mutex that protects the vb2_queue struct. The 408 407 * driver can set this to a mutex to let the v4l2 core serialize 409 408 * the queuing ioctls. If the driver wants to handle locking ··· 470 463 unsigned fileio_read_once:1; 471 464 unsigned fileio_write_immediately:1; 472 465 unsigned allow_zero_bytesused:1; 466 + unsigned quirk_poll_must_check_waiting_for_buffers:1; 473 467 474 468 struct mutex *lock; 475 469 void *owner;
+20 -10
include/uapi/linux/v4l2-dv-timings.h
··· 183 183 184 184 #define V4L2_DV_BT_CEA_3840X2160P24 { \ 185 185 .type = V4L2_DV_BT_656_1120, \ 186 - V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 186 + V4L2_INIT_BT_TIMINGS(3840, 2160, 0, \ 187 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 187 188 297000000, 1276, 88, 296, 8, 10, 72, 0, 0, 0, \ 188 189 V4L2_DV_BT_STD_CEA861, \ 189 190 V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \ ··· 192 191 193 192 #define V4L2_DV_BT_CEA_3840X2160P25 { \ 194 193 .type = V4L2_DV_BT_656_1120, \ 195 - V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 194 + V4L2_INIT_BT_TIMINGS(3840, 2160, 0, \ 195 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 196 196 297000000, 1056, 88, 296, 8, 10, 72, 0, 0, 0, \ 197 197 V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \ 198 198 } 199 199 200 200 #define V4L2_DV_BT_CEA_3840X2160P30 { \ 201 201 .type = V4L2_DV_BT_656_1120, \ 202 - V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 202 + V4L2_INIT_BT_TIMINGS(3840, 2160, 0, \ 203 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 203 204 297000000, 176, 88, 296, 8, 10, 72, 0, 0, 0, \ 204 205 V4L2_DV_BT_STD_CEA861, \ 205 206 V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \ ··· 209 206 210 207 #define V4L2_DV_BT_CEA_3840X2160P50 { \ 211 208 .type = V4L2_DV_BT_656_1120, \ 212 - V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 209 + V4L2_INIT_BT_TIMINGS(3840, 2160, 0, \ 210 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 213 211 594000000, 1056, 88, 296, 8, 10, 72, 0, 0, 0, \ 214 212 V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \ 215 213 } 216 214 217 215 #define V4L2_DV_BT_CEA_3840X2160P60 { \ 218 216 .type = V4L2_DV_BT_656_1120, \ 219 - V4L2_INIT_BT_TIMINGS(3840, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 217 + V4L2_INIT_BT_TIMINGS(3840, 2160, 0, \ 218 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 220 219 594000000, 176, 88, 296, 8, 10, 72, 0, 0, 0, \ 221 220 V4L2_DV_BT_STD_CEA861, \ 222 221 V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \ ··· 226 221 227 222 #define V4L2_DV_BT_CEA_4096X2160P24 { \ 228 223 .type = V4L2_DV_BT_656_1120, \ 229 - V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 224 + V4L2_INIT_BT_TIMINGS(4096, 2160, 0, \ 225 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 230 226 297000000, 1020, 88, 296, 8, 10, 72, 0, 0, 0, \ 231 227 V4L2_DV_BT_STD_CEA861, \ 232 228 V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \ ··· 235 229 236 230 #define V4L2_DV_BT_CEA_4096X2160P25 { \ 237 231 .type = V4L2_DV_BT_656_1120, \ 238 - V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 232 + V4L2_INIT_BT_TIMINGS(4096, 2160, 0, \ 233 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 239 234 297000000, 968, 88, 128, 8, 10, 72, 0, 0, 0, \ 240 235 V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \ 241 236 } 242 237 243 238 #define V4L2_DV_BT_CEA_4096X2160P30 { \ 244 239 .type = V4L2_DV_BT_656_1120, \ 245 - V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 240 + V4L2_INIT_BT_TIMINGS(4096, 2160, 0, \ 241 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 246 242 297000000, 88, 88, 128, 8, 10, 72, 0, 0, 0, \ 247 243 V4L2_DV_BT_STD_CEA861, \ 248 244 V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \ ··· 252 244 253 245 #define V4L2_DV_BT_CEA_4096X2160P50 { \ 254 246 .type = V4L2_DV_BT_656_1120, \ 255 - V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 247 + V4L2_INIT_BT_TIMINGS(4096, 2160, 0, \ 248 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 256 249 594000000, 968, 88, 128, 8, 10, 72, 0, 0, 0, \ 257 250 V4L2_DV_BT_STD_CEA861, V4L2_DV_FL_IS_CE_VIDEO) \ 258 251 } 259 252 260 253 #define V4L2_DV_BT_CEA_4096X2160P60 { \ 261 254 .type = V4L2_DV_BT_656_1120, \ 262 - V4L2_INIT_BT_TIMINGS(4096, 2160, 0, V4L2_DV_HSYNC_POS_POL, \ 255 + V4L2_INIT_BT_TIMINGS(4096, 2160, 0, \ 256 + V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \ 263 257 594000000, 88, 88, 128, 8, 10, 72, 0, 0, 0, \ 264 258 V4L2_DV_BT_STD_CEA861, \ 265 259 V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO) \