diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-07-31 03:51:25 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-08-09 20:17:32 -0300 |
commit | f46940399b74171814f485d58bcdf70929f59d67 (patch) | |
tree | c175817c246ae3cbcb5fc84601afb9c78a709642 /drivers/media | |
parent | 7224679a319fb1738f9da662287ce109d653f758 (diff) | |
download | blackbird-op-linux-f46940399b74171814f485d58bcdf70929f59d67.tar.gz blackbird-op-linux-f46940399b74171814f485d58bcdf70929f59d67.zip |
[media] mem2mem_testdev: 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')
-rw-r--r-- | drivers/media/video/mem2mem_testdev.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c index 7efe9ad7acc7..6d0d2fb11bbe 100644 --- a/drivers/media/video/mem2mem_testdev.c +++ b/drivers/media/video/mem2mem_testdev.c @@ -891,10 +891,15 @@ static int m2mtest_open(struct file *file) struct m2mtest_dev *dev = video_drvdata(file); struct m2mtest_ctx *ctx = NULL; struct v4l2_ctrl_handler *hdl; + int rc = 0; + if (mutex_lock_interruptible(&dev->dev_mutex)) + return -ERESTARTSYS; ctx = kzalloc(sizeof *ctx, GFP_KERNEL); - if (!ctx) - return -ENOMEM; + if (!ctx) { + rc = -ENOMEM; + goto open_unlock; + } v4l2_fh_init(&ctx->fh, video_devdata(file)); file->private_data = &ctx->fh; @@ -927,11 +932,11 @@ static int m2mtest_open(struct file *file) ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); if (IS_ERR(ctx->m2m_ctx)) { - int ret = PTR_ERR(ctx->m2m_ctx); + rc = PTR_ERR(ctx->m2m_ctx); v4l2_ctrl_handler_free(hdl); kfree(ctx); - return ret; + goto open_unlock; } v4l2_fh_add(&ctx->fh); @@ -939,6 +944,8 @@ static int m2mtest_open(struct file *file) dprintk(dev, "Created instance %p, m2m_ctx: %p\n", ctx, ctx->m2m_ctx); +open_unlock: + mutex_unlock(&dev->dev_mutex); return 0; } @@ -952,7 +959,9 @@ static int m2mtest_release(struct file *file) v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); v4l2_ctrl_handler_free(&ctx->hdl); + mutex_lock(&dev->dev_mutex); v4l2_m2m_ctx_release(ctx->m2m_ctx); + mutex_unlock(&dev->dev_mutex); kfree(ctx); atomic_dec(&dev->num_inst); @@ -970,9 +979,15 @@ static unsigned int m2mtest_poll(struct file *file, static int m2mtest_mmap(struct file *file, struct vm_area_struct *vma) { + struct m2mtest_dev *dev = video_drvdata(file); struct m2mtest_ctx *ctx = file2ctx(file); + int res; - return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); + if (mutex_lock_interruptible(&dev->dev_mutex)) + return -ERESTARTSYS; + res = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); + mutex_unlock(&dev->dev_mutex); + return res; } static const struct v4l2_file_operations m2mtest_fops = { @@ -1027,10 +1042,6 @@ static int m2mtest_probe(struct platform_device *pdev) } *vfd = m2mtest_videodev; - /* Locking in file operations other than ioctl should be done - by the driver, not the V4L2 core. - This driver needs auditing so that this flag can be removed. */ - set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags); vfd->lock = &dev->dev_mutex; ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); |