aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media')
-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
8 files changed, 54 insertions, 27 deletions
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