Skip to content

Commit 97b6ff8

Browse files
ribaldaHans Verkuil
authored andcommitted
media: uvcvideo: Drop stream->mutex
Since commit c93d73c ("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>
1 parent 1ab4052 commit 97b6ff8

4 files changed

Lines changed: 11 additions & 50 deletions

File tree

drivers/media/usb/uvc/uvc_driver.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ static void uvc_stream_delete(struct uvc_streaming *stream)
183183
if (stream->async_wq)
184184
destroy_workqueue(stream->async_wq);
185185

186-
mutex_destroy(&stream->mutex);
187-
188186
usb_put_intf(stream->intf);
189187

190188
kfree(stream->formats);
@@ -201,8 +199,6 @@ static struct uvc_streaming *uvc_stream_new(struct uvc_device *dev,
201199
if (stream == NULL)
202200
return NULL;
203201

204-
mutex_init(&stream->mutex);
205-
206202
stream->dev = dev;
207203
stream->intf = usb_get_intf(intf);
208204
stream->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;

drivers/media/usb/uvc/uvc_metadata.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,12 @@ static int uvc_meta_v4l2_set_format(struct file *file, void *priv,
9999
* Metadata buffers would still be perfectly parseable, but it's more
100100
* consistent and cleaner to disallow that.
101101
*/
102-
mutex_lock(&stream->mutex);
103-
104102
if (vb2_is_busy(&stream->meta.queue.queue))
105-
ret = -EBUSY;
106-
else
107-
stream->meta.format = fmt->dataformat;
103+
return -EBUSY;
108104

109-
mutex_unlock(&stream->mutex);
105+
stream->meta.format = fmt->dataformat;
110106

111-
return ret;
107+
return 0;
112108
}
113109

114110
static int uvc_meta_v4l2_enum_formats(struct file *file, void *priv,

drivers/media/usb/uvc/uvc_v4l2.c

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,12 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,
329329
* developers test their webcams with the Linux driver as well as with
330330
* the Windows driver).
331331
*/
332-
mutex_lock(&stream->mutex);
333332
if (stream->dev->quirks & UVC_QUIRK_PROBE_EXTRAFIELDS)
334333
probe->dwMaxVideoFrameSize =
335334
stream->ctrl.dwMaxVideoFrameSize;
336335

337336
/* Probe the device. */
338337
ret = uvc_probe_video(stream, probe);
339-
mutex_unlock(&stream->mutex);
340338
if (ret < 0)
341339
return ret;
342340

@@ -395,19 +393,15 @@ static int uvc_ioctl_g_fmt(struct file *file, void *priv,
395393
struct uvc_streaming *stream = handle->stream;
396394
const struct uvc_format *format;
397395
const struct uvc_frame *frame;
398-
int ret = 0;
399396

400397
if (fmt->type != stream->type)
401398
return -EINVAL;
402399

403-
mutex_lock(&stream->mutex);
404400
format = stream->cur_format;
405401
frame = stream->cur_frame;
406402

407-
if (format == NULL || frame == NULL) {
408-
ret = -EINVAL;
409-
goto done;
410-
}
403+
if (!format || !frame)
404+
return -EINVAL;
411405

412406
fmt->fmt.pix.pixelformat = format->fcc;
413407
fmt->fmt.pix.width = frame->wWidth;
@@ -419,9 +413,7 @@ static int uvc_ioctl_g_fmt(struct file *file, void *priv,
419413
fmt->fmt.pix.xfer_func = format->xfer_func;
420414
fmt->fmt.pix.ycbcr_enc = format->ycbcr_enc;
421415

422-
done:
423-
mutex_unlock(&stream->mutex);
424-
return ret;
416+
return 0;
425417
}
426418

427419
static int uvc_ioctl_s_fmt(struct file *file, void *priv,
@@ -441,19 +433,14 @@ static int uvc_ioctl_s_fmt(struct file *file, void *priv,
441433
if (ret < 0)
442434
return ret;
443435

444-
mutex_lock(&stream->mutex);
445-
if (vb2_is_busy(&stream->queue.queue)) {
446-
ret = -EBUSY;
447-
goto done;
448-
}
436+
if (vb2_is_busy(&stream->queue.queue))
437+
return -EBUSY;
449438

450439
stream->ctrl = probe;
451440
stream->cur_format = format;
452441
stream->cur_frame = frame;
453442

454-
done:
455-
mutex_unlock(&stream->mutex);
456-
return ret;
443+
return 0;
457444
}
458445

459446
static int uvc_ioctl_g_parm(struct file *file, void *priv,
@@ -466,10 +453,7 @@ static int uvc_ioctl_g_parm(struct file *file, void *priv,
466453
if (parm->type != stream->type)
467454
return -EINVAL;
468455

469-
mutex_lock(&stream->mutex);
470456
numerator = stream->ctrl.dwFrameInterval;
471-
mutex_unlock(&stream->mutex);
472-
473457
denominator = 10000000;
474458
v4l2_simplify_fraction(&numerator, &denominator, 8, 333);
475459

@@ -519,12 +503,8 @@ static int uvc_ioctl_s_parm(struct file *file, void *priv,
519503
uvc_dbg(stream->dev, FORMAT, "Setting frame interval to %u/%u (%u)\n",
520504
timeperframe.numerator, timeperframe.denominator, interval);
521505

522-
mutex_lock(&stream->mutex);
523-
524-
if (uvc_queue_streaming(&stream->queue)) {
525-
mutex_unlock(&stream->mutex);
506+
if (uvc_queue_streaming(&stream->queue))
526507
return -EBUSY;
527-
}
528508

529509
format = stream->cur_format;
530510
frame = stream->cur_frame;
@@ -556,14 +536,11 @@ static int uvc_ioctl_s_parm(struct file *file, void *priv,
556536

557537
/* Probe the device with the new settings. */
558538
ret = uvc_probe_video(stream, &probe);
559-
if (ret < 0) {
560-
mutex_unlock(&stream->mutex);
539+
if (ret < 0)
561540
return ret;
562-
}
563541

564542
stream->ctrl = probe;
565543
stream->cur_frame = frame;
566-
mutex_unlock(&stream->mutex);
567544

568545
/* Return the actual frame period. */
569546
timeperframe.numerator = probe.dwFrameInterval;
@@ -940,10 +917,8 @@ static int uvc_ioctl_g_selection(struct file *file, void *priv,
940917

941918
sel->r.left = 0;
942919
sel->r.top = 0;
943-
mutex_lock(&stream->mutex);
944920
sel->r.width = stream->cur_frame->wWidth;
945921
sel->r.height = stream->cur_frame->wHeight;
946-
mutex_unlock(&stream->mutex);
947922

948923
return 0;
949924
}

drivers/media/usb/uvc/uvcvideo.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,6 @@ struct uvc_streaming {
469469
const struct uvc_format *cur_format;
470470
const struct uvc_frame *cur_frame;
471471

472-
/*
473-
* Protect access to ctrl, cur_format, cur_frame and hardware video
474-
* probe control.
475-
*/
476-
struct mutex mutex;
477-
478472
/* Buffers queue. */
479473
unsigned int frozen : 1;
480474
struct uvc_video_queue queue;

0 commit comments

Comments
 (0)