Commit eb55a2a95d65d6701375c719e2ce2cc8721f902b

Authored by Linus Torvalds

Merge tag 'media/v3.17-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media

Pull media fixes from Mauro Carvalho Chehab:
 "For some last time fixes:
   - a regression detected on Kernel 3.16 related to VBI Teletext
     application breakage on drivers using videobuf2 (see
     https://bugzilla.kernel.org/show_bug.cgi?id=84401).  The bug was
     noticed on saa7134 (migrated to VB2 on 3.16), but also affects
     em28xx (migrated on 3.9 to VB2);
   - two additional sanity checks at videobuf2;
   - two fixups to restore proper VBI support at the em28xx driver;
   - two Kernel oops fixups (at cx24123 and cx2341x drivers);
   - a bug at adv7604 where an if was doing just the opposite as it
     would be expected;
   - some documentation fixups to match the behavior defined at the
     Kernel"

* tag 'media/v3.17-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media:
  [media] em28xx-v4l: get rid of field "users" in struct em28xx_v4l2"
  [media] em28xx: fix VBI handling logic
  [media] DocBook media: improve the poll() documentation
  [media] DocBook media: fix the poll() 'no QBUF' documentation
  [media] vb2: fix VBI/poll regression
  [media] cx2341x: fix kernel oops
  [media] cx24123: fix kernel oops due to missing parent pointer
  [media] adv7604: fix inverted condition
  [media] media/radio: fix radio-miropcm20.c build with io.h header file
  [media] vb2: fix plane index sanity check in vb2_plane_cookie()
  [media] DocBook media: update version number and V4L2 changes
  [media] DocBook media: fix fieldname in struct v4l2_subdev_selection
  [media] vb2: fix vb2 state check when start_streaming fails
  [media] videobuf2-core.h: fix comment
  [media] videobuf2-core: add comments before the WARN_ON
  [media] videobuf2-dma-sg: fix for wrong GFP mask to sg_alloc_table_from_pages

Showing 13 changed files Side-by-side Diff

Documentation/DocBook/media/v4l/compat.xml
... ... @@ -2545,6 +2545,30 @@
2545 2545 </orderedlist>
2546 2546 </section>
2547 2547  
  2548 + <section>
  2549 + <title>V4L2 in Linux 3.16</title>
  2550 + <orderedlist>
  2551 + <listitem>
  2552 + <para>Added event V4L2_EVENT_SOURCE_CHANGE.
  2553 + </para>
  2554 + </listitem>
  2555 + </orderedlist>
  2556 + </section>
  2557 +
  2558 + <section>
  2559 + <title>V4L2 in Linux 3.17</title>
  2560 + <orderedlist>
  2561 + <listitem>
  2562 + <para>Extended &v4l2-pix-format;. Added format flags.
  2563 + </para>
  2564 + </listitem>
  2565 + <listitem>
  2566 + <para>Added compound control types and &VIDIOC-QUERY-EXT-CTRL;.
  2567 + </para>
  2568 + </listitem>
  2569 + </orderedlist>
  2570 + </section>
  2571 +
2548 2572 <section id="other">
2549 2573 <title>Relation of V4L2 to other Linux multimedia APIs</title>
2550 2574  
Documentation/DocBook/media/v4l/func-poll.xml
... ... @@ -29,9 +29,12 @@
29 29 to accept data for output.</para>
30 30  
31 31 <para>When streaming I/O has been negotiated this function waits
32   -until a buffer has been filled or displayed and can be dequeued with
33   -the &VIDIOC-DQBUF; ioctl. When buffers are already in the outgoing
34   -queue of the driver the function returns immediately.</para>
  32 +until a buffer has been filled by the capture device and can be dequeued
  33 +with the &VIDIOC-DQBUF; ioctl. For output devices this function waits
  34 +until the device is ready to accept a new buffer to be queued up with
  35 +the &VIDIOC-QBUF; ioctl for display. When buffers are already in the outgoing
  36 +queue of the driver (capture) or the incoming queue isn't full (display)
  37 +the function returns immediately.</para>
35 38  
36 39 <para>On success <function>poll()</function> returns the number of
37 40 file descriptors that have been selected (that is, file descriptors
38 41  
39 42  
... ... @@ -44,11 +47,23 @@
44 47 flags. When the function timed out it returns a value of zero, on
45 48 failure it returns <returnvalue>-1</returnvalue> and the
46 49 <varname>errno</varname> variable is set appropriately. When the
47   -application did not call &VIDIOC-QBUF; or &VIDIOC-STREAMON; yet the
  50 +application did not call &VIDIOC-STREAMON; the
48 51 <function>poll()</function> function succeeds, but sets the
49 52 <constant>POLLERR</constant> flag in the
50   -<structfield>revents</structfield> field.</para>
  53 +<structfield>revents</structfield> field. When the
  54 +application has called &VIDIOC-STREAMON; for a capture device but hasn't
  55 +yet called &VIDIOC-QBUF;, the <function>poll()</function> function
  56 +succeeds and sets the <constant>POLLERR</constant> flag in the
  57 +<structfield>revents</structfield> field. For output devices this
  58 +same situation will cause <function>poll()</function> to succeed
  59 +as well, but it sets the <constant>POLLOUT</constant> and
  60 +<constant>POLLWRNORM</constant> flags in the <structfield>revents</structfield>
  61 +field.</para>
51 62  
  63 + <para>If an event occurred (see &VIDIOC-DQEVENT;) then
  64 +<constant>POLLPRI</constant> will be set in the <structfield>revents</structfield>
  65 +field and <function>poll()</function> will return.</para>
  66 +
52 67 <para>When use of the <function>read()</function> function has
53 68 been negotiated and the driver does not capture yet, the
54 69 <function>poll</function> function starts capturing. When that fails
55 70  
... ... @@ -58,9 +73,17 @@
58 73 may return immediately.</para>
59 74  
60 75 <para>When use of the <function>write()</function> function has
61   -been negotiated the <function>poll</function> function just waits
  76 +been negotiated and the driver does not stream yet, the
  77 +<function>poll</function> function starts streaming. When that fails
  78 +it returns a <constant>POLLERR</constant> as above. Otherwise it waits
62 79 until the driver is ready for a non-blocking
63 80 <function>write()</function> call.</para>
  81 +
  82 + <para>If the caller is only interested in events (just
  83 +<constant>POLLPRI</constant> is set in the <structfield>events</structfield>
  84 +field), then <function>poll()</function> will <emphasis>not</emphasis>
  85 +start streaming if the driver does not stream yet. This makes it
  86 +possible to just poll for events and not for buffers.</para>
64 87  
65 88 <para>All drivers implementing the <function>read()</function> or
66 89 <function>write()</function> function or streaming I/O must also
Documentation/DocBook/media/v4l/v4l2.xml
... ... @@ -152,10 +152,11 @@
152 152 applications. -->
153 153  
154 154 <revision>
155   - <revnumber>3.16</revnumber>
156   - <date>2014-05-27</date>
157   - <authorinitials>lp</authorinitials>
158   - <revremark>Extended &v4l2-pix-format;. Added format flags.
  155 + <revnumber>3.17</revnumber>
  156 + <date>2014-08-04</date>
  157 + <authorinitials>lp, hv</authorinitials>
  158 + <revremark>Extended &v4l2-pix-format;. Added format flags. Added compound control types
  159 +and VIDIOC_QUERY_EXT_CTRL.
159 160 </revremark>
160 161 </revision>
161 162  
... ... @@ -538,7 +539,7 @@
538 539 </partinfo>
539 540  
540 541 <title>Video for Linux Two API Specification</title>
541   - <subtitle>Revision 3.14</subtitle>
  542 + <subtitle>Revision 3.17</subtitle>
542 543  
543 544 <chapter id="common">
544 545 &sub-common;
Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
... ... @@ -119,7 +119,7 @@
119 119 </row>
120 120 <row>
121 121 <entry>&v4l2-rect;</entry>
122   - <entry><structfield>rect</structfield></entry>
  122 + <entry><structfield>r</structfield></entry>
123 123 <entry>Selection rectangle, in pixels.</entry>
124 124 </row>
125 125 <row>
drivers/media/common/cx2341x.c
... ... @@ -1490,6 +1490,7 @@
1490 1490 {
1491 1491 struct v4l2_ctrl_config cfg;
1492 1492  
  1493 + memset(&cfg, 0, sizeof(cfg));
1493 1494 cx2341x_ctrl_fill(id, &cfg.name, &cfg.type, &min, &max, &step, &def, &cfg.flags);
1494 1495 cfg.ops = &cx2341x_ops;
1495 1496 cfg.id = id;
drivers/media/dvb-frontends/cx24123.c
... ... @@ -1095,6 +1095,7 @@
1095 1095 sizeof(state->tuner_i2c_adapter.name));
1096 1096 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo;
1097 1097 state->tuner_i2c_adapter.algo_data = NULL;
  1098 + state->tuner_i2c_adapter.dev.parent = i2c->dev.parent;
1098 1099 i2c_set_adapdata(&state->tuner_i2c_adapter, state);
1099 1100 if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) {
1100 1101 err("tuner i2c bus could not be initialized\n");
drivers/media/i2c/adv7604.c
... ... @@ -2325,7 +2325,7 @@
2325 2325 v4l2_info(sd, "HDCP keys read: %s%s\n",
2326 2326 (hdmi_read(sd, 0x04) & 0x20) ? "yes" : "no",
2327 2327 (hdmi_read(sd, 0x04) & 0x10) ? "ERROR" : "");
2328   - if (!is_hdmi(sd)) {
  2328 + if (is_hdmi(sd)) {
2329 2329 bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01;
2330 2330 bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01;
2331 2331 bool audio_mute = io_read(sd, 0x65) & 0x40;
drivers/media/radio/radio-miropcm20.c
... ... @@ -27,6 +27,7 @@
27 27  
28 28 #include <linux/module.h>
29 29 #include <linux/init.h>
  30 +#include <linux/io.h>
30 31 #include <linux/delay.h>
31 32 #include <linux/videodev2.h>
32 33 #include <linux/kthread.h>
drivers/media/usb/em28xx/em28xx-video.c
... ... @@ -1342,7 +1342,7 @@
1342 1342 struct em28xx *dev = video_drvdata(file);
1343 1343 struct em28xx_v4l2 *v4l2 = dev->v4l2;
1344 1344  
1345   - if (v4l2->streaming_users > 0)
  1345 + if (vb2_is_busy(&v4l2->vb_vidq))
1346 1346 return -EBUSY;
1347 1347  
1348 1348 vidioc_try_fmt_vid_cap(file, priv, f);
... ... @@ -1883,8 +1883,9 @@
1883 1883 return -EINVAL;
1884 1884 }
1885 1885  
1886   - em28xx_videodbg("open dev=%s type=%s\n",
1887   - video_device_node_name(vdev), v4l2_type_names[fh_type]);
  1886 + em28xx_videodbg("open dev=%s type=%s users=%d\n",
  1887 + video_device_node_name(vdev), v4l2_type_names[fh_type],
  1888 + v4l2->users);
1888 1889  
1889 1890 if (mutex_lock_interruptible(&dev->lock))
1890 1891 return -ERESTARTSYS;
... ... @@ -1897,9 +1898,7 @@
1897 1898 return ret;
1898 1899 }
1899 1900  
1900   - if (v4l2_fh_is_singular_file(filp)) {
1901   - em28xx_videodbg("first opened filehandle, initializing device\n");
1902   -
  1901 + if (v4l2->users == 0) {
1903 1902 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
1904 1903  
1905 1904 if (vdev->vfl_type != VFL_TYPE_RADIO)
... ... @@ -1910,8 +1909,6 @@
1910 1909 * of some i2c devices
1911 1910 */
1912 1911 em28xx_wake_i2c(dev);
1913   - } else {
1914   - em28xx_videodbg("further filehandles are already opened\n");
1915 1912 }
1916 1913  
1917 1914 if (vdev->vfl_type == VFL_TYPE_RADIO) {
... ... @@ -1921,6 +1918,7 @@
1921 1918  
1922 1919 kref_get(&dev->ref);
1923 1920 kref_get(&v4l2->ref);
  1921 + v4l2->users++;
1924 1922  
1925 1923 mutex_unlock(&dev->lock);
1926 1924  
1927 1925  
... ... @@ -2027,11 +2025,12 @@
2027 2025 struct em28xx_v4l2 *v4l2 = dev->v4l2;
2028 2026 int errCode;
2029 2027  
  2028 + em28xx_videodbg("users=%d\n", v4l2->users);
  2029 +
  2030 + vb2_fop_release(filp);
2030 2031 mutex_lock(&dev->lock);
2031 2032  
2032   - if (v4l2_fh_is_singular_file(filp)) {
2033   - em28xx_videodbg("last opened filehandle, shutting down device\n");
2034   -
  2033 + if (v4l2->users == 1) {
2035 2034 /* No sense to try to write to the device */
2036 2035 if (dev->disconnected)
2037 2036 goto exit;
2038 2037  
... ... @@ -2050,12 +2049,10 @@
2050 2049 em28xx_errdev("cannot change alternate number to "
2051 2050 "0 (error=%i)\n", errCode);
2052 2051 }
2053   - } else {
2054   - em28xx_videodbg("further opened filehandles left\n");
2055 2052 }
2056 2053  
2057 2054 exit:
2058   - vb2_fop_release(filp);
  2055 + v4l2->users--;
2059 2056 kref_put(&v4l2->ref, em28xx_free_v4l2);
2060 2057 mutex_unlock(&dev->lock);
2061 2058 kref_put(&dev->ref, em28xx_free_device);
drivers/media/usb/em28xx/em28xx.h
... ... @@ -524,6 +524,7 @@
524 524 int sensor_yres;
525 525 int sensor_xtal;
526 526  
  527 + int users; /* user count for exclusive use */
527 528 int streaming_users; /* number of actively streaming users */
528 529  
529 530 u32 frequency; /* selected tuner frequency */
drivers/media/v4l2-core/videobuf2-core.c
... ... @@ -971,6 +971,7 @@
971 971 * to the userspace.
972 972 */
973 973 req->count = allocated_buffers;
  974 + q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
974 975  
975 976 return 0;
976 977 }
... ... @@ -1018,6 +1019,7 @@
1018 1019 memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
1019 1020 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
1020 1021 q->memory = create->memory;
  1022 + q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
1021 1023 }
1022 1024  
1023 1025 num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers);
... ... @@ -1130,7 +1132,7 @@
1130 1132 */
1131 1133 void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no)
1132 1134 {
1133   - if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
  1135 + if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
1134 1136 return NULL;
1135 1137  
1136 1138 return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
... ... @@ -1165,13 +1167,10 @@
1165 1167 if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
1166 1168 return;
1167 1169  
1168   - if (!q->start_streaming_called) {
1169   - if (WARN_ON(state != VB2_BUF_STATE_QUEUED))
1170   - state = VB2_BUF_STATE_QUEUED;
1171   - } else if (WARN_ON(state != VB2_BUF_STATE_DONE &&
1172   - state != VB2_BUF_STATE_ERROR)) {
1173   - state = VB2_BUF_STATE_ERROR;
1174   - }
  1170 + if (WARN_ON(state != VB2_BUF_STATE_DONE &&
  1171 + state != VB2_BUF_STATE_ERROR &&
  1172 + state != VB2_BUF_STATE_QUEUED))
  1173 + state = VB2_BUF_STATE_ERROR;
1175 1174  
1176 1175 #ifdef CONFIG_VIDEO_ADV_DEBUG
1177 1176 /*
... ... @@ -1762,6 +1761,12 @@
1762 1761 q->start_streaming_called = 0;
1763 1762  
1764 1763 dprintk(1, "driver refused to start streaming\n");
  1764 + /*
  1765 + * If you see this warning, then the driver isn't cleaning up properly
  1766 + * after a failed start_streaming(). See the start_streaming()
  1767 + * documentation in videobuf2-core.h for more information how buffers
  1768 + * should be returned to vb2 in start_streaming().
  1769 + */
1765 1770 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
1766 1771 unsigned i;
1767 1772  
... ... @@ -1777,6 +1782,12 @@
1777 1782 /* Must be zero now */
1778 1783 WARN_ON(atomic_read(&q->owned_by_drv_count));
1779 1784 }
  1785 + /*
  1786 + * If done_list is not empty, then start_streaming() didn't call
  1787 + * vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED) but STATE_ERROR or
  1788 + * STATE_DONE.
  1789 + */
  1790 + WARN_ON(!list_empty(&q->done_list));
