Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2730580rdb; Mon, 12 Feb 2024 15:00:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWtfX4+hiqnyyTDK1npIwmslCDq7gvHw5hTNGubUvMNIsp05YSBYSKjOVk72aOxZlmOVuDxpMARc74E/HO/o6D3Twg1j6zkbxzzwqLd0A== X-Google-Smtp-Source: AGHT+IGZxePyO0cOrjiZWQ04OVq40ENUvPrWYS7wXExDDPew1B0PaYpPYdRzR+z5fAEzp3tdUL1m X-Received: by 2002:a05:6a20:d48f:b0:19a:360c:75d8 with SMTP id im15-20020a056a20d48f00b0019a360c75d8mr12709622pzb.14.1707778804835; Mon, 12 Feb 2024 15:00:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707778804; cv=pass; d=google.com; s=arc-20160816; b=h5MmF2owDQ4Ug88sVp+ZMf3IV/BS+jyi+eRf5UChCGNyOIDZhDZlA+Wz6OATlYupXU 7BqRCJz3T4IIgfYQYIBeQTOi6AkzoX2Ykf8c9iXx1dE97WJcjGCWyoasq2GpfE4aYxHK s+AKFkbzhMhOr3km2ViMI1ZcbwQIIwWED4CwaYc4vjLliGxbFqyISZ+Bmp9Ab1blmEog MarwJgLOAWTW2soxzfNKPW3vymBwouQZ0v4WSf3+XtuZwWc6/4WN8w0wzfY01j1mOunb ibj1pL2U13/A3p6qGho34YwS8aG7on2rKIFtLg4G+SH0RU68vNW88xUHGtV1TOG9XMZe tkQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5wIBuhnfud0NSIyXCYYH7RWvOnQnp39Nk9kVwBgZhR4=; fh=ii7lfqIKgo7TQfY+2sXpTawgAy5RFUPFeKLjl4w203I=; b=wrJP2H4CL1LUgaj7oCE6rPWLYCluIcnCIgo2oz/WZPLrGtLeqMc2MikEp+NJyZRiQf h0KK7s1lfFmun1TpM8NKBfBfNZSJ20Ceo93IfU8jqS9q4q+q5puWzZFs4fk2ytTxFoGy RuiQol490L9GzstjROxskMZUd54a9N54IkIDiftLpOTHBPi9N0sTzxxP249bxx4ho5Jr a6jkfpNNisG7GkD7CZViR11B0aYl2hHHeDxVnr2geM5v46Uam5bJapy3MP2JDHOri0jl onLIF8WE7Y+ls8IPOIQkBJWRtCiu6OtapOIKqwwkOiSNLuHiCxV2VykY4yBm0r5cFw6r G5Zw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=VzRsKRyI; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-62509-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62509-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWBnbXmkyMUlMmdGtm/ueqjA7zea+qTWtg925TNkV8ZA05xcPAtSHs+8xHid8oj7dinrQmvMudHLjECWFO0zzcPxtfFfgAJkE48eSbKRg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k25-20020a6568d9000000b005cec90b9a98si885917pgt.835.2024.02.12.15.00.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:00:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62509-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=VzRsKRyI; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-62509-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62509-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C4C51282AB8 for ; Mon, 12 Feb 2024 23:00:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9AE54EB32; Mon, 12 Feb 2024 22:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VzRsKRyI" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 BB2714F1F6; Mon, 12 Feb 2024 22:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707778782; cv=none; b=dMvUIpkeRJYui9s62zMK36WW0s9A3+v5lZiwRHHr34SL+FkcUaflByjWkBhBQAJVuFdfiEfG/gZ1IOVVu4z/yQHrr45RPpQuNMOKcwujtsv9flAv9GbUtn0xQQy81x+0Qx1k0UNVkjVXuEtFiUaZUoyXzw9dO4rNo2Z9KlEeJpI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707778782; c=relaxed/simple; bh=vR/K496rPA2KU+aba4Uu2IC/4oIYinSUxJ9EgHzvb30=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZaT0S6TyI2Tc5mUNA5rKpEfplHIigACyYfwDe7yXf5/eHdoSqViuMH3ss973rqnL/iEPhatzpfvgUiur+2I9LgB5XfuVhzN1iEvYT6SOIG65IRoA5E3NKdDaBYoSl+FeQjvnnhX7dnNs09yGN+7LByia3ScRC0Rj8RvGTKuVkv8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=VzRsKRyI; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (unknown [109.130.69.237]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CB11B2D8; Mon, 12 Feb 2024 23:59:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1707778776; bh=vR/K496rPA2KU+aba4Uu2IC/4oIYinSUxJ9EgHzvb30=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VzRsKRyIm/u78yM0TPPGDEjCyjn2uwfGVk22wjzOznum1khiuJrpVSi8gHqA0l6FY djWvyfgXx4yqkHGgBe45uEhcix4qTg4OF9m6HtzR93dtZ0J1O96G3ej19wAoKn4Gzo sHAJkXLAJd1sve4N2Y9yQec0Yvxkfz9Wfaw7jlEs= Date: Tue, 13 Feb 2024 00:59:40 +0200 From: Laurent Pinchart To: Ricardo Ribalda Cc: Mauro Carvalho Chehab , Sergey Senozhatsky , linux-kernel@vger.kernel.org, "hn.chen" , linux-media@vger.kernel.org Subject: Re: [PATCH v9 1/6] media: uvcvideo: Fix negative modulus calculation Message-ID: <20240212225940.GA19316@pendragon.ideasonboard.com> References: <20220920-resend-hwtimestamp-v9-0-55a89f46f6be@chromium.org> <20220920-resend-hwtimestamp-v9-1-55a89f46f6be@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220920-resend-hwtimestamp-v9-1-55a89f46f6be@chromium.org> Hi Ricardo, Thank you for the patch. On Wed, Mar 15, 2023 at 02:30:12PM +0100, Ricardo Ribalda wrote: > If head is 0, last will be addressing the index 0 instead of clock->size > -1. Luckily clock->head is unsiged, otherwise it would be addressing > 0xffffffff. I'm not following you. In the expression (clock->head - 1) % clock->size clock->head is an unsigned int, and 1 as a signed int, so the result of the subtraction is promoted to an unsigned int. When clock->head is 0, the expression evaluates to 0xffffffff % clock->size clock->size is a power of two (hardcoded to 32 at the moment), so the expression evaluates to 31, as intended. Am I missing something ? > Nontheless, this is not the intented behaviour and should be fixed. > > Fixes: 66847ef013cc ("[media] uvcvideo: Add UVC timestamps support") > Signed-off-by: Ricardo Ribalda > --- > drivers/media/usb/uvc/uvc_video.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > index d4b023d4de7c..4ff4ab4471fe 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c > @@ -732,7 +732,7 @@ void uvc_video_clock_update(struct uvc_streaming *stream, > goto done; > > first = &clock->samples[clock->head]; > - last = &clock->samples[(clock->head - 1) % clock->size]; > + last = &clock->samples[(clock->head - 1 + clock->size) % clock->size]; > > /* First step, PTS to SOF conversion. */ > delta_stc = buf->pts - (1UL << 31); -- Regards, Laurent Pinchart