From patchwork Mon Oct 3 10:16:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 12997419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8667AC433FE for ; Mon, 3 Oct 2022 10:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbiJCKQn (ORCPT ); Mon, 3 Oct 2022 06:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiJCKQm (ORCPT ); Mon, 3 Oct 2022 06:16:42 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1B422CE20 for ; Mon, 3 Oct 2022 03:16:40 -0700 (PDT) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DCD0B440; Mon, 3 Oct 2022 12:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664792197; bh=kmC8BNMznMK7bXklWmIHtSqUpJY+lR9xYFRDYIAlSiI=; h=From:To:Cc:Subject:Date:From; b=I4QCJxEtTNj4UGTbk983p/4rBaebfyndOVD0XjuT+DvTfMySMOm8KWQu4njDPVRzr oW3P3p5UpIJVYqHDfKUvQiu5+QVwBGoUkoDzk+ZG14e5arHpewnIXiAxu0g2Inz30r CXNLurziXwC06S1GYHjwzdQgBLD6buN5qC87T6bU= From: Daniel Scally To: linux-usb@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, kieran@linuxembedded.co.uk, balbi@kernel.org, gregkh@linuxfoundation.org, mgr@pengutronix.de, Daniel Scally Subject: [PATCH] uvc: gadget: uvc: Defer uvcg_complete_buffer() until .complete() Date: Mon, 3 Oct 2022 11:16:27 +0100 Message-Id: <20221003101627.144026-1-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Calling uvcg_complete_buffer() from uvc_video_encode_isoc() sometimes causes the final isoc packet for a video frame to be delayed long enough to cause the USB controller to drop it. The first isoc packet of the next video frame is then received by the host, which interprets the toggled FID bit correctly such that the stream continues without interruption, but the first frame will be missing the last isoc packet's worth of bytes. To fix the issue delay the call to uvcg_complete_buffer() until the usb_request's .complete() callback, as already happens when the data is encoded via uvc_video_encode_isoc_sg(). Signed-off-by: Daniel Scally Reviewed-by: Michael Grzeschik --- drivers/usb/gadget/function/uvc_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index c00ce0e91f5d..041819a655ed 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -194,6 +194,7 @@ static void uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video, struct uvc_buffer *buf) { + struct uvc_request *ureq = req->context; void *mem = req->buf; int len = video->req_size; int ret; @@ -213,7 +214,7 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video, video->queue.buf_used = 0; buf->state = UVC_BUF_STATE_DONE; list_del(&buf->queue); - uvcg_complete_buffer(&video->queue, buf); + ureq->last_buf = buf; video->fid ^= UVC_STREAM_FID; } }