Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1051492rdb; Mon, 19 Feb 2024 02:41:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWSbwHmR2nfYYfxYtKFAlpxDuVpfmcuFsMXq0/ebHRuJfu4HRsOdEcOmSd2tOpdMfWjnPeUDPIWEyPrrzjs5Rq2mUU9AL2XkC1mbmnp9Q== X-Google-Smtp-Source: AGHT+IHu+YLGdax6Gk/AdyZ94Ceo2B5OXW3QkZGxfiM4EBmhkWfkkS6qoT3mK5/c4LfS1pslNT4d X-Received: by 2002:a05:6808:318e:b0:3c1:6036:9137 with SMTP id cd14-20020a056808318e00b003c160369137mr754271oib.34.1708339286624; Mon, 19 Feb 2024 02:41:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708339286; cv=pass; d=google.com; s=arc-20160816; b=Hp1SCOk8ZOjZX6c77p6BAwMFLdr7V4v71ZIl5qPrrTo7RL4tWE3pKI46ml9iEhhhkz PmfIgh6XrAusDut6DLcV5pyAB2KZ7bl9y/Hw0ecy6u7Ys6IWJde3xpfgKWrMlY7CuP7j fDw6QVu0Vga2Y+XBcT0bmdenOCcgREPM9q3J4NK6CiVSkiq1qCmkYJCFxFXQCKjgFFP1 4w2/tN+P5vc+niTWkBjUPdXgLaR+S6bgqmSDUVR0hFKobMrzVdUoox8mNzsRbF4E3GGl StxyiwQl5mvSHs+z1mIUVqDvPRMLy06fwtT+ZEjcPHGMzfSFU5fGlfF4fF+3u3koItGM FaEw== 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=UeZrqX3JuDj2uSLs79BlhkQum5gogU1ZBMzLpFV918Y=; fh=WfpwFwVEj24zwR92bZPT8UkZcFPphawJtKLkW/jAW9s=; b=MTMjxCmpY1hteIEnMmu1OgdE2FNpwtF7A7xKyqT4e39+6m/5Mbf+EuGtcOtaAddrfA aGr+QAl164jUYS4B1xabSZzUZOvy3144SPsoheJEI5HbRXKmdbtaLRWnnAEIL0OoUxq2 JHixZK3UhmPWFjWdUByPQtPxNsGYe1Iq/KMO11PR+7ZTyTIkMpcJzbziT+KZ79ccFyDe smY54OS+lOOKHtKBzB2+U1E5jZ1XElGBDN/gTp17wzZGZnm9lzsf5ykEP0cgeLgoTu5B eO+PveqNMIrYIwLn7ADuj9J4KgghKBOoDWuQS8JQ4hwGo7O3JWCCzUsLmqCMSA8G2pXT LkhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=aOUsX6hq; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-71137-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71137-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s37-20020a05622a1aa500b0042c7689da6dsi6457513qtc.606.2024.02.19.02.41.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 02:41:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71137-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=aOUsX6hq; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-71137-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71137-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5F4EB1C215E2 for ; Mon, 19 Feb 2024 10:41:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7802F28DBC; Mon, 19 Feb 2024 10:40:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aOUsX6hq" 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 0265D286AE; Mon, 19 Feb 2024 10:40:42 +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=1708339244; cv=none; b=jQA68sUbdQqDPxwjjvCK6dvJjGpDfOAr7zz2BoHBnZighyBOa16M5p/9I59pkuhpUTuueBLUUQbxFqi3nfYMynPGXIv9R+YmoHPFQOaKTJ8Kq+/jSPX4GyBa/hjGBsV/K2TWJCbnLPpnsrYkTH/CF1xhHvSiIKtZlIiOfkj9dn8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708339244; c=relaxed/simple; bh=EsN/+7thfuLmfHd8qe3dlDirPQrVnNo5wOQUpPckTFM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FabHMd3KcNF6w9/2RdrYcY4Ia48o8vi3K6I+3a8gl0dWSF71flLOT1pL4j8ZNr8z2Vv7c1WxqgZqb5zylCSn9ynoe85NyCJUYe6A/MX9wulxqsmXy3ZEPbwFyif1Lpsbcf7PKjI1PxWfLTSlPySpyDJCx63Lzn92jLo3HC/SQuI= 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=aOUsX6hq; 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 (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 05DB966F; Mon, 19 Feb 2024 11:40:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708339235; bh=EsN/+7thfuLmfHd8qe3dlDirPQrVnNo5wOQUpPckTFM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aOUsX6hqtRgcpJKKdJwVdfS6Ke3wRdZUpyPOpuis7GGI4TmZqH6I59LTyWOyjwwR8 kgqZRghP3W7mVOE0ua09idjToY1KmSNjwqx9R5dHkBaXpEFjqmgZsSoqAHTsMn3e3F jydIgBCvZHEBy85R1g3PNuZVpNS++Q07MAOVjKas= Date: Mon, 19 Feb 2024 12:40:46 +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: <20240219104046.GB13043@pendragon.ideasonboard.com> References: <20220920-resend-hwtimestamp-v9-0-55a89f46f6be@chromium.org> <20220920-resend-hwtimestamp-v9-1-55a89f46f6be@chromium.org> <20240212225940.GA19316@pendragon.ideasonboard.com> 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: Hi Ricardo, On Mon, Feb 19, 2024 at 11:28:03AM +0100, Ricardo Ribalda wrote: > On Mon, 12 Feb 2024 at 23:59, Laurent Pinchart wrote: > > 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 ? > > Take a look to: https://godbolt.org/z/xYeqTx6ba > > The expression only works because the size is a power of two. In this > set I am allowing sizes that are not powers of two. Could you then update the commit message to explain that ? I'll review the rest of the series this week. > > > 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