aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/mem2mem_testdev.c29
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)
891 struct m2mtest_dev *dev = video_drvdata(file); 891 struct m2mtest_dev *dev = video_drvdata(file);
892 struct m2mtest_ctx *ctx = NULL; 892 struct m2mtest_ctx *ctx = NULL;
893 struct v4l2_ctrl_handler *hdl; 893 struct v4l2_ctrl_handler *hdl;
894 int rc = 0;
894 895
896 if (mutex_lock_interruptible(&dev->dev_mutex))
897 return -ERESTARTSYS;
895 ctx = kzalloc(sizeof *ctx, GFP_KERNEL); 898 ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
896 if (!ctx) 899 if (!ctx) {
897 return -ENOMEM; 900 rc = -ENOMEM;
901 goto open_unlock;
902 }
898 903
899 v4l2_fh_init(&ctx->fh, video_devdata(file)); 904 v4l2_fh_init(&ctx->fh, video_devdata(file));
900 file->private_data = &ctx->fh; 905 file->private_data = &ctx->fh;
@@ -927,11 +932,11 @@ static int m2mtest_open(struct file *file)
927 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 932 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
928 933
929 if (IS_ERR(ctx->m2m_ctx)) { 934 if (IS_ERR(ctx->m2m_ctx)) {
930 int ret = PTR_ERR(ctx->m2m_ctx); 935 rc = PTR_ERR(ctx->m2m_ctx);
931 936
932 v4l2_ctrl_handler_free(hdl); 937 v4l2_ctrl_handler_free(hdl);
933 kfree(ctx); 938 kfree(ctx);
934 return ret; 939 goto open_unlock;
935 } 940 }
936 941
937 v4l2_fh_add(&ctx->fh); 942 v4l2_fh_add(&ctx->fh);
@@ -939,6 +944,8 @@ static int m2mtest_open(struct file *file)
939 944
940 dprintk(dev, "Created instance %p, m2m_ctx: %p\n", ctx, ctx->m2m_ctx); 945 dprintk(dev, "Created instance %p, m2m_ctx: %p\n", ctx, ctx->m2m_ctx);
941 946
947open_unlock:
948 mutex_unlock(&dev->dev_mutex);
942 return 0; 949 return 0;
943} 950}
944 951
@@ -952,7 +959,9 @@ static int m2mtest_release(struct file *file)
952 v4l2_fh_del(&ctx->fh); 959 v4l2_fh_del(&ctx->fh);
953 v4l2_fh_exit(&ctx->fh); 960 v4l2_fh_exit(&ctx->fh);
954 v4l2_ctrl_handler_free(&ctx->hdl); 961 v4l2_ctrl_handler_free(&ctx->hdl);
962 mutex_lock(&dev->dev_mutex);
955 v4l2_m2m_ctx_release(ctx->m2m_ctx); 963 v4l2_m2m_ctx_release(ctx->m2m_ctx);
964 mutex_unlock(&dev->dev_mutex);
956 kfree(ctx); 965 kfree(ctx);
957 966
958 atomic_dec(&dev->num_inst); 967 atomic_dec(&dev->num_inst);
@@ -970,9 +979,15 @@ static unsigned int m2mtest_poll(struct file *file,
970 979
971static int m2mtest_mmap(struct file *file, struct vm_area_struct *vma) 980static int m2mtest_mmap(struct file *file, struct vm_area_struct *vma)
972{ 981{
982 struct m2mtest_dev *dev = video_drvdata(file);
973 struct m2mtest_ctx *ctx = file2ctx(file); 983 struct m2mtest_ctx *ctx = file2ctx(file);
984 int res;
974 985
975 return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 986 if (mutex_lock_interruptible(&dev->dev_mutex))
987 return -ERESTARTSYS;
988 res = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
989 mutex_unlock(&dev->dev_mutex);
990 return res;
976} 991}
977 992
978static const struct v4l2_file_operations m2mtest_fops = { 993static const struct v4l2_file_operations m2mtest_fops = {
@@ -1027,10 +1042,6 @@ static int m2mtest_probe(struct platform_device *pdev)
1027 } 1042 }
1028 1043
1029 *vfd = m2mtest_videodev; 1044 *vfd = m2mtest_videodev;
1030 /* Locking in file operations other than ioctl should be done
1031 by the driver, not the V4L2 core.
1032 This driver needs auditing so that this flag can be removed. */
1033 set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags);
1034 vfd->lock = &dev->dev_mutex; 1045 vfd->lock = &dev->dev_mutex;
1035 1046
1036 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); 1047 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);