Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp438623lqb; Tue, 28 May 2024 23:14:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV58yeQW1ZR3Z98Rnulw68cD+4xIU3UBj89zleRQBPmuvzZahkMqtfxjvlOX2ZFsLNA4HCZKO7x5CiTC+3wo45zSJuvFWcqBtTsNnHg7g== X-Google-Smtp-Source: AGHT+IHC0wK3JTMfQyXsgxCaJPHqfq2mnailnJDl9SUioHBESNg2E36xRPaMkDI/YIlT9zdma/On X-Received: by 2002:a05:6a00:408a:b0:6ea:c7bd:90e3 with SMTP id d2e1a72fcca58-70202d107d4mr1908120b3a.14.1716963243354; Tue, 28 May 2024 23:14:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716963243; cv=pass; d=google.com; s=arc-20160816; b=doDhRkcMxtBW2F7171JVinqLS+UjHhfw+rMZNM775BMsTcgim8BEXKSMtj9mVxeiDl dYIflOgpu3kYJhwYh2RGPjNfAno0pyw9FQaJMZNL5C84KPau2tHduYcPZzAFaXIXMCJm zW8XgGSEXncqT96AQ6nUQbnboOFVZ9UF/pNws4qiw6lKTgiVczJbsjBhcoDY9px8OaQu NO2FjmKHVYIs8qdcspE79C3tfng5u9vreq7SSsjPtZPUjVT5KmLdbB2D/H5gYlMnV+cR gnd0zj1tZnlFqFJ2xqWqJ8fcRHET7y+hOGAaUouT989CQnokHzY50ADuhlxDr5mHikLC FnFw== 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=mb1XJXdu2//C7Xx7gnMlD9T15Ki5dUYRiH8NLKoSURY=; fh=VrzPnkJyAY3GxYNEDaJO5hmj9B6V7700fMY2eD8ZcRU=; b=GA1BYciGF1qQ0ZYGdrqpK/ykx7vbvGSB3p84CqYQIPRshb1DVdd3EzP1LkyMij1oHU 1kiOwzXpVgZjZrU0AjS/l6JnuzbaK2XOC6n15hxiIICt49oHbEBlxScLeY4eRrVm7prU 9NbUZXuwjXZjs2simfk+tjN75CqWmJahgKRYgAXGMhXpZdsjZreH02IBu6b29doKSXKf 4khTgTN1H9YGvPAaaWMNQpo6olmke6u9nyKjJPeD76ImblcPfgxTlvHIDG8vEBWpg3Er Zm9iMLhOkf8d1YDuPEoHtQuiNI+C6M7iUq4F+PByyJsJLoiMssrRPoYgvXMVQbXGNmjS EaFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ObHQyTi2; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-193493-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-697cc79b041si6205945a12.194.2024.05.28.23.14.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 23:14:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193493-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 header.i=@chromium.org header.s=google header.b=ObHQyTi2; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-193493-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 F2D1828820C for ; Wed, 29 May 2024 06:14:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A18315DBC6; Wed, 29 May 2024 06:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ObHQyTi2" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F31681D68F for ; Wed, 29 May 2024 06:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716963234; cv=none; b=gVAa8r0hIQBQmcsUswhctktU2H8hS1iXaMc1WHY8ptvlVhDYQO2g8Ll1i7vn+hQexgbBYUd8CCp7LJTR30a0seGiqr6So0lolvtdEFz/eYXohnpIT5GlI9xJCfaqsQ166gGMqqXil9TWN7yrauTSAUrXv3hSJytam7RQhGvoytU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716963234; c=relaxed/simple; bh=3FSvLZlOgEc+aUu5jFCR372lA79UDHQsiGqRizvsNeE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lkkoS/RqIC21LBmaE2iFFRdfdHPtFQ1yJ89nbZsqrzxFrJUlDC786Rp2coVVMrafiRHejXE0l5j6KLAbN6bvTVDYAt5cnC8EhxBg0oyhdIzu9MBFSefSUMGks7H7EXwK0LJVptviWCquc6tHK7178wrcIgFyQp/cHfYfUm9gprw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ObHQyTi2; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1f48e9414e9so4960795ad.0 for ; Tue, 28 May 2024 23:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716963232; x=1717568032; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mb1XJXdu2//C7Xx7gnMlD9T15Ki5dUYRiH8NLKoSURY=; b=ObHQyTi2uozW3LJSjuzasfLf5XFeatxXArsoz5kulkjHaV/vtzdFsBE21GyGaxvKw7 s+k/4A+bGU2bulqQjVdb+2pT1xmVC5vuLMY5Vy9pHN6FBCsBEXUWnT3ufRsTkI4XVZNj Qgu2JNJbzpP6vaAUVsOh2G0uWcoMhP7mEOWRE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716963232; x=1717568032; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mb1XJXdu2//C7Xx7gnMlD9T15Ki5dUYRiH8NLKoSURY=; b=RzUrMTbi+PxP16Kletko7JtTgkZnrOlQfvI8+O0Iw3J44eJPNxcl+OPBcLREcUWQfC B7WtaW0KxNtkKJm/kGkJbaaajtyJCnMjiP1zIt+WQ+Wklhd0SEFUYeYVyH28cjfpQs5k YlrUvktSzJfwdekZfhfLvKo46XHlpfhokdnBnfOQSVtColvNtYHRSfbEG3G6ijs/ZW5y nQI6Xpm725MFJDIgeQvVNmlq25hukfTpF+ysJ7MPuXq3HA3HKYZ6rb2berDGv7GDwEQv MOzn5NbglWtWjSbTjOaZNhrpIee5DbLs/Xn9SqHRgt1bymdtUH1qHXRtRbWDPwfzfh5S larA== X-Forwarded-Encrypted: i=1; AJvYcCWomkzHYIpIZX3zGSdNmiid085dE2ULO6DSoDaiHRLFav8Vox4fNPH/e4CeVc4FhvNsdGNpUC9n3WPXwoINmvtRszs+kxUKV5WYU3H4 X-Gm-Message-State: AOJu0YzTlNniLdNGgK26qlAziZUg0AjMGQxLnfWLoT/FDkFku2Aea3r1 1uxVW4nhksXinDMR1JjXkeSrqLQCk/bcXwAiE38TMQZN4dXoYGWnIveiGoUE7A== X-Received: by 2002:a17:903:18a:b0:1f4:736a:27fa with SMTP id d9443c01a7336-1f4e95f4709mr20001565ad.0.1716963232293; Tue, 28 May 2024 23:13:52 -0700 (PDT) Received: from chromium.org (174.71.80.34.bc.googleusercontent.com. [34.80.71.174]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f47efff203sm61305385ad.241.2024.05.28.23.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 23:13:51 -0700 (PDT) Date: Wed, 29 May 2024 15:13:48 +0900 From: Tomasz Figa To: Ricardo Ribalda Cc: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "hn.chen" , Hans Verkuil , Sergey Senozhatsky Subject: Re: [PATCH v10 1/6] media: uvcvideo: Support timestamp lists of any size Message-ID: References: <20240323-resend-hwtimestamp-v10-0-b08e590d97c7@chromium.org> <20240323-resend-hwtimestamp-v10-1-b08e590d97c7@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=us-ascii Content-Disposition: inline In-Reply-To: <20240323-resend-hwtimestamp-v10-1-b08e590d97c7@chromium.org> On Sat, Mar 23, 2024 at 10:48:02AM +0000, Ricardo Ribalda wrote: > The tail of the list lives at the position before the head. This is > mathematically noted as: > ``` > (head-1) mod size. > ``` > Unfortunately C, does not have a modulus operator, but a remainder > operator (%). > The reminder operation has a different result than the modulus if > (head -1) is a negative number and size is not a power of two. > > Adding size to (head-1) allows the code to run with any value of size. > > This does not change the current behaviour of the driver, as the size is > always a power of two, but avoid tedious debugging if we ever change its > size. > > Reviewed-by: Sergey Senozhatsky > 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 7cbf4692bd875..659c9e9880a99 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); > > -- > 2.44.0.396.g6e790dbe36-goog > > It could be worth mentioning that basically head == 0 is the problematic case here, but otherwise good catch. Reviewed-by: Tomasz Figa Best regards, Tomasz