aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-23 07:46:43 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-09 18:48:53 -0400
commit87cb0278c9872aced7e01952ff1f84a653cb56e4 (patch)
tree6b53834abe56f8832009b7576b81cc664b9d85c0 /drivers
parenta2e10b5aee587442fd7831e1707cce32e3b2e414 (diff)
[media] fsl-viu: 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/fsl-viu.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/drivers/media/video/fsl-viu.c b/drivers/media/video/fsl-viu.c
index 777486f7cadb..20f981008faf 100644
--- a/drivers/media/video/fsl-viu.c
+++ b/drivers/media/video/fsl-viu.c
@@ -1279,10 +1279,16 @@ static int viu_open(struct file *file)
1279 dprintk(1, "open minor=%d type=%s users=%d\n", minor, 1279 dprintk(1, "open minor=%d type=%s users=%d\n", minor,
1280 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users); 1280 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
1281 1281
1282 if (mutex_lock_interruptible(&dev->lock)) {
1283 dev->users--;
1284 return -ERESTARTSYS;
1285 }
1286
1282 /* allocate and initialize per filehandle data */ 1287 /* allocate and initialize per filehandle data */
1283 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 1288 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1284 if (!fh) { 1289 if (!fh) {
1285 dev->users--; 1290 dev->users--;
1291 mutex_unlock(&dev->lock);
1286 return -ENOMEM; 1292 return -ENOMEM;
1287 } 1293 }
1288 1294
@@ -1325,6 +1331,7 @@ static int viu_open(struct file *file)
1325 fh->type, V4L2_FIELD_INTERLACED, 1331 fh->type, V4L2_FIELD_INTERLACED,
1326 sizeof(struct viu_buf), fh, 1332 sizeof(struct viu_buf), fh,
1327 &fh->dev->lock); 1333 &fh->dev->lock);
1334 mutex_unlock(&dev->lock);
1328 return 0; 1335 return 0;
1329} 1336}
1330 1337
@@ -1340,9 +1347,12 @@ static ssize_t viu_read(struct file *file, char __user *data, size_t count,
1340 dev->ovenable = 0; 1347 dev->ovenable = 0;
1341 1348
1342 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1349 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1350 if (mutex_lock_interruptible(&dev->lock))
1351 return -ERESTARTSYS;
1343 viu_start_dma(dev); 1352 viu_start_dma(dev);
1344 ret = videobuf_read_stream(&fh->vb_vidq, data, count, 1353 ret = videobuf_read_stream(&fh->vb_vidq, data, count,
1345 ppos, 0, file->f_flags & O_NONBLOCK); 1354 ppos, 0, file->f_flags & O_NONBLOCK);
1355 mutex_unlock(&dev->lock);
1346 return ret; 1356 return ret;
1347 } 1357 }
1348 return 0; 1358 return 0;
@@ -1352,11 +1362,16 @@ static unsigned int viu_poll(struct file *file, struct poll_table_struct *wait)
1352{ 1362{
1353 struct viu_fh *fh = file->private_data; 1363 struct viu_fh *fh = file->private_data;
1354 struct videobuf_queue *q = &fh->vb_vidq; 1364 struct videobuf_queue *q = &fh->vb_vidq;
1365 struct viu_dev *dev = fh->dev;
1366 unsigned int res;
1355 1367
1356 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1368 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1357 return POLLERR; 1369 return POLLERR;
1358 1370
1359 return videobuf_poll_stream(file, q, wait); 1371 mutex_lock(&dev->lock);
1372 res = videobuf_poll_stream(file, q, wait);
1373 mutex_unlock(&dev->lock);
1374 return res;
1360} 1375}
1361 1376
1362static int viu_release(struct file *file) 1377static int viu_release(struct file *file)
@@ -1365,9 +1380,11 @@ static int viu_release(struct file *file)
1365 struct viu_dev *dev = fh->dev; 1380 struct viu_dev *dev = fh->dev;
1366 int minor = video_devdata(file)->minor; 1381 int minor = video_devdata(file)->minor;
1367 1382
1383 mutex_lock(&dev->lock);
1368 viu_stop_dma(dev); 1384 viu_stop_dma(dev);
1369 videobuf_stop(&fh->vb_vidq); 1385 videobuf_stop(&fh->vb_vidq);
1370 videobuf_mmap_free(&fh->vb_vidq); 1386 videobuf_mmap_free(&fh->vb_vidq);
1387 mutex_unlock(&dev->lock);
1371 1388
1372 kfree(fh); 1389 kfree(fh);
1373 1390
@@ -1394,11 +1411,15 @@ void viu_reset(struct viu_reg *reg)
1394static int viu_mmap(struct file *file, struct vm_area_struct *vma) 1411static int viu_mmap(struct file *file, struct vm_area_struct *vma)
1395{ 1412{
1396 struct viu_fh *fh = file->private_data; 1413 struct viu_fh *fh = file->private_data;
1414 struct viu_dev *dev = fh->dev;
1397 int ret; 1415 int ret;
1398 1416
1399 dprintk(1, "mmap called, vma=0x%08lx\n", (unsigned long)vma); 1417 dprintk(1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
1400 1418
1419 if (mutex_lock_interruptible(&dev->lock))
1420 return -ERESTARTSYS;
1401 ret = videobuf_mmap_mapper(&fh->vb_vidq, vma); 1421 ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1422 mutex_unlock(&dev->lock);
1402 1423
1403 dprintk(1, "vma start=0x%08lx, size=%ld, ret=%d\n", 1424 dprintk(1, "vma start=0x%08lx, size=%ld, ret=%d\n",
1404 (unsigned long)vma->vm_start, 1425 (unsigned long)vma->vm_start,
@@ -1544,10 +1565,6 @@ static int __devinit viu_of_probe(struct platform_device *op)
1544 1565
1545 /* initialize locks */ 1566 /* initialize locks */
1546 mutex_init(&viu_dev->lock); 1567 mutex_init(&viu_dev->lock);
1547 /* Locking in file operations other than ioctl should be done
1548 by the driver, not the V4L2 core.
1549 This driver needs auditing so that this flag can be removed. */
1550 set_bit(V4L2_FL_LOCK_ALL_FOPS, &viu_dev->vdev->flags);
1551 viu_dev->vdev->lock = &viu_dev->lock; 1568 viu_dev->vdev->lock = &viu_dev->lock;
1552 spin_lock_init(&viu_dev->slock); 1569 spin_lock_init(&viu_dev->slock);
1553 1570