Skip to content

Commit 840fb2c

Browse files
ribaldamchehab
authored andcommitted
media: uvcvideo: Remove duplicated cap/out code
The *_vid_cap and *_vid_out helpers seem to be identical: - Remove all the cap/out duplicated code. - Remove s/g_parm helpers - Reorder uvc_ioctl_ops And now that we are at it, fix a comment for uvc_acquire_privileges() Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 7309f3e commit 840fb2c

File tree

1 file changed

+43
-119
lines changed

1 file changed

+43
-119
lines changed

drivers/media/usb/uvc/uvc_v4l2.c

Lines changed: 43 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "uvcvideo.h"
2828

29+
static int uvc_acquire_privileges(struct uvc_fh *handle);
30+
2931
static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain,
3032
struct uvc_control_mapping *map,
3133
const struct uvc_xu_control_mapping *xmap)
@@ -361,9 +363,11 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream,
361363
return ret;
362364
}
363365

364-
static int uvc_v4l2_get_format(struct uvc_streaming *stream,
365-
struct v4l2_format *fmt)
366+
static int uvc_ioctl_g_fmt(struct file *file, void *fh,
367+
struct v4l2_format *fmt)
366368
{
369+
struct uvc_fh *handle = fh;
370+
struct uvc_streaming *stream = handle->stream;
367371
const struct uvc_format *format;
368372
const struct uvc_frame *frame;
369373
int ret = 0;
@@ -395,14 +399,20 @@ static int uvc_v4l2_get_format(struct uvc_streaming *stream,
395399
return ret;
396400
}
397401

398-
static int uvc_v4l2_set_format(struct uvc_streaming *stream,
399-
struct v4l2_format *fmt)
402+
static int uvc_ioctl_s_fmt(struct file *file, void *fh,
403+
struct v4l2_format *fmt)
400404
{
405+
struct uvc_fh *handle = fh;
406+
struct uvc_streaming *stream = handle->stream;
401407
struct uvc_streaming_control probe;
402408
const struct uvc_format *format;
403409
const struct uvc_frame *frame;
404410
int ret;
405411

412+
ret = uvc_acquire_privileges(handle);
413+
if (ret < 0)
414+
return ret;
415+
406416
if (fmt->type != stream->type)
407417
return -EINVAL;
408418

@@ -426,10 +436,12 @@ static int uvc_v4l2_set_format(struct uvc_streaming *stream,
426436
return ret;
427437
}
428438

429-
static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
430-
struct v4l2_streamparm *parm)
439+
static int uvc_ioctl_g_parm(struct file *file, void *fh,
440+
struct v4l2_streamparm *parm)
431441
{
432442
u32 numerator, denominator;
443+
struct uvc_fh *handle = fh;
444+
struct uvc_streaming *stream = handle->stream;
433445

434446
if (parm->type != stream->type)
435447
return -EINVAL;
@@ -461,9 +473,11 @@ static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream,
461473
return 0;
462474
}
463475

464-
static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
465-
struct v4l2_streamparm *parm)
476+
static int uvc_ioctl_s_parm(struct file *file, void *fh,
477+
struct v4l2_streamparm *parm)
466478
{
479+
struct uvc_fh *handle = fh;
480+
struct uvc_streaming *stream = handle->stream;
467481
struct uvc_streaming_control probe;
468482
struct v4l2_fract timeperframe;
469483
const struct uvc_format *format;
@@ -472,6 +486,10 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
472486
unsigned int i;
473487
int ret;
474488

489+
ret = uvc_acquire_privileges(handle);
490+
if (ret < 0)
491+
return ret;
492+
475493
if (parm->type != stream->type)
476494
return -EINVAL;
477495

@@ -573,6 +591,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
573591
* - VIDIOC_S_INPUT
574592
* - VIDIOC_S_PARM
575593
* - VIDIOC_S_FMT
594+
* - VIDIOC_CREATE_BUFS
576595
* - VIDIOC_REQBUFS
577596
*/
578597
static int uvc_acquire_privileges(struct uvc_fh *handle)
@@ -685,11 +704,13 @@ static int uvc_ioctl_querycap(struct file *file, void *fh,
685704
return 0;
686705
}
687706

688-
static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream,
707+
static int uvc_ioctl_enum_fmt(struct file *file, void *fh,
689708
struct v4l2_fmtdesc *fmt)
690709
{
691-
const struct uvc_format *format;
710+
struct uvc_fh *handle = fh;
711+
struct uvc_streaming *stream = handle->stream;
692712
enum v4l2_buf_type type = fmt->type;
713+
const struct uvc_format *format;
693714
u32 index = fmt->index;
694715

695716
if (fmt->type != stream->type || fmt->index >= stream->nformats)
@@ -707,82 +728,8 @@ static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream,
707728
return 0;
708729
}
709730

710-
static int uvc_ioctl_enum_fmt_vid_cap(struct file *file, void *fh,
711-
struct v4l2_fmtdesc *fmt)
712-
{
713-
struct uvc_fh *handle = fh;
714-
struct uvc_streaming *stream = handle->stream;
715-
716-
return uvc_ioctl_enum_fmt(stream, fmt);
717-
}
718-
719-
static int uvc_ioctl_enum_fmt_vid_out(struct file *file, void *fh,
720-
struct v4l2_fmtdesc *fmt)
721-
{
722-
struct uvc_fh *handle = fh;
723-
struct uvc_streaming *stream = handle->stream;
724-
725-
return uvc_ioctl_enum_fmt(stream, fmt);
726-
}
727-
728-
static int uvc_ioctl_g_fmt_vid_cap(struct file *file, void *fh,
729-
struct v4l2_format *fmt)
730-
{
731-
struct uvc_fh *handle = fh;
732-
struct uvc_streaming *stream = handle->stream;
733-
734-
return uvc_v4l2_get_format(stream, fmt);
735-
}
736-
737-
static int uvc_ioctl_g_fmt_vid_out(struct file *file, void *fh,
738-
struct v4l2_format *fmt)
739-
{
740-
struct uvc_fh *handle = fh;
741-
struct uvc_streaming *stream = handle->stream;
742-
743-
return uvc_v4l2_get_format(stream, fmt);
744-
}
745-
746-
static int uvc_ioctl_s_fmt_vid_cap(struct file *file, void *fh,
747-
struct v4l2_format *fmt)
748-
{
749-
struct uvc_fh *handle = fh;
750-
struct uvc_streaming *stream = handle->stream;
751-
int ret;
752-
753-
ret = uvc_acquire_privileges(handle);
754-
if (ret < 0)
755-
return ret;
756-
757-
return uvc_v4l2_set_format(stream, fmt);
758-
}
759-
760-
static int uvc_ioctl_s_fmt_vid_out(struct file *file, void *fh,
761-
struct v4l2_format *fmt)
762-
{
763-
struct uvc_fh *handle = fh;
764-
struct uvc_streaming *stream = handle->stream;
765-
int ret;
766-
767-
ret = uvc_acquire_privileges(handle);
768-
if (ret < 0)
769-
return ret;
770-
771-
return uvc_v4l2_set_format(stream, fmt);
772-
}
773-
774-
static int uvc_ioctl_try_fmt_vid_cap(struct file *file, void *fh,
775-
struct v4l2_format *fmt)
776-
{
777-
struct uvc_fh *handle = fh;
778-
struct uvc_streaming *stream = handle->stream;
779-
struct uvc_streaming_control probe;
780-
781-
return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL);
782-
}
783-
784-
static int uvc_ioctl_try_fmt_vid_out(struct file *file, void *fh,
785-
struct v4l2_format *fmt)
731+
static int uvc_ioctl_try_fmt(struct file *file, void *fh,
732+
struct v4l2_format *fmt)
786733
{
787734
struct uvc_fh *handle = fh;
788735
struct uvc_streaming *stream = handle->stream;
@@ -1212,29 +1159,6 @@ static int uvc_ioctl_g_selection(struct file *file, void *fh,
12121159
return 0;
12131160
}
12141161

1215-
static int uvc_ioctl_g_parm(struct file *file, void *fh,
1216-
struct v4l2_streamparm *parm)
1217-
{
1218-
struct uvc_fh *handle = fh;
1219-
struct uvc_streaming *stream = handle->stream;
1220-
1221-
return uvc_v4l2_get_streamparm(stream, parm);
1222-
}
1223-
1224-
static int uvc_ioctl_s_parm(struct file *file, void *fh,
1225-
struct v4l2_streamparm *parm)
1226-
{
1227-
struct uvc_fh *handle = fh;
1228-
struct uvc_streaming *stream = handle->stream;
1229-
int ret;
1230-
1231-
ret = uvc_acquire_privileges(handle);
1232-
if (ret < 0)
1233-
return ret;
1234-
1235-
return uvc_v4l2_set_streamparm(stream, parm);
1236-
}
1237-
12381162
static int uvc_ioctl_enum_framesizes(struct file *file, void *fh,
12391163
struct v4l2_frmsizeenum *fsize)
12401164
{
@@ -1543,15 +1467,17 @@ static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
15431467
#endif
15441468

15451469
const struct v4l2_ioctl_ops uvc_ioctl_ops = {
1470+
.vidioc_g_fmt_vid_cap = uvc_ioctl_g_fmt,
1471+
.vidioc_g_fmt_vid_out = uvc_ioctl_g_fmt,
1472+
.vidioc_s_fmt_vid_cap = uvc_ioctl_s_fmt,
1473+
.vidioc_s_fmt_vid_out = uvc_ioctl_s_fmt,
1474+
.vidioc_g_parm = uvc_ioctl_g_parm,
1475+
.vidioc_s_parm = uvc_ioctl_s_parm,
15461476
.vidioc_querycap = uvc_ioctl_querycap,
1547-
.vidioc_enum_fmt_vid_cap = uvc_ioctl_enum_fmt_vid_cap,
1548-
.vidioc_enum_fmt_vid_out = uvc_ioctl_enum_fmt_vid_out,
1549-
.vidioc_g_fmt_vid_cap = uvc_ioctl_g_fmt_vid_cap,
1550-
.vidioc_g_fmt_vid_out = uvc_ioctl_g_fmt_vid_out,
1551-
.vidioc_s_fmt_vid_cap = uvc_ioctl_s_fmt_vid_cap,
1552-
.vidioc_s_fmt_vid_out = uvc_ioctl_s_fmt_vid_out,
1553-
.vidioc_try_fmt_vid_cap = uvc_ioctl_try_fmt_vid_cap,
1554-
.vidioc_try_fmt_vid_out = uvc_ioctl_try_fmt_vid_out,
1477+
.vidioc_enum_fmt_vid_cap = uvc_ioctl_enum_fmt,
1478+
.vidioc_enum_fmt_vid_out = uvc_ioctl_enum_fmt,
1479+
.vidioc_try_fmt_vid_cap = uvc_ioctl_try_fmt,
1480+
.vidioc_try_fmt_vid_out = uvc_ioctl_try_fmt,
15551481
.vidioc_reqbufs = uvc_ioctl_reqbufs,
15561482
.vidioc_querybuf = uvc_ioctl_querybuf,
15571483
.vidioc_qbuf = uvc_ioctl_qbuf,
@@ -1570,8 +1496,6 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = {
15701496
.vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls,
15711497
.vidioc_querymenu = uvc_ioctl_querymenu,
15721498
.vidioc_g_selection = uvc_ioctl_g_selection,
1573-
.vidioc_g_parm = uvc_ioctl_g_parm,
1574-
.vidioc_s_parm = uvc_ioctl_s_parm,
15751499
.vidioc_enum_framesizes = uvc_ioctl_enum_framesizes,
15761500
.vidioc_enum_frameintervals = uvc_ioctl_enum_frameintervals,
15771501
.vidioc_subscribe_event = uvc_ioctl_subscribe_event,

0 commit comments

Comments
 (0)