Linux IIO development
 help / color / mirror / Atom feed
From: Vasileios Amoiridis <vassilisamir@gmail.com>
To: David Lechner <dlechner@baylibre.com>
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
Subject: Re: [PATCH v2 3/4] iio: common: ssp_sensors: drop conditional optimization for simplicity
Date: Wed, 18 Dec 2024 22:13:55 +0100	[thread overview]
Message-ID: <Z2M7E9gmJyFkNEcD@vamoirid-laptop> (raw)
In-Reply-To: <82e97712-3765-4d93-bdb5-f50fa7025e81@baylibre.com>

On Wed, Dec 18, 2024 at 09:17:44AM -0600, David Lechner wrote:
> 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 <vassilisamir@gmail.com>
> >>> ---
> >>>  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 <linux/iio/kfifo_buf.h>
> >>>  #include <linux/module.h>
> >>>  #include <linux/slab.h>
> >>> +#include <linux/unaligned.h>
> >>> +#include <linux/units.h>
> >>>  #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.
> 

Hi David,

Hmmm, I think you are right. I can fix it in next, iteration. I will
wait also for Jonathan's comments on the rest of the series.

Cheers,
Vasilis

> > 
> > 	include/linux/units.h:12:#define MEGA 1000000UL
> > 
> > Cheers,
> > Vasilis
> > 
> >>>  
> >>>  	return iio_push_to_buffers_with_timestamp(indio_dev, spd->buffer,
> >>>  						  calculated_time);
> >>
> 

  reply	other threads:[~2024-12-18 21:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-14 19:14 [PATCH v2 0/4] iio: mark scan_timestamp as __private Vasileios Amoiridis
2024-12-14 19:14 ` [PATCH v2 1/4] iio: adc: dln2-adc: zero full struct instead of just the padding Vasileios Amoiridis
2024-12-19 17:41   ` Jonathan Cameron
2024-12-14 19:14 ` [PATCH v2 2/4] iio: adc: max1363: make use of iio_is_soft_ts_enabled() Vasileios Amoiridis
2024-12-19 17:45   ` Jonathan Cameron
2024-12-14 19:14 ` [PATCH v2 3/4] iio: common: ssp_sensors: drop conditional optimization for simplicity Vasileios Amoiridis
2024-12-16 21:57   ` David Lechner
2024-12-17 23:41     ` Vasileios Amoiridis
2024-12-18 15:17       ` David Lechner
2024-12-18 21:13         ` Vasileios Amoiridis [this message]
2024-12-19 17:47           ` Jonathan Cameron
2024-12-14 19:14 ` [PATCH v2 4/4] iio: core: mark scan_timestamp as __private Vasileios Amoiridis
2024-12-19 17:49   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z2M7E9gmJyFkNEcD@vamoirid-laptop \
    --to=vassilisamir@gmail.com \
    --cc=abhashkumarjha123@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jackoalan@gmail.com \
    --cc=jic23@kernel.org \
    --cc=jstephan@baylibre.com \
    --cc=k.wrona@samsung.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox