Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: uvcvideo: Drop stream->mutex

Since commit c93d73c9c2cf ("media: uvcvideo: Use vb2 ioctl and fop
helpers"), the IOCTLs are serialized. Due to this there is no more need
to protect ctrl, cur_format or cur_frame from concurrent access.

Drop stream->mutex after thanking it for years of good service.

Use this opportunity to do fix some CodeStyle.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans de Goede <hansg@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Ricardo Ribalda and committed by
Hans Verkuil
97b6ff86 1ab40529

+11 -50
-4
drivers/media/usb/uvc/uvc_driver.c
··· 183 183 if (stream->async_wq) 184 184 destroy_workqueue(stream->async_wq); 185 185 186 - mutex_destroy(&stream->mutex); 187 - 188 186 usb_put_intf(stream->intf); 189 187 190 188 kfree(stream->formats); ··· 198 200 stream = kzalloc(sizeof(*stream), GFP_KERNEL); 199 201 if (stream == NULL) 200 202 return NULL; 201 - 202 - mutex_init(&stream->mutex); 203 203 204 204 stream->dev = dev; 205 205 stream->intf = usb_get_intf(intf);
+3 -7
drivers/media/usb/uvc/uvc_metadata.c
··· 99 99 * Metadata buffers would still be perfectly parseable, but it's more 100 100 * consistent and cleaner to disallow that. 101 101 */ 102 - mutex_lock(&stream->mutex); 103 - 104 102 if (vb2_is_busy(&stream->meta.queue.queue)) 105 - ret = -EBUSY; 106 - else 107 - stream->meta.format = fmt->dataformat; 103 + return -EBUSY; 108 104 109 - mutex_unlock(&stream->mutex); 105 + stream->meta.format = fmt->dataformat; 110 106 111 - return ret; 107 + return 0; 112 108 } 113 109 114 110 static int uvc_meta_v4l2_enum_formats(struct file *file, void *priv,
+8 -33
drivers/media/usb/uvc/uvc_v4l2.c
··· 329 329 * developers test their webcams with the Linux driver as well as with 330 330 * the Windows driver). 331 331 */ 332 - mutex_lock(&stream->mutex); 333 332 if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS) 334 333 probe->dwMaxVideoFrameSize = 335 334 stream->ctrl.dwMaxVideoFrameSize; 336 335 337 336 /* Probe the device. */ 338 337 ret = uvc_probe_video(stream, probe); 339 - mutex_unlock(&stream->mutex); 340 338 if (ret < 0) 341 339 return ret; 342 340 ··· 393 395 struct uvc_streaming *stream = handle->stream; 394 396 const struct uvc_format *format; 395 397 const struct uvc_frame *frame; 396 - int ret = 0; 397 398 398 399 if (fmt->type != stream->type) 399 400 return -EINVAL; 400 401 401 - mutex_lock(&stream->mutex); 402 402 format = stream->cur_format; 403 403 frame = stream->cur_frame; 404 404 405 - if (format == NULL || frame == NULL) { 406 - ret = -EINVAL; 407 - goto done; 408 - } 405 + if (!format || !frame) 406 + return -EINVAL; 409 407 410 408 fmt->fmt.pix.pixelformat = format->fcc; 411 409 fmt->fmt.pix.width = frame->wWidth; ··· 413 419 fmt->fmt.pix.xfer_func = format->xfer_func; 414 420 fmt->fmt.pix.ycbcr_enc = format->ycbcr_enc; 415 421 416 - done: 417 - mutex_unlock(&stream->mutex); 418 - return ret; 422 + return 0; 419 423 } 420 424 421 425 static int uvc_ioctl_s_fmt(struct file *file, void *priv, ··· 433 441 if (ret < 0) 434 442 return ret; 435 443 436 - mutex_lock(&stream->mutex); 437 - if (vb2_is_busy(&stream->queue.queue)) { 438 - ret = -EBUSY; 439 - goto done; 440 - } 444 + if (vb2_is_busy(&stream->queue.queue)) 445 + return -EBUSY; 441 446 442 447 stream->ctrl = probe; 443 448 stream->cur_format = format; 444 449 stream->cur_frame = frame; 445 450 446 - done: 447 - mutex_unlock(&stream->mutex); 448 - return ret; 451 + return 0; 449 452 } 450 453 451 454 static int uvc_ioctl_g_parm(struct file *file, void *priv, ··· 453 466 if (parm->type != stream->type) 454 467 return -EINVAL; 455 468 456 - mutex_lock(&stream->mutex); 457 469 numerator = stream->ctrl.dwFrameInterval; 458 - mutex_unlock(&stream->mutex); 459 - 460 470 denominator = 10000000; 461 471 v4l2_simplify_fraction(&numerator, &denominator, 8, 333); 462 472 ··· 503 519 uvc_dbg(stream->dev, FORMAT, "Setting frame interval to %u/%u (%u)\n", 504 520 timeperframe.numerator, timeperframe.denominator, interval); 505 521 506 - mutex_lock(&stream->mutex); 507 - 508 - if (uvc_queue_streaming(&stream->queue)) { 509 - mutex_unlock(&stream->mutex); 522 + if (uvc_queue_streaming(&stream->queue)) 510 523 return -EBUSY; 511 - } 512 524 513 525 format = stream->cur_format; 514 526 frame = stream->cur_frame; ··· 536 556 537 557 /* Probe the device with the new settings. */ 538 558 ret = uvc_probe_video(stream, &probe); 539 - if (ret < 0) { 540 - mutex_unlock(&stream->mutex); 559 + if (ret < 0) 541 560 return ret; 542 - } 543 561 544 562 stream->ctrl = probe; 545 563 stream->cur_frame = frame; 546 - mutex_unlock(&stream->mutex); 547 564 548 565 /* Return the actual frame period. */ 549 566 timeperframe.numerator = probe.dwFrameInterval; ··· 917 940 918 941 sel->r.left = 0; 919 942 sel->r.top = 0; 920 - mutex_lock(&stream->mutex); 921 943 sel->r.width = stream->cur_frame->wWidth; 922 944 sel->r.height = stream->cur_frame->wHeight; 923 - mutex_unlock(&stream->mutex); 924 945 925 946 return 0; 926 947 }
-6
drivers/media/usb/uvc/uvcvideo.h
··· 469 469 const struct uvc_format *cur_format; 470 470 const struct uvc_frame *cur_frame; 471 471 472 - /* 473 - * Protect access to ctrl, cur_format, cur_frame and hardware video 474 - * probe control. 475 - */ 476 - struct mutex mutex; 477 - 478 472 /* Buffers queue. */ 479 473 unsigned int frozen : 1; 480 474 struct uvc_video_queue queue;