Skip to content

Commit 010dc57

Browse files
Xu Yanggregkh
authored andcommitted
usb: gadget: uvc: fix interval_duration calculation
According to USB specification: For full-/high-speed isochronous endpoints, the bInterval value is used as the exponent for a 2^(bInterval-1) value. To correctly convert bInterval as interval_duration: interval_duration = 2^(bInterval-1) * frame_interval Because the unit of video->interval is 100ns, add a comment info to make it clear. Fixes: 48dbe73 ("usb: gadget: uvc: set req_size and n_requests based on the frame interval") Cc: stable@vger.kernel.org Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Xu Yang <xu.yang_2@nxp.com> Link: https://patch.msgid.link/20260113-uvc-gadget-fix-patch-v2-2-62950ef5bcb5@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2edc1ac commit 010dc57

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

drivers/usb/gadget/function/uvc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct uvc_video {
107107
unsigned int width;
108108
unsigned int height;
109109
unsigned int imagesize;
110-
unsigned int interval;
110+
unsigned int interval; /* in 100ns units */
111111
struct mutex mutex; /* protects frame parameters */
112112

113113
unsigned int uvc_num_requests;

drivers/usb/gadget/function/uvc_video.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ uvc_video_prep_requests(struct uvc_video *video)
499499
{
500500
struct uvc_device *uvc = container_of(video, struct uvc_device, video);
501501
struct usb_composite_dev *cdev = uvc->func.config->cdev;
502-
unsigned int interval_duration = video->ep->desc->bInterval * 1250;
502+
unsigned int interval_duration;
503503
unsigned int max_req_size, req_size, header_size;
504504
unsigned int nreq;
505505

@@ -513,8 +513,11 @@ uvc_video_prep_requests(struct uvc_video *video)
513513
return;
514514
}
515515

516+
interval_duration = 2 << (video->ep->desc->bInterval - 1);
516517
if (cdev->gadget->speed < USB_SPEED_HIGH)
517-
interval_duration = video->ep->desc->bInterval * 10000;
518+
interval_duration *= 10000;
519+
else
520+
interval_duration *= 1250;
518521

519522
nreq = DIV_ROUND_UP(video->interval, interval_duration);
520523

0 commit comments

Comments
 (0)