From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E28CF46AA78; Tue, 21 Jul 2026 15:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784648014; cv=none; b=sh9JcpqTsoTUX6rYln6GgyKzplTwZTZ8GwA/d1spD0kCdnn/R8yAQfMEGfnEL3CCz5unZODXaUeQvxoiOz/ARyCtAxL3ZRjO0zfYl58DtPIOZjFg1g9rNPiXn1I8L3HpRC8VgjdJLhlmYuvD3lhD4IvRQXDqPX3aYn4xXPj9SVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784648014; c=relaxed/simple; bh=yEX1Ma+OvwAp2Kk1nNgAcWGwgK+zaX5mBFsXv0x2/u4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MfgYs2D8bCPEVrd5S0uEMwCwZb+c/vx4coBBJ8w/Nxc4ml7EbV5VrlCT7sctSf0cydq42BHzuN88Gdn1g19FQC0vRyoEudYEHQ0OuZ4GcdGZcqvaKKi3PT2x54/alXDZ7oTj/x1K1QJLqBnnpZNvKaSvtHd5pV9AFPH+H1cnZYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Q08nT4iB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Q08nT4iB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 467C01F000E9; Tue, 21 Jul 2026 15:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784648012; bh=tjy1HdS+9gEETRLa/MV49Ohm4VGQ0ni1C8x0heOpVBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Q08nT4iB27D5vXEprJBtd4POcx4fgWaIDa/V+dd8La1voz5rW2YTkUutZ2tNEw0yw bkG4HFPxMswrQGogv9061C+4uuykduIF9fWdlM3PcJvRCLmGXdfkmURdhnZMUuuCih Kc3aw71rsHk51gxT+I0a1EuwPTJPlJvHF8OW3bcA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Ricardo Ribalda , Hans de Goede , Hans Verkuil Subject: [PATCH 7.1 0011/2077] media: uvcvideo: Fix buffer sequence in frame gaps Date: Tue, 21 Jul 2026 16:54:44 +0200 Message-ID: <20260721152552.930051796@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Ribalda commit 2f24ac8dd87983a55f0498898f34a5f2b735b802 upstream. In UVC, the FID flips with every frame. For every FID flip, we increase the stream sequence number. Now, if a FID flips multiple times and there is no data transferred between the flips, the buffer sequence number will be set to the value of the stream sequence number after the first flip. Userspace uses the buffer sequence number to determine if there have been missing frames. With the current behaviour, userspace will think that the gap is in the wrong location. This patch modifies uvc_video_decode_start() to provide the correct buffer sequence number and timestamp. Cc: stable@kernel.org Fixes: 650b95feee35 ("[media] uvcvideo: Generate discontinuous sequence numbers when frames are lost") Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_video.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1185,6 +1185,19 @@ static int uvc_video_decode_start(struct stream->sequence++; if (stream->sequence) uvc_video_stats_update(stream); + + /* + * On a FID flip initialize sequence number and timestamp. + * + * The driver already takes care of injecting FID flips for + * UVC_QUIRK_STREAM_NO_FID and UVC_QUIRK_MJPEG_NO_EOF. + */ + if (buf) { + buf->buf.field = V4L2_FIELD_NONE; + buf->buf.sequence = stream->sequence; + buf->buf.vb2_buf.timestamp = + ktime_to_ns(uvc_video_get_time()); + } } uvc_video_clock_decode(stream, buf, data, len); @@ -1225,10 +1238,6 @@ static int uvc_video_decode_start(struct return -ENODATA; } - buf->buf.field = V4L2_FIELD_NONE; - buf->buf.sequence = stream->sequence; - buf->buf.vb2_buf.timestamp = ktime_to_ns(uvc_video_get_time()); - /* TODO: Handle PTS and SCR. */ buf->state = UVC_BUF_STATE_ACTIVE; if (meta_buf)