aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/em28xx
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-23 07:12:47 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-09 18:46:52 -0400
commit876cb14db3bec19960751bb02f03f72ee024a46f (patch)
tree64c8508677ca5d71dba07d87942072d04eeee846 /drivers/media/video/em28xx
parent4d345708ca2688a06ca22e758d3eecc0352f5461 (diff)
[media] em28xx: remove V4L2_FL_LOCK_ALL_FOPS
Add proper locking to the file operations, allowing for the removal of the V4L2_FL_LOCK_ALL_FOPS flag. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/em28xx')
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c52
1 files changed, 35 insertions, 17 deletions
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 50f5f4fc2148..ecb23df7f16e 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -2146,9 +2146,12 @@ static int em28xx_v4l2_open(struct file *filp)
2146 dev->users); 2146 dev->users);
2147 2147
2148 2148
2149 if (mutex_lock_interruptible(&dev->lock))
2150 return -ERESTARTSYS;
2149 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); 2151 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
2150 if (!fh) { 2152 if (!fh) {
2151 em28xx_errdev("em28xx-video.c: Out of memory?!\n"); 2153 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
2154 mutex_unlock(&dev->lock);
2152 return -ENOMEM; 2155 return -ENOMEM;
2153 } 2156 }
2154 fh->dev = dev; 2157 fh->dev = dev;
@@ -2189,6 +2192,7 @@ static int em28xx_v4l2_open(struct file *filp)
2189 V4L2_BUF_TYPE_VBI_CAPTURE, 2192 V4L2_BUF_TYPE_VBI_CAPTURE,
2190 V4L2_FIELD_SEQ_TB, 2193 V4L2_FIELD_SEQ_TB,
2191 sizeof(struct em28xx_buffer), fh, &dev->lock); 2194 sizeof(struct em28xx_buffer), fh, &dev->lock);
2195 mutex_unlock(&dev->lock);
2192 2196
2193 return errCode; 2197 return errCode;
2194} 2198}
@@ -2243,6 +2247,7 @@ static int em28xx_v4l2_close(struct file *filp)
2243 2247
2244 em28xx_videodbg("users=%d\n", dev->users); 2248 em28xx_videodbg("users=%d\n", dev->users);
2245 2249
2250 mutex_lock(&dev->lock);
2246 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) { 2251 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
2247 videobuf_stop(&fh->vb_vidq); 2252 videobuf_stop(&fh->vb_vidq);
2248 res_free(fh, EM28XX_RESOURCE_VIDEO); 2253 res_free(fh, EM28XX_RESOURCE_VIDEO);
@@ -2261,6 +2266,7 @@ static int em28xx_v4l2_close(struct file *filp)
2261 kfree(dev->alt_max_pkt_size); 2266 kfree(dev->alt_max_pkt_size);
2262 kfree(dev); 2267 kfree(dev);
2263 kfree(fh); 2268 kfree(fh);
2269 mutex_unlock(&dev->lock);
2264 return 0; 2270 return 0;
2265 } 2271 }
2266 2272
@@ -2285,6 +2291,7 @@ static int em28xx_v4l2_close(struct file *filp)
2285 videobuf_mmap_free(&fh->vb_vbiq); 2291 videobuf_mmap_free(&fh->vb_vbiq);
2286 kfree(fh); 2292 kfree(fh);
2287 dev->users--; 2293 dev->users--;
2294 mutex_unlock(&dev->lock);
2288 return 0; 2295 return 0;
2289} 2296}
2290 2297
@@ -2304,35 +2311,35 @@ em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2304 if (rc < 0) 2311 if (rc < 0)
2305 return rc; 2312 return rc;
2306 2313
2314 if (mutex_lock_interruptible(&dev->lock))
2315 return -ERESTARTSYS;
2307 /* FIXME: read() is not prepared to allow changing the video 2316 /* FIXME: read() is not prepared to allow changing the video
2308 resolution while streaming. Seems a bug at em28xx_set_fmt 2317 resolution while streaming. Seems a bug at em28xx_set_fmt
2309 */ 2318 */
2310 2319
2311 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 2320 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2312 if (res_locked(dev, EM28XX_RESOURCE_VIDEO)) 2321 if (res_locked(dev, EM28XX_RESOURCE_VIDEO))
2313 return -EBUSY; 2322 rc = -EBUSY;
2314 2323 else
2315 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, 2324 rc = videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
2316 filp->f_flags & O_NONBLOCK); 2325 filp->f_flags & O_NONBLOCK);
2317 } 2326 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2318
2319
2320 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2321 if (!res_get(fh, EM28XX_RESOURCE_VBI)) 2327 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2322 return -EBUSY; 2328 rc = -EBUSY;
2323 2329 else
2324 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0, 2330 rc = videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
2325 filp->f_flags & O_NONBLOCK); 2331 filp->f_flags & O_NONBLOCK);
2326 } 2332 }
2333 mutex_unlock(&dev->lock);
2327 2334
2328 return 0; 2335 return rc;
2329} 2336}
2330 2337
2331/* 2338/*
2332 * em28xx_v4l2_poll() 2339 * em28xx_poll()
2333 * will allocate buffers when called for the first time 2340 * will allocate buffers when called for the first time
2334 */ 2341 */
2335static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait) 2342static unsigned int em28xx_poll(struct file *filp, poll_table *wait)
2336{ 2343{
2337 struct em28xx_fh *fh = filp->private_data; 2344 struct em28xx_fh *fh = filp->private_data;
2338 struct em28xx *dev = fh->dev; 2345 struct em28xx *dev = fh->dev;
@@ -2355,6 +2362,18 @@ static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
2355 } 2362 }
2356} 2363}
2357 2364
2365static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
2366{
2367 struct em28xx_fh *fh = filp->private_data;
2368 struct em28xx *dev = fh->dev;
2369 unsigned int res;
2370
2371 mutex_lock(&dev->lock);
2372 res = em28xx_poll(filp, wait);
2373 mutex_unlock(&dev->lock);
2374 return res;
2375}
2376
2358/* 2377/*
2359 * em28xx_v4l2_mmap() 2378 * em28xx_v4l2_mmap()
2360 */ 2379 */
@@ -2368,10 +2387,13 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
2368 if (rc < 0) 2387 if (rc < 0)
2369 return rc; 2388 return rc;
2370 2389
2390 if (mutex_lock_interruptible(&dev->lock))
2391 return -ERESTARTSYS;
2371 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 2392 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2372 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); 2393 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
2373 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) 2394 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
2374 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma); 2395 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
2396 mutex_unlock(&dev->lock);
2375 2397
2376 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", 2398 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2377 (unsigned long)vma->vm_start, 2399 (unsigned long)vma->vm_start,
@@ -2495,10 +2517,6 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
2495 vfd->release = video_device_release; 2517 vfd->release = video_device_release;
2496 vfd->debug = video_debug; 2518 vfd->debug = video_debug;
2497 vfd->lock = &dev->lock; 2519 vfd->lock = &dev->lock;
2498 /* Locking in file operations other than ioctl should be done
2499 by the driver, not the V4L2 core.
2500 This driver needs auditing so that this flag can be removed. */
2501 set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags);
2502 2520
2503 snprintf(vfd->name, sizeof(vfd->name), "%s %s", 2521 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
2504 dev->name, type_name); 2522 dev->name, type_name);