From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 931317080D for ; Wed, 18 Dec 2024 15:17:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734535069; cv=none; b=M3w2X++9bzAQsViZhBoSdWVgYtf8haIpa7njVDeIUHq99dRSaNFlJmvk8mVDDQOPIn1Y2pIzHLmLeZyf4uXKt8c8I5OS3aBIx47PX6e1Wdqgvq7cKI5RQgW71xFjMnFe6AEWbRDGs7G0+kPPa5uzNfMH6mJF/bAKUAlak/c48Rw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734535069; c=relaxed/simple; bh=5NJ6pIot8+0pvM6LtkETerACOgIy0iHfKl37XP/iDvo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iJ4VY/QjcsEd8u6sAuIpuWDMq/9ANK0UGyBSpFDlVTZMhVuuRz0qIDG0lC6xd5KSdalcXXd3ApNArjJp8W29x5/oEf7RNUL0RisPPKj5GUL0HqsCGUemAc2+YsnjDnC6Bp8Yj9lrx70URgbYOERP1Sqx6gZN0WaUhXSVGsHUNfw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=COktTU/J; arc=none smtp.client-ip=209.85.161.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="COktTU/J" Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5f2e13cb356so3102641eaf.2 for ; Wed, 18 Dec 2024 07:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1734535065; x=1735139865; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=6mueA8G+pAaD8m1QaOhjicnLM7XcQxaxCrEuNZaj5EQ=; b=COktTU/JfLw8byN3qx7pXiz5OJGwk3XDchTsbBtZ7u2d1Pmlgj8rto6TfIzEWJdsdh ZDP5Q1cWxv92mi1gEbqY2FvKh3WkR3kbEjzLbL3/kbzsr1aYP7R/wgYX9tOCWee/3zQq 2tPUBYY49jZnlKCx8MNgoJZhVcMS5zrPLotrpvlj0Q3Z3OwQbdL7rKg1SCl3Baa6cbQj zGRfEjE7G7jZ7iN9bx6bTxR0sOMrjFwYZILdcxKME0+b+rhSAjZdyPwgGbrybLWvzsSV 71pAUG+zaNxF7lv/YuIhVkScIt6C8X8Sx3HXtOJp/Xw4A4J+tyZJ5AFlUxev+rP7ZAHi N4Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734535065; x=1735139865; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6mueA8G+pAaD8m1QaOhjicnLM7XcQxaxCrEuNZaj5EQ=; b=Cuwg+XlvSgSoI22CrJvopYLgLPHeZyhc44yXIuBzHBN8YHOCng+R8GQ+DOeWJtBqCE 6uF5arYaMynVyvKA9ue1MfMLVj3XB6j+4b94/KdneDUqeulqP41qAe2/J78fx4hA3HEs P1YwaunF7iD7wYiGWo867MCEHHn03lyg6Tse8iuR1RKylOx6zxRbI0AlKpZ3G+HJReDt /zuJBOIJSs+QbAj440NYUbqZONa7gDb2tX+Tl8eu32RXvy/yigjeMwb6hJ7DQLVehZox pe3TRPqjLVdYO3OH+B8x80go68WtklUUPotF4J7yos1GtgrJupS2ed2Q+wfI78OHTBW7 1JgA== X-Forwarded-Encrypted: i=1; AJvYcCWqaS2nzhE1lSwIW3p5zFDD759yB2WHbd1VUpG6KPY1/EcWFM6svA0VaMXyxTKYqvf2j6aspLgC2Fi+Dpg=@vger.kernel.org X-Gm-Message-State: AOJu0YxQyFcJ0pBFx5eKi58tCv+AZxDxU/uLQ+YsLbA07KxHjDpaXqtl hq0atDl7x352NZp4+6otwU+uCd5ZddfJOUyxN+I0Bydcwvvz4D9+HpfkcMO4TXo= X-Gm-Gg: ASbGncvrwZ9sJgdYhcSJhO1RPFG8ghf0zyMKo7VHUh9iU+Gm+EbN1peFWCeb+F7pm4Z eDudRY3L304VIofqMlWJ4tcwUM/+Tjc7CriIv6IAIzsmaB1wPfP3PaCYGxAJnxBHrBy/3o9NJWY 1uU/+YnYojB+87ziESGrGlWhnXpAzu3JVTMXphpwnYsZBASTq8DF02KExZ7yhKlB1x2v78k4Con 0zzqL/7x3q6whWSJvWMFS2pllsi2nUMIpkdqLaRse2bQ/jYQv7bRFlqU1jlTsXOLQxbMsQ385AM g5FTfehVcoKWUWAUCQ== X-Google-Smtp-Source: AGHT+IGbYgF8Hk3CR1cekwwZ+DKAnSD04hz9wQulZ9HxHSPWc19jn8x5Cw+Ea+nPDOhQLmzvjSRk+Q== X-Received: by 2002:a05:6870:971e:b0:29e:70c7:a3eb with SMTP id 586e51a60fabf-2a7b3025f25mr1620526fac.7.1734535065551; Wed, 18 Dec 2024 07:17:45 -0800 (PST) Received: from [192.168.0.142] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-2a3d2541725sm3479964fac.12.2024.12.18.07.17.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Dec 2024 07:17:44 -0800 (PST) Message-ID: <82e97712-3765-4d93-bdb5-f50fa7025e81@baylibre.com> Date: Wed, 18 Dec 2024 09:17:44 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/4] iio: common: ssp_sensors: drop conditional optimization for simplicity To: Vasileios Amoiridis Cc: jic23@kernel.org, lars@metafoo.de, krzysztof.kozlowski@linaro.org, nuno.sa@analog.com, u.kleine-koenig@baylibre.com, abhashkumarjha123@gmail.com, jstephan@baylibre.com, jackoalan@gmail.com, k.wrona@samsung.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20241214191421.94172-1-vassilisamir@gmail.com> <20241214191421.94172-4-vassilisamir@gmail.com> <5e133bba-ee3e-498f-80ea-375dd857c057@baylibre.com> From: David Lechner Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/17/24 5:41 PM, Vasileios Amoiridis wrote: > On Mon, Dec 16, 2024 at 03:57:44PM -0600, David Lechner wrote: >> On 12/14/24 1:14 PM, Vasileios Amoiridis wrote: >>> Drop conditional in favor of always calculating the timestamp value. >>> This simplifies the code and allows to drop usage of internal private >>> variable "scan_timestamp" of the struct iio_dev. >>> >>> Signed-off-by: Vasileios Amoiridis >>> --- >>> drivers/iio/common/ssp_sensors/ssp_iio.c | 9 +++------ >>> 1 file changed, 3 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c b/drivers/iio/common/ssp_sensors/ssp_iio.c >>> index caa404edd9d0..6b86b5315694 100644 >>> --- a/drivers/iio/common/ssp_sensors/ssp_iio.c >>> +++ b/drivers/iio/common/ssp_sensors/ssp_iio.c >>> @@ -8,6 +8,8 @@ >>> #include >>> #include >>> #include >>> +#include >>> +#include >>> #include "ssp_iio_sensor.h" >>> >>> /** >>> @@ -70,7 +72,6 @@ EXPORT_SYMBOL_NS(ssp_common_buffer_postdisable, "IIO_SSP_SENSORS"); >>> int ssp_common_process_data(struct iio_dev *indio_dev, void *buf, >>> unsigned int len, int64_t timestamp) >>> { >>> - __le32 time; >>> int64_t calculated_time = 0; >>> struct ssp_sensor_data *spd = iio_priv(indio_dev); >>> >>> @@ -82,11 +83,7 @@ int ssp_common_process_data(struct iio_dev *indio_dev, void *buf, >>> */ >>> memcpy(spd->buffer, buf, len); >>> >>> - if (indio_dev->scan_timestamp) { >>> - memcpy(&time, &((char *)buf)[len], SSP_TIME_SIZE); >>> - calculated_time = >>> - timestamp + (int64_t)le32_to_cpu(time) * 1000000; >>> - } >>> + calculated_time = timestamp + get_unaligned_le32(buf + len) * MEGA; >> >> Don't we still need to cast to 64 bit to avoid multiplication overflow? >> > > Hi David, > > Thanks for your message! > > Aren't we already covered by the fact that MEGA is defined as an > unsigned long? That is only 64-bits on 64-bit architectures, so could still overflow on 32-bit architectures where long is 32-bit. > > include/linux/units.h:12:#define MEGA 1000000UL > > Cheers, > Vasilis > >>> >>> return iio_push_to_buffers_with_timestamp(indio_dev, spd->buffer, >>> calculated_time); >>