1780 1791 return ret;
1781 1792 }
1782 1793  
... ... @@ -1812,6 +1823,7 @@
1812 1823 */
1813 1824 list_add_tail(&vb->queued_entry, &q->queued_list);
1814 1825 q->queued_count++;
  1826 + q->waiting_for_buffers = false;
1815 1827 vb->state = VB2_BUF_STATE_QUEUED;
1816 1828 if (V4L2_TYPE_IS_OUTPUT(q->type)) {
1817 1829 /*
... ... @@ -2123,6 +2135,12 @@
2123 2135 if (q->start_streaming_called)
2124 2136 call_void_qop(q, stop_streaming, q);
2125 2137  
  2138 + /*
  2139 + * If you see this warning, then the driver isn't cleaning up properly
  2140 + * in stop_streaming(). See the stop_streaming() documentation in
  2141 + * videobuf2-core.h for more information how buffers should be returned
  2142 + * to vb2 in stop_streaming().
  2143 + */
2126 2144 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
2127 2145 for (i = 0; i < q->num_buffers; ++i)
2128 2146 if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE)
... ... @@ -2272,6 +2290,7 @@
2272 2290 * their normal dequeued state.
2273 2291 */
2274 2292 __vb2_queue_cancel(q);
  2293 + q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
2275 2294  
2276 2295 dprintk(3, "successful\n");
2277 2296 return 0;
2278 2297  
... ... @@ -2590,10 +2609,17 @@
2590 2609 }
2591 2610  
2592 2611 /*
2593   - * There is nothing to wait for if no buffer has been queued and the
2594   - * queue isn't streaming, or if the error flag is set.
  2612 + * There is nothing to wait for if the queue isn't streaming, or if the
  2613 + * error flag is set.
2595 2614 */
2596   - if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error)
  2615 + if (!vb2_is_streaming(q) || q->error)
  2616 + return res | POLLERR;
  2617 + /*
  2618 + * For compatibility with vb1: if QBUF hasn't been called yet, then
  2619 + * return POLLERR as well. This only affects capture queues, output
  2620 + * queues will always initialize waiting_for_buffers to false.
  2621 + */
  2622 + if (q->waiting_for_buffers)
