aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2012-06-08 03:47:34 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-06-18 18:45:59 -0400
commit9f4161a6b8796dc41dc3924d7869622f7975706a (patch)
treec34283e665e545ad976954cc34e39aef9eb2bde8 /drivers/media/video
parent4e6bb2a5fb9265a222e3a86b215f4c5e6bcd61de (diff)
[media] v4l: mem2mem_testdev: Fix race conditions in driver
The mem2mem_testdev allows multiple instances to be opened in parallel. Source and destination queue data are being shared between all instances, which can lead to kernel oops due to race conditions (most likely to happen inside device_run()). Attached patch fixes mentioned problem by storing queue data per device context. Signed-off-by: Tomasz Moń <desowin@gmail.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/mem2mem_testdev.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
index d2dec585e61..3945556f573 100644
--- a/drivers/media/video/mem2mem_testdev.c
+++ b/drivers/media/video/mem2mem_testdev.c
@@ -110,22 +110,6 @@ enum {
110 V4L2_M2M_DST = 1, 110 V4L2_M2M_DST = 1,
111}; 111};
112 112
113/* Source and destination queue data */
114static struct m2mtest_q_data q_data[2];
115
116static struct m2mtest_q_data *get_q_data(enum v4l2_buf_type type)
117{
118 switch (type) {
119 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
120 return &q_data[V4L2_M2M_SRC];
121 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
122 return &q_data[V4L2_M2M_DST];
123 default:
124 BUG();
125 }
126 return NULL;
127}
128
129#define V4L2_CID_TRANS_TIME_MSEC V4L2_CID_PRIVATE_BASE 113#define V4L2_CID_TRANS_TIME_MSEC V4L2_CID_PRIVATE_BASE
130#define V4L2_CID_TRANS_NUM_BUFS (V4L2_CID_PRIVATE_BASE + 1) 114#define V4L2_CID_TRANS_NUM_BUFS (V4L2_CID_PRIVATE_BASE + 1)
131 115
@@ -198,8 +182,26 @@ struct m2mtest_ctx {
198 int aborting; 182 int aborting;
199 183
200 struct v4l2_m2m_ctx *m2m_ctx; 184 struct v4l2_m2m_ctx *m2m_ctx;
185
186 /* Source and destination queue data */
187 struct m2mtest_q_data q_data[2];
201}; 188};
202 189
190static struct m2mtest_q_data *get_q_data(struct m2mtest_ctx *ctx,
191 enum v4l2_buf_type type)
192{
193 switch (type) {
194 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
195 return &ctx->q_data[V4L2_M2M_SRC];
196 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
197 return &ctx->q_data[V4L2_M2M_DST];
198 default:
199 BUG();
200 }
201 return NULL;
202}
203
204
203static struct v4l2_queryctrl *get_ctrl(int id) 205static struct v4l2_queryctrl *get_ctrl(int id)
204{ 206{
205 int i; 207 int i;
@@ -223,7 +225,7 @@ static int device_process(struct m2mtest_ctx *ctx,
223 int tile_w, bytes_left; 225 int tile_w, bytes_left;
224 int width, height, bytesperline; 226 int width, height, bytesperline;
225 227
226 q_data = get_q_data(V4L2_BUF_TYPE_VIDEO_OUTPUT); 228 q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
227 229
228 width = q_data->width; 230 width = q_data->width;
229 height = q_data->height; 231 height = q_data->height;
@@ -436,7 +438,7 @@ static int vidioc_g_fmt(struct m2mtest_ctx *ctx, struct v4l2_format *f)
436 if (!vq) 438 if (!vq)
437 return -EINVAL; 439 return -EINVAL;
438 440
439 q_data = get_q_data(f->type); 441 q_data = get_q_data(ctx, f->type);
440 442
441 f->fmt.pix.width = q_data->width; 443 f->fmt.pix.width = q_data->width;
442 f->fmt.pix.height = q_data->height; 444 f->fmt.pix.height = q_data->height;
@@ -535,7 +537,7 @@ static int vidioc_s_fmt(struct m2mtest_ctx *ctx, struct v4l2_format *f)
535 if (!vq) 537 if (!vq)
536 return -EINVAL; 538 return -EINVAL;
537 539
538 q_data = get_q_data(f->type); 540 q_data = get_q_data(ctx, f->type);
539 if (!q_data) 541 if (!q_data)
540 return -EINVAL; 542 return -EINVAL;
541 543
@@ -747,7 +749,7 @@ static int m2mtest_queue_setup(struct vb2_queue *vq,
747 struct m2mtest_q_data *q_data; 749 struct m2mtest_q_data *q_data;
748 unsigned int size, count = *nbuffers; 750 unsigned int size, count = *nbuffers;
749 751
750 q_data = get_q_data(vq->type); 752 q_data = get_q_data(ctx, vq->type);
751 753
752 size = q_data->width * q_data->height * q_data->fmt->depth >> 3; 754 size = q_data->width * q_data->height * q_data->fmt->depth >> 3;
753 755
@@ -775,7 +777,7 @@ static int m2mtest_buf_prepare(struct vb2_buffer *vb)
775 777
776 dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type); 778 dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type);
777 779
778 q_data = get_q_data(vb->vb2_queue->type); 780 q_data = get_q_data(ctx, vb->vb2_queue->type);
779 781
780 if (vb2_plane_size(vb, 0) < q_data->sizeimage) { 782 if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
781 dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n", 783 dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n",
@@ -860,6 +862,9 @@ static int m2mtest_open(struct file *file)
860 ctx->transtime = MEM2MEM_DEF_TRANSTIME; 862 ctx->transtime = MEM2MEM_DEF_TRANSTIME;
861 ctx->num_processed = 0; 863 ctx->num_processed = 0;
862 864
865 ctx->q_data[V4L2_M2M_SRC].fmt = &formats[0];
866 ctx->q_data[V4L2_M2M_DST].fmt = &formats[0];
867
863 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 868 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
864 869
865 if (IS_ERR(ctx->m2m_ctx)) { 870 if (IS_ERR(ctx->m2m_ctx)) {
@@ -986,9 +991,6 @@ static int m2mtest_probe(struct platform_device *pdev)
986 goto err_m2m; 991 goto err_m2m;
987 } 992 }
988 993
989 q_data[V4L2_M2M_SRC].fmt = &formats[0];
990 q_data[V4L2_M2M_DST].fmt = &formats[0];
991
992 return 0; 994 return 0;
993 995
994 v4l2_m2m_release(dev->m2m_dev); 996 v4l2_m2m_release(dev->m2m_dev);