From nobody Fri Dec 27 00:02:40 2024 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 927861A255A for ; Fri, 29 Nov 2024 19:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908511; cv=none; b=d46paWxYLhxwq5zDMNVHkMlRS99fw0j4jrp3/k9DW380oM1319ZABGsJ3QUOVqPXHkvQKjDXKlUtH/AZsFWB9I560UYT+pPqMWIAjeU65OqcTAJu244NCrhA0tofvcL6pDymR5i1GlhR+GlOpoAojhknPH3JfNCbWFI5JUk5cJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908511; c=relaxed/simple; bh=Cgcbp6qez5SBKxJsZZNqx/40+s6dzeX0l7p170v6KME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=NOXdfsgHbD92mvRGHShDlLOsk9E8KtFA7YUmXNH58OlqsEbAe0YYsfWZ8bq7q3t98wH0RQGgSeVYDc4IhklWJhSm7clkZKTFZxNeZemP9cGP5rANg1Fgp2MVmB4VTtQ6prq23SeOsz/CNxV162yiMPL8ef80dlmGzHbYsgGr7g8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=YMKiYfRV; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YMKiYfRV" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7b66a740de4so155726985a.3 for ; Fri, 29 Nov 2024 11:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732908508; x=1733513308; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=nMjLrhak7emeEGQAr5hNiFOWhZ4QE7VyWOQvbrmhiU4=; b=YMKiYfRVo25q37THIG8MQj01vtYKTv5JYFpEn2vZO0yDw0Lq3JTA52CUdLaD/H5fKr LgWpKe5UvhH+rE9k5tlSDTmyDAnmn1ywJdPrS+Q7n4xgAKulT469JiMOnzjq3wO8XvZV 0dw5YjOdb8BjZ6fyivW+/2qrNNUYpSPZ75XPo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732908508; x=1733513308; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nMjLrhak7emeEGQAr5hNiFOWhZ4QE7VyWOQvbrmhiU4=; b=Ntc1lRlZODcjEhLjsIKkG5548vY/LS0wKGdG4Wj0+k00TmlRw2P10hsSVzXkKCfQ/W 6h9xCrQZrT8VyjILk0Bsuq1sn7aH5vaaX7FHHp4Mv6q2IQvJsKTkeaeirss9RE2eqYj3 sdX1JRE+MnfQOZ6rY/iYuoDVdrwNWfoZEo+UJv08jcByMjjBDlhAYd90XznSHdSMzY5W m558bjH+bbcdNp+FwD6o05r05UAKIrSL59i3shiEzh+tgcrA+iGzypv6Az4fWyvX/VQe SZ+7c8+TxD76ncq0JZneQVN3jQewZ2Yid2ADSBsxL/r8kCvwXucfzbMLVMshKhM9Wq4H v21g== X-Forwarded-Encrypted: i=1; AJvYcCUo+mNNsLHVCI70zRZgJTv+Iv0pg2giPSYhpaSCysonVgVvNM+hpEI2ytMmaTrTdgm1GRHViVxUaN7enWI=@vger.kernel.org X-Gm-Message-State: AOJu0YwRALB/qmdkBjF0/CASoOc+5nrLK+v7VWjBxTzlC/WIjU1Q17Ul rWkHNIb2QMODoadVdmJI4MjRSqUTon139mOaz8FjZvDs/tHYbd0D86PL/bJ0ow== X-Gm-Gg: ASbGncudKbaXpQpKVciAcxoXXe41dsqiUoZ7EboBbhy/A3FjfO+To9Z7xFRoQP3mA9k FRdB0HzSATXY6CxPUnjRXnPlfC4th9ztO2/Tpift1C0xnkPcRdo1tgCcp1Uv1gKrRJVGbrPbEKy WEhPNyi5J9tvL17t6vJIL02+eDZwG4WQCe112yB6ZRUyu4niYMzO2Sf6/U5yB1L7I4YBeUPTfmR Cr/3RguEaAuHANow8zad1Cv7KzsLZrM89e1pm/s1wq021AK/cJbVp3cj4gKEqei2QDNQAIWQKvk KWLQVjQpUNg4QWFLrNcPnK1m X-Google-Smtp-Source: AGHT+IGuCDNyzHI8S9pwqB2Ms7ffUr3w3ETlMCIDqHDQA3SZ/AAMCR53hhJ2/xIYpkwRNeRhRDlG+A== X-Received: by 2002:a05:620a:2794:b0:7ae:310a:84e5 with SMTP id af79cd13be357-7b67c2525b8mr1853428585a.8.1732908508517; Fri, 29 Nov 2024 11:28:28 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b6849b7275sm165318885a.105.2024.11.29.11.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 11:28:27 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 19:28:26 +0000 Subject: [PATCH v2] media: uvcvideo: Remove duplicated cap/out code Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241129-uvc-dup-cap-out-v2-1-596cb9bdd5e8@chromium.org> X-B4-Tracking: v=1; b=H4sIANkVSmcC/3WNOw7CMBBErxJtzSJ/EEhU3AOl8I94i8TROrZAk e+OSY+meiPNmx1yYAoZ7sMOHCplSksHdRrARbNMAcl3BiXURUp1w1Id+rKiMyumsuHVCO2EDFo YDX21cnjR+zA+x86R8pb4cxxU+Wv/u6rEHuud8coba8XDRU4zlfmceIKxtfYFbddg9rEAAAA= To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 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() Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- Unless I miss something, cap and out helpers are identical. So there is no need to duplicate code --- Changes in v2: - Add missing acquire_privileges. - Also remove helper for s/g_parm. - Reorder callbacks. - Link to v1: https://lore.kernel.org/r/20241127-uvc-dup-cap-out-v1-1-1bdca= d2dabb0@chromium.org --- drivers/media/usb/uvc/uvc_v4l2.c | 162 +++++++++++------------------------= ---- 1 file changed, 43 insertions(+), 119 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 97c5407f6603..42f0f8a89865 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -26,6 +26,8 @@ =20 #include "uvcvideo.h" =20 +static int uvc_acquire_privileges(struct uvc_fh *handle); + static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain, struct uvc_control_mapping *map, const struct uvc_xu_control_mapping *xmap) @@ -361,9 +363,11 @@ static int uvc_v4l2_try_format(struct uvc_streaming *s= tream, return ret; } =20 -static int uvc_v4l2_get_format(struct uvc_streaming *stream, - struct v4l2_format *fmt) +static int uvc_ioctl_g_fmt(struct file *file, void *fh, + struct v4l2_format *fmt) { + struct uvc_fh *handle =3D fh; + struct uvc_streaming *stream =3D handle->stream; const struct uvc_format *format; const struct uvc_frame *frame; int ret =3D 0; @@ -395,14 +399,20 @@ static int uvc_v4l2_get_format(struct uvc_streaming *= stream, return ret; } =20 -static int uvc_v4l2_set_format(struct uvc_streaming *stream, - struct v4l2_format *fmt) +static int uvc_ioctl_s_fmt(struct file *file, void *fh, + struct v4l2_format *fmt) { + struct uvc_fh *handle =3D fh; + struct uvc_streaming *stream =3D handle->stream; struct uvc_streaming_control probe; const struct uvc_format *format; const struct uvc_frame *frame; int ret; =20 + ret =3D uvc_acquire_privileges(handle); + if (ret) + return ret; + if (fmt->type !=3D stream->type) return -EINVAL; =20 @@ -426,10 +436,12 @@ static int uvc_v4l2_set_format(struct uvc_streaming *= stream, return ret; } =20 -static int uvc_v4l2_get_streamparm(struct uvc_streaming *stream, - struct v4l2_streamparm *parm) +static int uvc_ioctl_g_parm(struct file *file, void *fh, + struct v4l2_streamparm *parm) { u32 numerator, denominator; + struct uvc_fh *handle =3D fh; + struct uvc_streaming *stream =3D handle->stream; =20 if (parm->type !=3D stream->type) return -EINVAL; @@ -461,9 +473,11 @@ static int uvc_v4l2_get_streamparm(struct uvc_streamin= g *stream, return 0; } =20 -static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream, - struct v4l2_streamparm *parm) +static int uvc_ioctl_s_parm(struct file *file, void *fh, + struct v4l2_streamparm *parm) { + struct uvc_fh *handle =3D fh; + struct uvc_streaming *stream =3D handle->stream; struct uvc_streaming_control probe; struct v4l2_fract timeperframe; const struct uvc_format *format; @@ -472,6 +486,10 @@ static int uvc_v4l2_set_streamparm(struct uvc_streamin= g *stream, unsigned int i; int ret; =20 + ret =3D uvc_acquire_privileges(handle); + if (ret < 0) + return ret; + if (parm->type !=3D stream->type) return -EINVAL; =20 @@ -573,6 +591,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming= *stream, * - VIDIOC_S_INPUT * - VIDIOC_S_PARM * - VIDIOC_S_FMT + * - VIDIOC_CREATE_BUFS * - VIDIOC_REQBUFS */ static int uvc_acquire_privileges(struct uvc_fh *handle) @@ -685,11 +704,13 @@ static int uvc_ioctl_querycap(struct file *file, void= *fh, return 0; } =20 -static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream, +static int uvc_ioctl_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *fmt) { - const struct uvc_format *format; + struct uvc_fh *handle =3D fh; + struct uvc_streaming *stream =3D handle->stream; enum v4l2_buf_type type =3D fmt->type; + const struct uvc_format *format; u32 index =3D fmt->index; =20 if (fmt->type !=3D stream->type || fmt->index >=3D stream->nformats) @@ -707,82 +728,8 @@ static int uvc_ioctl_enum_fmt(struct uvc_streaming *st= ream, return 0; } =20 -static int uvc_ioctl_enum_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_fmtdesc *fmt) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - return uvc_ioctl_enum_fmt(stream, fmt); -} - -static int uvc_ioctl_enum_fmt_vid_out(struct file *file, void *fh, - struct v4l2_fmtdesc *fmt) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - return uvc_ioctl_enum_fmt(stream, fmt); -} - -static int uvc_ioctl_g_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - return uvc_v4l2_get_format(stream, fmt); -} - -static int uvc_ioctl_g_fmt_vid_out(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - return uvc_v4l2_get_format(stream, fmt); -} - -static int uvc_ioctl_s_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_v4l2_set_format(stream, fmt); -} - -static int uvc_ioctl_s_fmt_vid_out(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_v4l2_set_format(stream, fmt); -} - -static int uvc_ioctl_try_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - struct uvc_streaming_control probe; - - return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); -} - -static int uvc_ioctl_try_fmt_vid_out(struct file *file, void *fh, - struct v4l2_format *fmt) +static int uvc_ioctl_try_fmt(struct file *file, void *fh, + struct v4l2_format *fmt) { struct uvc_fh *handle =3D fh; struct uvc_streaming *stream =3D handle->stream; @@ -1212,29 +1159,6 @@ static int uvc_ioctl_g_selection(struct file *file, = void *fh, return 0; } =20 -static int uvc_ioctl_g_parm(struct file *file, void *fh, - struct v4l2_streamparm *parm) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - return uvc_v4l2_get_streamparm(stream, parm); -} - -static int uvc_ioctl_s_parm(struct file *file, void *fh, - struct v4l2_streamparm *parm) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_v4l2_set_streamparm(stream, parm); -} - static int uvc_ioctl_enum_framesizes(struct file *file, void *fh, struct v4l2_frmsizeenum *fsize) { @@ -1543,15 +1467,17 @@ static unsigned long uvc_v4l2_get_unmapped_area(str= uct file *file, #endif =20 const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { + .vidioc_g_fmt_vid_cap =3D uvc_ioctl_g_fmt, + .vidioc_g_fmt_vid_out =3D uvc_ioctl_g_fmt, + .vidioc_s_fmt_vid_cap =3D uvc_ioctl_s_fmt, + .vidioc_s_fmt_vid_out =3D uvc_ioctl_s_fmt, + .vidioc_g_parm =3D uvc_ioctl_g_parm, + .vidioc_s_parm =3D uvc_ioctl_s_parm, .vidioc_querycap =3D uvc_ioctl_querycap, - .vidioc_enum_fmt_vid_cap =3D uvc_ioctl_enum_fmt_vid_cap, - .vidioc_enum_fmt_vid_out =3D uvc_ioctl_enum_fmt_vid_out, - .vidioc_g_fmt_vid_cap =3D uvc_ioctl_g_fmt_vid_cap, - .vidioc_g_fmt_vid_out =3D uvc_ioctl_g_fmt_vid_out, - .vidioc_s_fmt_vid_cap =3D uvc_ioctl_s_fmt_vid_cap, - .vidioc_s_fmt_vid_out =3D uvc_ioctl_s_fmt_vid_out, - .vidioc_try_fmt_vid_cap =3D uvc_ioctl_try_fmt_vid_cap, - .vidioc_try_fmt_vid_out =3D uvc_ioctl_try_fmt_vid_out, + .vidioc_enum_fmt_vid_cap =3D uvc_ioctl_enum_fmt, + .vidioc_enum_fmt_vid_out =3D uvc_ioctl_enum_fmt, + .vidioc_try_fmt_vid_cap =3D uvc_ioctl_try_fmt, + .vidioc_try_fmt_vid_out =3D uvc_ioctl_try_fmt, .vidioc_reqbufs =3D uvc_ioctl_reqbufs, .vidioc_querybuf =3D uvc_ioctl_querybuf, .vidioc_qbuf =3D uvc_ioctl_qbuf, @@ -1570,8 +1496,6 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { .vidioc_try_ext_ctrls =3D uvc_ioctl_try_ext_ctrls, .vidioc_querymenu =3D uvc_ioctl_querymenu, .vidioc_g_selection =3D uvc_ioctl_g_selection, - .vidioc_g_parm =3D uvc_ioctl_g_parm, - .vidioc_s_parm =3D uvc_ioctl_s_parm, .vidioc_enum_framesizes =3D uvc_ioctl_enum_framesizes, .vidioc_enum_frameintervals =3D uvc_ioctl_enum_frameintervals, .vidioc_subscribe_event =3D uvc_ioctl_subscribe_event, --- base-commit: 72ad4ff638047bbbdf3232178fea4bec1f429319 change-id: 20241127-uvc-dup-cap-out-6a03c01e30a3 Best regards, --=20 Ricardo Ribalda