2597 2623 return res | POLLERR;
2598 2624  
2599 2625 /*
drivers/media/v4l2-core/videobuf2-dma-sg.c
... ... @@ -113,7 +113,7 @@
113 113 goto fail_pages_alloc;
114 114  
115 115 ret = sg_alloc_table_from_pages(&buf->sg_table, buf->pages,
116   - buf->num_pages, 0, size, gfp_flags);
  116 + buf->num_pages, 0, size, GFP_KERNEL);
117 117 if (ret)
118 118 goto fail_table_alloc;
119 119  
include/media/videobuf2-core.h
... ... @@ -295,7 +295,7 @@
295 295 * can return an error if hardware fails, in that case all
296 296 * buffers that have been already given by the @buf_queue
297 297 * callback are to be returned by the driver by calling
298   - * @vb2_buffer_done(VB2_BUF_STATE_DEQUEUED).
  298 + * @vb2_buffer_done(VB2_BUF_STATE_QUEUED).
299 299 * If you need a minimum number of buffers before you can
300 300 * start streaming, then set @min_buffers_needed in the
301 301 * vb2_queue structure. If that is non-zero then
... ... @@ -380,6 +380,9 @@
380 380 * @start_streaming_called: start_streaming() was called successfully and we
381 381 * started streaming.
382 382 * @error: a fatal error occurred on the queue
  383 + * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for
  384 + * buffers. Only set for capture queues if qbuf has not yet been
  385 + * called since poll() needs to return POLLERR in that situation.
383 386 * @fileio: file io emulator internal data, used only if emulator is active
384 387 * @threadio: thread io internal data, used only if thread is active
385 388 */
... ... @@ -417,6 +420,7 @@
417 420 unsigned int streaming:1;
418 421 unsigned int start_streaming_called:1;
419 422 unsigned int error:1;
  423 + unsigned int waiting_for_buffers:1;
420 424  
421 425 struct vb2_fileio_data *fileio;
422 426 struct vb2_threadio_data *threadio;