Linux USB
 help / color / mirror / Atom feed
From: Keisuke Tsukuda <tkdkei@outlook.jp>
To: "nkapron@google.com" <nkapron@google.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"liuc63@xiaopeng.com" <liuc63@xiaopeng.com>,
	"mgr@kernel.org" <mgr@kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH] usb: gadget: uvc: preserve the interval on rejected S_PARM
Date: Fri, 4 Dec 2026 07:02:45 +0000	[thread overview]
Message-ID: <20261204070239.61791-1-tkdkei@outlook.jp> (raw)

Commit 087ed08145e4 ("usb: gadget: uvc: reject zero interval in
uvc_v4l2_s_parm()") added a check for a zero frame interval, but the
function stores the converted interval before that check. S_PARM with
timeperframe 0/1 therefore returns -EINVAL while leaving
video->interval at zero. A later isochronous STREAMON computes zero
requests and divides by zero when sizing them.

Check the converted interval before storing it, so a rejected request
leaves the previous interval unchanged.

Fixes: 087ed08145e4 ("usb: gadget: uvc: reject zero interval in uvc_v4l2_s_parm()")
Cc: stable@vger.kernel.org
Signed-off-by: Keisuke Tsukuda <tkdkei@outlook.jp>

---
Tested on a Tinker Board 3N (DWC3) at SuperSpeed. Before the change,
S_PARM(0/1) returned EINVAL but G_PARM changed from 1/60 to 0/1.
With the change, S_PARM still returned EINVAL and G_PARM remained
at 1/60. A subsequent 160x120 YUYV stream reached the host.

diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index e9b9288c5..cad86c356 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -359,19 +359,21 @@ static int uvc_v4l2_s_parm(struct file *file, void *fh,
 	struct uvc_device *uvc = video_get_drvdata(vdev);
 	struct uvc_video *video = &uvc->video;
 	struct v4l2_fract timeperframe;
+	u32 interval;
 
 	if (!V4L2_TYPE_IS_OUTPUT(parm->type))
 		return -EINVAL;
 
 	timeperframe = parm->parm.output.timeperframe;
 
-	video->interval = v4l2_fraction_to_interval(timeperframe.numerator,
-						    timeperframe.denominator);
+	interval = v4l2_fraction_to_interval(timeperframe.numerator,
+					     timeperframe.denominator);
 
-	if (!video->interval) {
+	if (!interval) {
 		uvcg_dbg(&uvc->func, "Invalid zero interval, rejecting\n");
 		return -EINVAL;
 	}
+	video->interval = interval;
 
 	uvcg_dbg(&uvc->func, "Setting frame interval to %u/%u (%u)\n",
 		 timeperframe.numerator, timeperframe.denominator,

                 reply	other threads:[~2026-12-04  7:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204070239.61791-1-tkdkei@outlook.jp \
    --to=tkdkei@outlook.jp \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=liuc63@xiaopeng.com \
    --cc=mgr@kernel.org \
    --cc=nkapron@google.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox