aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-24 05:54:18 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-09 19:12:46 -0400
commitb0d5cd6b5f2137b3485c96c673beebfd6c726fd3 (patch)
tree412d9c9833237b70c1b4b22db75c0dacf21f6e44
parent8422b087834f198a63f33c46f34059356cafef9d (diff)
[media] s5p-jpeg: 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>
-rw-r--r--drivers/media/video/s5p-jpeg/jpeg-core.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/drivers/media/video/s5p-jpeg/jpeg-core.c b/drivers/media/video/s5p-jpeg/jpeg-core.c
index 813b801238d1..be04d584e36a 100644
--- a/drivers/media/video/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/video/s5p-jpeg/jpeg-core.c
@@ -292,6 +292,11 @@ static int s5p_jpeg_open(struct file *file)
292 if (!ctx) 292 if (!ctx)
293 return -ENOMEM; 293 return -ENOMEM;
294 294
295 if (mutex_lock_interruptible(&jpeg->lock)) {
296 ret = -ERESTARTSYS;
297 goto free;
298 }
299
295 v4l2_fh_init(&ctx->fh, vfd); 300 v4l2_fh_init(&ctx->fh, vfd);
296 /* Use separate control handler per file handle */ 301 /* Use separate control handler per file handle */
297 ctx->fh.ctrl_handler = &ctx->ctrl_handler; 302 ctx->fh.ctrl_handler = &ctx->ctrl_handler;
@@ -319,20 +324,26 @@ static int s5p_jpeg_open(struct file *file)
319 324
320 ctx->out_q.fmt = out_fmt; 325 ctx->out_q.fmt = out_fmt;
321 ctx->cap_q.fmt = s5p_jpeg_find_format(ctx->mode, V4L2_PIX_FMT_YUYV); 326 ctx->cap_q.fmt = s5p_jpeg_find_format(ctx->mode, V4L2_PIX_FMT_YUYV);
327 mutex_unlock(&jpeg->lock);
322 return 0; 328 return 0;
323 329
324error: 330error:
325 v4l2_fh_del(&ctx->fh); 331 v4l2_fh_del(&ctx->fh);
326 v4l2_fh_exit(&ctx->fh); 332 v4l2_fh_exit(&ctx->fh);
333 mutex_unlock(&jpeg->lock);
334free:
327 kfree(ctx); 335 kfree(ctx);
328 return ret; 336 return ret;
329} 337}
330 338
331static int s5p_jpeg_release(struct file *file) 339static int s5p_jpeg_release(struct file *file)
332{ 340{
341 struct s5p_jpeg *jpeg = video_drvdata(file);
333 struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data); 342 struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data);
334 343
344 mutex_lock(&jpeg->lock);
335 v4l2_m2m_ctx_release(ctx->m2m_ctx); 345 v4l2_m2m_ctx_release(ctx->m2m_ctx);
346 mutex_unlock(&jpeg->lock);
336 v4l2_ctrl_handler_free(&ctx->ctrl_handler); 347 v4l2_ctrl_handler_free(&ctx->ctrl_handler);
337 v4l2_fh_del(&ctx->fh); 348 v4l2_fh_del(&ctx->fh);
338 v4l2_fh_exit(&ctx->fh); 349 v4l2_fh_exit(&ctx->fh);
@@ -344,16 +355,27 @@ static int s5p_jpeg_release(struct file *file)
344static unsigned int s5p_jpeg_poll(struct file *file, 355static unsigned int s5p_jpeg_poll(struct file *file,
345 struct poll_table_struct *wait) 356 struct poll_table_struct *wait)
346{ 357{
358 struct s5p_jpeg *jpeg = video_drvdata(file);
347 struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data); 359 struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data);
360 unsigned int res;
348 361
349 return v4l2_m2m_poll(file, ctx->m2m_ctx, wait); 362 mutex_lock(&jpeg->lock);
363 res = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
364 mutex_unlock(&jpeg->lock);
365 return res;
350} 366}
351 367
352static int s5p_jpeg_mmap(struct file *file, struct vm_area_struct *vma) 368static int s5p_jpeg_mmap(struct file *file, struct vm_area_struct *vma)
353{ 369{
370 struct s5p_jpeg *jpeg = video_drvdata(file);
354 struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data); 371 struct s5p_jpeg_ctx *ctx = fh_to_ctx(file->private_data);
372 int ret;
355 373
356 return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 374 if (mutex_lock_interruptible(&jpeg->lock))
375 return -ERESTARTSYS;
376 ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
377 mutex_unlock(&jpeg->lock);
378 return ret;
357} 379}
358 380
359static const struct v4l2_file_operations s5p_jpeg_fops = { 381static const struct v4l2_file_operations s5p_jpeg_fops = {
@@ -1372,10 +1394,6 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
1372 jpeg->vfd_encoder->release = video_device_release; 1394 jpeg->vfd_encoder->release = video_device_release;
1373 jpeg->vfd_encoder->lock = &jpeg->lock; 1395 jpeg->vfd_encoder->lock = &jpeg->lock;
1374 jpeg->vfd_encoder->v4l2_dev = &jpeg->v4l2_dev; 1396 jpeg->vfd_encoder->v4l2_dev = &jpeg->v4l2_dev;
1375 /* Locking in file operations other than ioctl should be done
1376 by the driver, not the V4L2 core.
1377 This driver needs auditing so that this flag can be removed. */
1378 set_bit(V4L2_FL_LOCK_ALL_FOPS, &jpeg->vfd_encoder->flags);
1379 1397
1380 ret = video_register_device(jpeg->vfd_encoder, VFL_TYPE_GRABBER, -1); 1398 ret = video_register_device(jpeg->vfd_encoder, VFL_TYPE_GRABBER, -1);
1381 if (ret) { 1399 if (ret) {
@@ -1403,10 +1421,6 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
1403 jpeg->vfd_decoder->release = video_device_release; 1421 jpeg->vfd_decoder->release = video_device_release;
1404 jpeg->vfd_decoder->lock = &jpeg->lock; 1422 jpeg->vfd_decoder->lock = &jpeg->lock;
1405 jpeg->vfd_decoder->v4l2_dev = &jpeg->v4l2_dev; 1423 jpeg->vfd_decoder->v4l2_dev = &jpeg->v4l2_dev;
1406 /* Locking in file operations other than ioctl should be done by the driver,
1407 not the V4L2 core.
1408 This driver needs auditing so that this flag can be removed. */
1409 set_bit(V4L2_FL_LOCK_ALL_FOPS, &jpeg->vfd_decoder->flags);
1410 1424
1411 ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_GRABBER, -1); 1425 ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_GRABBER, -1);
1412 if (ret) { 1426 if (ret) {