aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/media/v4l/compat.xml24
-rw-r--r--Documentation/DocBook/media/v4l/func-poll.xml35
-rw-r--r--Documentation/DocBook/media/v4l/v4l2.xml11
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml2
-rw-r--r--drivers/media/common/cx2341x.c1
-rw-r--r--drivers/media/dvb-frontends/cx24123.c1
-rw-r--r--drivers/media/i2c/adv7604.c2
-rw-r--r--drivers/media/radio/radio-miropcm20.c1
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c25
-rw-r--r--drivers/media/usb/em28xx/em28xx.h1
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c48
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-sg.c2
-rw-r--r--include/media/videobuf2-core.h6
13 files changed, 119 insertions, 40 deletions
diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml
index eee6f0f4aa43..3a626d1b8f2e 100644
--- a/Documentation/DocBook/media/v4l/compat.xml
+++ b/Documentation/DocBook/media/v4l/compat.xml
@@ -2545,6 +2545,30 @@ fields changed from _s32 to _u32.
2545 </orderedlist> 2545 </orderedlist>
2546 </section> 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 <section id="other"> 2572 <section id="other">
2549 <title>Relation of V4L2 to other Linux multimedia APIs</title> 2573 <title>Relation of V4L2 to other Linux multimedia APIs</title>
2550 2574
diff --git a/Documentation/DocBook/media/v4l/func-poll.xml b/Documentation/DocBook/media/v4l/func-poll.xml
index 85cad8bff5ba..4c73f115219b 100644
--- a/Documentation/DocBook/media/v4l/func-poll.xml
+++ b/Documentation/DocBook/media/v4l/func-poll.xml
@@ -29,9 +29,12 @@ can suspend execution until the driver has captured data or is ready
29to accept data for output.</para> 29to accept data for output.</para>
30 30
31 <para>When streaming I/O has been negotiated this function waits 31 <para>When streaming I/O has been negotiated this function waits
32until a buffer has been filled or displayed and can be dequeued with 32until a buffer has been filled by the capture device and can be dequeued
33the &VIDIOC-DQBUF; ioctl. When buffers are already in the outgoing 33with the &VIDIOC-DQBUF; ioctl. For output devices this function waits
34queue of the driver the function returns immediately.</para> 34until the device is ready to accept a new buffer to be queued up with
35the &VIDIOC-QBUF; ioctl for display. When buffers are already in the outgoing
36queue of the driver (capture) or the incoming queue isn't full (display)
37the function returns immediately.</para>
35 38
36 <para>On success <function>poll()</function> returns the number of 39 <para>On success <function>poll()</function> returns the number of
37file descriptors that have been selected (that is, file descriptors 40file descriptors that have been selected (that is, file descriptors
@@ -44,10 +47,22 @@ Capture devices set the <constant>POLLIN</constant> and
44flags. When the function timed out it returns a value of zero, on 47flags. When the function timed out it returns a value of zero, on
45failure it returns <returnvalue>-1</returnvalue> and the 48failure it returns <returnvalue>-1</returnvalue> and the
46<varname>errno</varname> variable is set appropriately. When the 49<varname>errno</varname> variable is set appropriately. When the
47application did not call &VIDIOC-QBUF; or &VIDIOC-STREAMON; yet the 50application did not call &VIDIOC-STREAMON; the
48<function>poll()</function> function succeeds, but sets the 51<function>poll()</function> function succeeds, but sets the
49<constant>POLLERR</constant> flag in the 52<constant>POLLERR</constant> flag in the
50<structfield>revents</structfield> field.</para> 53<structfield>revents</structfield> field. When the
54application has called &VIDIOC-STREAMON; for a capture device but hasn't
55yet called &VIDIOC-QBUF;, the <function>poll()</function> function
56succeeds and sets the <constant>POLLERR</constant> flag in the
57<structfield>revents</structfield> field. For output devices this
58same situation will cause <function>poll()</function> to succeed
59as well, but it sets the <constant>POLLOUT</constant> and
60<constant>POLLWRNORM</constant> flags in the <structfield>revents</structfield>
61field.</para>
62
63 <para>If an event occurred (see &VIDIOC-DQEVENT;) then
64<constant>POLLPRI</constant> will be set in the <structfield>revents</structfield>
65field and <function>poll()</function> will return.</para>
51 66
52 <para>When use of the <function>read()</function> function has 67 <para>When use of the <function>read()</function> function has
53been negotiated and the driver does not capture yet, the 68been negotiated and the driver does not capture yet, the
@@ -58,10 +73,18 @@ continuously (as opposed to, for example, still images) the function
58may return immediately.</para> 73may return immediately.</para>
59 74
60 <para>When use of the <function>write()</function> function has 75 <para>When use of the <function>write()</function> function has
61been negotiated the <function>poll</function> function just waits 76been negotiated and the driver does not stream yet, the
77<function>poll</function> function starts streaming. When that fails
78it returns a <constant>POLLERR</constant> as above. Otherwise it waits
62until the driver is ready for a non-blocking 79until the driver is ready for a non-blocking
63<function>write()</function> call.</para> 80<function>write()</function> call.</para>
64 81
82 <para>If the caller is only interested in events (just
83<constant>POLLPRI</constant> is set in the <structfield>events</structfield>
84field), then <function>poll()</function> will <emphasis>not</emphasis>
85start streaming if the driver does not stream yet. This makes it
86possible to just poll for events and not for buffers.</para>
87
65 <para>All drivers implementing the <function>read()</function> or 88 <para>All drivers implementing the <function>read()</function> or
66<function>write()</function> function or streaming I/O must also 89<function>write()</function> function or streaming I/O must also
67support the <function>poll()</function> function.</para> 90support the <function>poll()</function> function.</para>
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml
index f2f81f06a17b..7cfe618f754d 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -152,10 +152,11 @@ structs, ioctls) must be noted in more detail in the history chapter
152applications. --> 152applications. -->
153 153
154 <revision> 154 <revision>
155 <revnumber>3.16</revnumber> 155 <revnumber>3.17</revnumber>
156 <date>2014-05-27</date> 156 <date>2014-08-04</date>
157 <authorinitials>lp</authorinitials> 157 <authorinitials>lp, hv</authorinitials>
158 <revremark>Extended &v4l2-pix-format;. Added format flags. 158 <revremark>Extended &v4l2-pix-format;. Added format flags. Added compound control types
159and VIDIOC_QUERY_EXT_CTRL.
159 </revremark> 160 </revremark>
160 </revision> 161 </revision>
161 162
@@ -538,7 +539,7 @@ and discussions on the V4L mailing list.</revremark>
538</partinfo> 539</partinfo>
539 540
540<title>Video for Linux Two API Specification</title> 541<title>Video for Linux Two API Specification</title>
541 <subtitle>Revision 3.14</subtitle> 542 <subtitle>Revision 3.17</subtitle>
542 543
543 <chapter id="common"> 544 <chapter id="common">
544 &sub-common; 545 &sub-common;
diff --git a/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
index 1ba9e999af3f..c62a7360719b 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subdev-g-selection.xml
@@ -119,7 +119,7 @@
119 </row> 119 </row>
120 <row> 120 <row>
121 <entry>&v4l2-rect;</entry> 121 <entry>&v4l2-rect;</entry>
122 <entry><structfield>rect</structfield></entry> 122 <entry><structfield>r</structfield></entry>
123 <entry>Selection rectangle, in pixels.</entry> 123 <entry>Selection rectangle, in pixels.</entry>
124 </row> 124 </row>
125 <row> 125 <row>
diff --git a/drivers/media/common/cx2341x.c b/drivers/media/common/cx2341x.c
index 103ef6bad2e2..be763150b8aa 100644
--- a/drivers/media/common/cx2341x.c
+++ b/drivers/media/common/cx2341x.c
@@ -1490,6 +1490,7 @@ static struct v4l2_ctrl *cx2341x_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
1490{ 1490{
1491 struct v4l2_ctrl_config cfg; 1491 struct v4l2_ctrl_config cfg;
1492 1492
1493 memset(&cfg, 0, sizeof(cfg));
1493 cx2341x_ctrl_fill(id, &cfg.name, &cfg.type, &min, &max, &step, &def, &cfg.flags); 1494 cx2341x_ctrl_fill(id, &cfg.name, &cfg.type, &min, &max, &step, &def, &cfg.flags);
1494 cfg.ops = &cx2341x_ops; 1495 cfg.ops = &cx2341x_ops;
1495 cfg.id = id; 1496 cfg.id = id;
diff --git a/drivers/media/dvb-frontends/cx24123.c b/drivers/media/dvb-frontends/cx24123.c
index 72fb5838cae0..7975c6608e20 100644
--- a/drivers/media/dvb-frontends/cx24123.c
+++ b/drivers/media/dvb-frontends/cx24123.c
@@ -1095,6 +1095,7 @@ struct dvb_frontend *cx24123_attach(const struct cx24123_config *config,
1095 sizeof(state->tuner_i2c_adapter.name)); 1095 sizeof(state->tuner_i2c_adapter.name));
1096 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo; 1096 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo;
1097 state->tuner_i2c_adapter.algo_data = NULL; 1097 state->tuner_i2c_adapter.algo_data = NULL;
1098 state->tuner_i2c_adapter.dev.parent = i2c->dev.parent;
1098 i2c_set_adapdata(&state->tuner_i2c_adapter, state); 1099 i2c_set_adapdata(&state->tuner_i2c_adapter, state);
1099 if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) { 1100 if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) {
1100 err("tuner i2c bus could not be initialized\n"); 1101 err("tuner i2c bus could not be initialized\n");
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index d4fa213ba74a..de88b980a837 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -2325,7 +2325,7 @@ static int adv7604_log_status(struct v4l2_subdev *sd)
2325 v4l2_info(sd, "HDCP keys read: %s%s\n", 2325 v4l2_info(sd, "HDCP keys read: %s%s\n",
2326 (hdmi_read(sd, 0x04) & 0x20) ? "yes" : "no", 2326 (hdmi_read(sd, 0x04) & 0x20) ? "yes" : "no",
2327 (hdmi_read(sd, 0x04) & 0x10) ? "ERROR" : ""); 2327 (hdmi_read(sd, 0x04) & 0x10) ? "ERROR" : "");
2328 if (!is_hdmi(sd)) { 2328 if (is_hdmi(sd)) {
2329 bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01; 2329 bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01;
2330 bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01; 2330 bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01;
2331 bool audio_mute = io_read(sd, 0x65) & 0x40; 2331 bool audio_mute = io_read(sd, 0x65) & 0x40;
diff --git a/drivers/media/radio/radio-miropcm20.c b/drivers/media/radio/radio-miropcm20.c
index 998919e97dfe..7b35e633118d 100644
--- a/drivers/media/radio/radio-miropcm20.c
+++ b/drivers/media/radio/radio-miropcm20.c
@@ -27,6 +27,7 @@
27 27
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/io.h>
30#include <linux/delay.h> 31#include <linux/delay.h>
31#include <linux/videodev2.h> 32#include <linux/videodev2.h>
32#include <linux/kthread.h> 33#include <linux/kthread.h>
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 90dec2955f1c..29abc379551e 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -1342,7 +1342,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1342 struct em28xx *dev = video_drvdata(file); 1342 struct em28xx *dev = video_drvdata(file);
1343 struct em28xx_v4l2 *v4l2 = dev->v4l2; 1343 struct em28xx_v4l2 *v4l2 = dev->v4l2;
1344 1344
1345 if (v4l2->streaming_users > 0) 1345 if (vb2_is_busy(&v4l2->vb_vidq))
1346 return -EBUSY; 1346 return -EBUSY;
1347 1347
1348 vidioc_try_fmt_vid_cap(file, priv, f); 1348 vidioc_try_fmt_vid_cap(file, priv, f);
@@ -1883,8 +1883,9 @@ static int em28xx_v4l2_open(struct file *filp)
1883 return -EINVAL; 1883 return -EINVAL;
1884 } 1884 }
1885 1885
1886 em28xx_videodbg("open dev=%s type=%s\n", 1886 em28xx_videodbg("open dev=%s type=%s users=%d\n",
1887 video_device_node_name(vdev), v4l2_type_names[fh_type]); 1887 video_device_node_name(vdev), v4l2_type_names[fh_type],
1888 v4l2->users);
1888 1889
1889 if (mutex_lock_interruptible(&dev->lock)) 1890 if (mutex_lock_interruptible(&dev->lock))
1890 return -ERESTARTSYS; 1891 return -ERESTARTSYS;
@@ -1897,9 +1898,7 @@ static int em28xx_v4l2_open(struct file *filp)
1897 return ret; 1898 return ret;
1898 } 1899 }
1899 1900
1900 if (v4l2_fh_is_singular_file(filp)) { 1901 if (v4l2->users == 0) {
1901 em28xx_videodbg("first opened filehandle, initializing device\n");
1902
1903 em28xx_set_mode(dev, EM28XX_ANALOG_MODE); 1902 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
1904 1903
1905 if (vdev->vfl_type != VFL_TYPE_RADIO) 1904 if (vdev->vfl_type != VFL_TYPE_RADIO)
@@ -1910,8 +1909,6 @@ static int em28xx_v4l2_open(struct file *filp)
1910 * of some i2c devices 1909 * of some i2c devices
1911 */ 1910 */
1912 em28xx_wake_i2c(dev); 1911 em28xx_wake_i2c(dev);
1913 } else {
1914 em28xx_videodbg("further filehandles are already opened\n");
1915 } 1912 }
1916 1913
1917 if (vdev->vfl_type == VFL_TYPE_RADIO) { 1914 if (vdev->vfl_type == VFL_TYPE_RADIO) {
@@ -1921,6 +1918,7 @@ static int em28xx_v4l2_open(struct file *filp)
1921 1918
1922 kref_get(&dev->ref); 1919 kref_get(&dev->ref);
1923 kref_get(&v4l2->ref); 1920 kref_get(&v4l2->ref);
1921 v4l2->users++;
1924 1922
1925 mutex_unlock(&dev->lock); 1923 mutex_unlock(&dev->lock);
1926 1924
@@ -2027,11 +2025,12 @@ static int em28xx_v4l2_close(struct file *filp)
2027 struct em28xx_v4l2 *v4l2 = dev->v4l2; 2025 struct em28xx_v4l2 *v4l2 = dev->v4l2;
2028 int errCode; 2026 int errCode;
2029 2027
2030 mutex_lock(&dev->lock); 2028 em28xx_videodbg("users=%d\n", v4l2->users);
2031 2029
2032 if (v4l2_fh_is_singular_file(filp)) { 2030 vb2_fop_release(filp);
2033 em28xx_videodbg("last opened filehandle, shutting down device\n"); 2031 mutex_lock(&dev->lock);
2034 2032
2033 if (v4l2->users == 1) {
2035 /* No sense to try to write to the device */ 2034 /* No sense to try to write to the device */
2036 if (dev->disconnected) 2035 if (dev->disconnected)
2037 goto exit; 2036 goto exit;
@@ -2050,12 +2049,10 @@ static int em28xx_v4l2_close(struct file *filp)
2050 em28xx_errdev("cannot change alternate number to " 2049 em28xx_errdev("cannot change alternate number to "
2051 "0 (error=%i)\n", errCode); 2050 "0 (error=%i)\n", errCode);
2052 } 2051 }
2053 } else {
2054 em28xx_videodbg("further opened filehandles left\n");
2055 } 2052 }
2056 2053
2057exit: 2054exit:
2058 vb2_fop_release(filp); 2055 v4l2->users--;
2059 kref_put(&v4l2->ref, em28xx_free_v4l2); 2056 kref_put(&v4l2->ref, em28xx_free_v4l2);
2060 mutex_unlock(&dev->lock); 2057 mutex_unlock(&dev->lock);
2061 kref_put(&dev->ref, em28xx_free_device); 2058 kref_put(&dev->ref, em28xx_free_device);
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index 84ef8efdb148..4360338e7b31 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -524,6 +524,7 @@ struct em28xx_v4l2 {
524 int sensor_yres; 524 int sensor_yres;
525 int sensor_xtal; 525 int sensor_xtal;
526 526
527 int users; /* user count for exclusive use */
527 int streaming_users; /* number of actively streaming users */ 528 int streaming_users; /* number of actively streaming users */
528 529
529 u32 frequency; /* selected tuner frequency */ 530 u32 frequency; /* selected tuner frequency */
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index c359006074a8..25d3ae2188cb 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -971,6 +971,7 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
971 * to the userspace. 971 * to the userspace.
972 */ 972 */
973 req->count = allocated_buffers; 973 req->count = allocated_buffers;
974 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
974 975
975 return 0; 976 return 0;
976} 977}
@@ -1018,6 +1019,7 @@ static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create
1018 memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); 1019 memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
1019 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); 1020 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
1020 q->memory = create->memory; 1021 q->memory = create->memory;
1022 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
1021 } 1023 }
1022 1024
1023 num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers); 1025 num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers);
@@ -1130,7 +1132,7 @@ EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
1130 */ 1132 */
1131void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no) 1133void *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 return NULL; 1136 return NULL;
1135 1137
1136 return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv); 1138 return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
@@ -1165,13 +1167,10 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
1165 if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) 1167 if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
1166 return; 1168 return;
1167 1169
1168 if (!q->start_streaming_called) { 1170 if (WARN_ON(state != VB2_BUF_STATE_DONE &&
1169 if (WARN_ON(state != VB2_BUF_STATE_QUEUED)) 1171 state != VB2_BUF_STATE_ERROR &&
1170 state = VB2_BUF_STATE_QUEUED; 1172 state != VB2_BUF_STATE_QUEUED))
1171 } else if (WARN_ON(state != VB2_BUF_STATE_DONE && 1173 state = VB2_BUF_STATE_ERROR;
1172 state != VB2_BUF_STATE_ERROR)) {
1173 state = VB2_BUF_STATE_ERROR;
1174 }
1175 1174
1176#ifdef CONFIG_VIDEO_ADV_DEBUG 1175#ifdef CONFIG_VIDEO_ADV_DEBUG
1177 /* 1176 /*
@@ -1762,6 +1761,12 @@ static int vb2_start_streaming(struct vb2_queue *q)
1762 q->start_streaming_called = 0; 1761 q->start_streaming_called = 0;
1763 1762
1764 dprintk(1, "driver refused to start streaming\n"); 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 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { 1770 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
1766 unsigned i; 1771 unsigned i;
1767 1772
@@ -1777,6 +1782,12 @@ static int vb2_start_streaming(struct vb2_queue *q)
1777 /* Must be zero now */ 1782 /* Must be zero now */
1778 WARN_ON(atomic_read(&q->owned_by_drv_count)); 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 return ret; 1791 return ret;
1781} 1792}
1782 1793
@@ -1812,6 +1823,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
1812 */ 1823 */
1813 list_add_tail(&vb->queued_entry, &q->queued_list); 1824 list_add_tail(&vb->queued_entry, &q->queued_list);
1814 q->queued_count++; 1825 q->queued_count++;
1826 q->waiting_for_buffers = false;
1815 vb->state = VB2_BUF_STATE_QUEUED; 1827 vb->state = VB2_BUF_STATE_QUEUED;
1816 if (V4L2_TYPE_IS_OUTPUT(q->type)) { 1828 if (V4L2_TYPE_IS_OUTPUT(q->type)) {
1817 /* 1829 /*
@@ -2123,6 +2135,12 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
2123 if (q->start_streaming_called) 2135 if (q->start_streaming_called)
2124 call_void_qop(q, stop_streaming, q); 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 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { 2144 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
2127 for (i = 0; i < q->num_buffers; ++i) 2145 for (i = 0; i < q->num_buffers; ++i)
2128 if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE) 2146 if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE)
@@ -2272,6 +2290,7 @@ static int vb2_internal_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
2272 * their normal dequeued state. 2290 * their normal dequeued state.
2273 */ 2291 */
2274 __vb2_queue_cancel(q); 2292 __vb2_queue_cancel(q);
2293 q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
2275 2294
2276 dprintk(3, "successful\n"); 2295 dprintk(3, "successful\n");
2277 return 0; 2296 return 0;
@@ -2590,10 +2609,17 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
2590 } 2609 }
2591 2610
2592 /* 2611 /*
2593 * There is nothing to wait for if no buffer has been queued and the 2612 * There is nothing to wait for if the queue isn't streaming, or if the
2594 * queue isn't streaming, or if the error flag is set. 2613 * error flag is set.
2614 */
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.
2595 */ 2621 */
2596 if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error) 2622 if (q->waiting_for_buffers)
2597 return res | POLLERR; 2623 return res | POLLERR;
2598 2624
2599 /* 2625 /*
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index adefc31bb853..9b163a440f89 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -113,7 +113,7 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_fla
113 goto fail_pages_alloc; 113 goto fail_pages_alloc;
114 114
115 ret = sg_alloc_table_from_pages(&buf->sg_table, buf->pages, 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 if (ret) 117 if (ret)
118 goto fail_table_alloc; 118 goto fail_table_alloc;
119 119
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index fc910a622451..2fefcf491aa8 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -295,7 +295,7 @@ struct vb2_buffer {
295 * can return an error if hardware fails, in that case all 295 * can return an error if hardware fails, in that case all
296 * buffers that have been already given by the @buf_queue 296 * buffers that have been already given by the @buf_queue
297 * callback are to be returned by the driver by calling 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 * If you need a minimum number of buffers before you can 299 * If you need a minimum number of buffers before you can
300 * start streaming, then set @min_buffers_needed in the 300 * start streaming, then set @min_buffers_needed in the
301 * vb2_queue structure. If that is non-zero then 301 * vb2_queue structure. If that is non-zero then
@@ -380,6 +380,9 @@ struct v4l2_fh;
380 * @start_streaming_called: start_streaming() was called successfully and we 380 * @start_streaming_called: start_streaming() was called successfully and we
381 * started streaming. 381 * started streaming.
382 * @error: a fatal error occurred on the queue 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 * @fileio: file io emulator internal data, used only if emulator is active 386 * @fileio: file io emulator internal data, used only if emulator is active
384 * @threadio: thread io internal data, used only if thread is active 387 * @threadio: thread io internal data, used only if thread is active
385 */ 388 */
@@ -417,6 +420,7 @@ struct vb2_queue {
417 unsigned int streaming:1; 420 unsigned int streaming:1;
418 unsigned int start_streaming_called:1; 421 unsigned int start_streaming_called:1;
419 unsigned int error:1; 422 unsigned int error:1;
423 unsigned int waiting_for_buffers:1;
420 424
421 struct vb2_fileio_data *fileio; 425 struct vb2_fileio_data *fileio;
422 struct vb2_threadio_data *threadio; 426 struct vb2_threadio_data *threadio;