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 38D3B46C4AC; Tue, 21 Jul 2026 17:38:11 +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=1784655494; cv=none; b=epGmfvf+51wRNkMOjU4I68DpZ5TU5DkcQTlT7ML1bYVPMrvh6jbR/K+gSoZSbSv9gHR974seKkwEcWtU3/VXUUIF72/RwqCaWyTy7tknapqPNBTySAVnvlLaMX/YKJKJZuSrSO9uhmw+uOW7vOsU97vWt5sgtaENFY0YjiLwJMQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784655494; c=relaxed/simple; bh=sVaiM4Fvd4dCZJ3R9W/fVYaiDJBXwXDxsfTr4k4MMDI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B1F5p4TW1xT5JJw+RchH8AQDeBnbmgl4y1Un5M20I0G9BJlGbOglz79EOSScJ1ZBsgqkmb2NsTjGWQpz4BRzOEMPHf6HVAF4Njz24NG6P1qZjZ6eLBppA0n/K4dqRHa6Q1n3X+0l5ZJCEIPVccy/VCh4kqpaIhLMvDAd4WSGU7E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=miNGUziP; 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="miNGUziP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F2701F00A3D; Tue, 21 Jul 2026 17:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784655491; bh=iOASOheUXm4OgcYG7ozmyi6iJeYX5e60834IMapywm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=miNGUziPV+hD6XS4BkIW5aEfmZvFRrbNkxtYKsWOe1v8yGlel9gzGWpoczix0yBJG Rx6FWSsgHMLvpiWn8m5/fvvijWeapszBZepajZGyAw5fz9CCpWxt697bwXcZKqnO2a wr1gYqHR2JiP9PH30Hznqy68f+lL6Htp7BLqTP3A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yunke Cao , Hans de Goede , Ricardo Ribalda , Hans Verkuil Subject: [PATCH 6.18 0029/1611] media: uvcvideo: Do not add clock samples with small sof delta Date: Tue, 21 Jul 2026 17:02:25 +0200 Message-ID: <20260721152515.464958683@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152514.750365251@linuxfoundation.org> References: <20260721152514.750365251@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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Ribalda commit ba649fff36c1fe68489a86d00285224907edd436 upstream. Some UVC 1.1 cameras running in fast isochronous mode tend to spam the USB host with a lot of empty packets. These packets contain clock information and are added to the clock buffer but do not add any accuracy to the calculation. In fact, it is quite the opposite, in our calculations, only the first and the last timestamp is used, and we only have 32 slots. Ignore the samples that will produce less than MIN_HW_TIMESTAMP_DIFF data. Fixes: 141270bd95d4 ("media: uvcvideo: Refactor clock circular buffer") Cc: stable@vger.kernel.org Tested-by: Yunke Cao Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda Link: https://patch.msgid.link/20260513-uvc-hwtimestamp-v3-4-7a64838b0b02@chromium.org Signed-off-by: Hans de Goede Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_video.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -537,6 +537,15 @@ static void uvc_video_clock_add_sample(s spin_unlock_irqrestore(&clock->lock, flags); } +static inline u16 sof_diff(u16 a, u16 b) +{ + /* + * Because the result is modulo 2048 (via & 2047), we do not need a + * special case for a < b. + */ + return (a - b) & 2047; +} + static void uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, const u8 *data, int len) @@ -657,12 +666,13 @@ uvc_video_clock_decode(struct uvc_stream sample.dev_sof = (sample.dev_sof + stream->clock.sof_offset) & 2047; /* - * To limit the amount of data, drop SCRs with an SOF identical to the + * To limit the amount of data, drop SCRs with an SOF similar to the * previous one. This filtering is also needed to support UVC 1.5, where * all the data packets of the same frame contains the same SOF. In that * case only the first one will match the host_sof. */ - if (sample.dev_sof == stream->clock.last_sof) + if (sof_diff(sample.dev_sof, stream->clock.last_sof) <= + (UVC_MIN_HW_TIMESTAMP_DIFF / stream->clock.size)) return; uvc_video_clock_add_sample(&stream->clock, &sample);