aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-24 05:43:02 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-09 19:11:50 -0400
commit1f7e073da5ba4c1b3af8ad0f313e9d3e6447f858 (patch)
tree3cd894368aaa740ad350a8cf1cc35c166142bf6f /drivers
parent28c3682ac59dcc551682eceb021b66386ee4e570 (diff)
[media] cx231xx: 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')
-rw-r--r--drivers/media/video/cx231xx/cx231xx-video.c47
1 files changed, 36 insertions, 11 deletions
diff --git a/drivers/media/video/cx231xx/cx231xx-video.c b/drivers/media/video/cx231xx/cx231xx-video.c
index 523aa49d6b86..790b28d7f764 100644
--- a/drivers/media/video/cx231xx/cx231xx-video.c
+++ b/drivers/media/video/cx231xx/cx231xx-video.c
@@ -2168,6 +2168,10 @@ static int cx231xx_v4l2_open(struct file *filp)
2168 cx231xx_errdev("cx231xx-video.c: Out of memory?!\n"); 2168 cx231xx_errdev("cx231xx-video.c: Out of memory?!\n");
2169 return -ENOMEM; 2169 return -ENOMEM;
2170 } 2170 }
2171 if (mutex_lock_interruptible(&dev->lock)) {
2172 kfree(fh);
2173 return -ERESTARTSYS;
2174 }
2171 fh->dev = dev; 2175 fh->dev = dev;
2172 fh->radio = radio; 2176 fh->radio = radio;
2173 fh->type = fh_type; 2177 fh->type = fh_type;
@@ -2226,6 +2230,7 @@ static int cx231xx_v4l2_open(struct file *filp)
2226 sizeof(struct cx231xx_buffer), 2230 sizeof(struct cx231xx_buffer),
2227 fh, &dev->lock); 2231 fh, &dev->lock);
2228 } 2232 }
2233 mutex_unlock(&dev->lock);
2229 2234
2230 return errCode; 2235 return errCode;
2231} 2236}
@@ -2272,11 +2277,11 @@ void cx231xx_release_analog_resources(struct cx231xx *dev)
2272} 2277}
2273 2278
2274/* 2279/*
2275 * cx231xx_v4l2_close() 2280 * cx231xx_close()
2276 * stops streaming and deallocates all resources allocated by the v4l2 2281 * stops streaming and deallocates all resources allocated by the v4l2
2277 * calls and ioctls 2282 * calls and ioctls
2278 */ 2283 */
2279static int cx231xx_v4l2_close(struct file *filp) 2284static int cx231xx_close(struct file *filp)
2280{ 2285{
2281 struct cx231xx_fh *fh = filp->private_data; 2286 struct cx231xx_fh *fh = filp->private_data;
2282 struct cx231xx *dev = fh->dev; 2287 struct cx231xx *dev = fh->dev;
@@ -2355,6 +2360,18 @@ static int cx231xx_v4l2_close(struct file *filp)
2355 return 0; 2360 return 0;
2356} 2361}
2357 2362
2363static int cx231xx_v4l2_close(struct file *filp)
2364{
2365 struct cx231xx_fh *fh = filp->private_data;
2366 struct cx231xx *dev = fh->dev;
2367 int rc;
2368
2369 mutex_lock(&dev->lock);
2370 rc = cx231xx_close(filp);
2371 mutex_unlock(&dev->lock);
2372 return rc;
2373}
2374
2358/* 2375/*
2359 * cx231xx_v4l2_read() 2376 * cx231xx_v4l2_read()
2360 * will allocate buffers when called for the first time 2377 * will allocate buffers when called for the first time
@@ -2378,8 +2395,12 @@ cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2378 if (unlikely(rc < 0)) 2395 if (unlikely(rc < 0))
2379 return rc; 2396 return rc;
2380 2397
2381 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, 2398 if (mutex_lock_interruptible(&dev->lock))
2399 return -ERESTARTSYS;
2400 rc = videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
2382 filp->f_flags & O_NONBLOCK); 2401 filp->f_flags & O_NONBLOCK);
2402 mutex_unlock(&dev->lock);
2403 return rc;
2383 } 2404 }
2384 return 0; 2405 return 0;
2385} 2406}
@@ -2404,10 +2425,15 @@ static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table *wait)
2404 return POLLERR; 2425 return POLLERR;
2405 2426
2406 if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) || 2427 if ((V4L2_BUF_TYPE_VIDEO_CAPTURE == fh->type) ||
2407 (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) 2428 (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) {
2408 return videobuf_poll_stream(filp, &fh->vb_vidq, wait); 2429 unsigned int res;
2409 else 2430
2410 return POLLERR; 2431 mutex_lock(&dev->lock);
2432 res = videobuf_poll_stream(filp, &fh->vb_vidq, wait);
2433 mutex_unlock(&dev->lock);
2434 return res;
2435 }
2436 return POLLERR;
2411} 2437}
2412 2438
2413/* 2439/*
@@ -2428,7 +2454,10 @@ static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
2428 if (unlikely(rc < 0)) 2454 if (unlikely(rc < 0))
2429 return rc; 2455 return rc;
2430 2456
2457 if (mutex_lock_interruptible(&dev->lock))
2458 return -ERESTARTSYS;
2431 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); 2459 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
2460 mutex_unlock(&dev->lock);
2432 2461
2433 cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n", 2462 cx231xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2434 (unsigned long)vma->vm_start, 2463 (unsigned long)vma->vm_start,
@@ -2545,10 +2574,6 @@ static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
2545 vfd->release = video_device_release; 2574 vfd->release = video_device_release;
2546 vfd->debug = video_debug; 2575 vfd->debug = video_debug;
2547 vfd->lock = &dev->lock; 2576 vfd->lock = &dev->lock;
2548 /* Locking in file operations other than ioctl should be done
2549 by the driver, not the V4L2 core.
2550 This driver needs auditing so that this flag can be removed. */
2551 set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags);
2552 2577
2553 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); 2578 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
2554 2579