public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
* [PATCH 0/8] iio: timestamp declaration cleanup
@ 2026-05-17 18:17 David Lechner
  2026-05-17 18:17 ` [PATCH 1/8] iio: common: scmi_sensors: simplify timestamp channel definition David Lechner
                   ` (10 more replies)
  0 siblings, 11 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

While looking around the code, I noticed that there are a lot of places
were we are manually filling all of the fields of an IIO timestamp.

This is error-prone (as seen in the first patch) and more verbose than
it needs to be.

I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
macro for doing a struct assignment. This does require a cast, which
makes it a bit more verbose, but we were already doing that in to
drivers, so I went with it anyway.

If we want to consider alternatives, we could make a iio helper function
or macro like the first and second patches did.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
David Lechner (8):
      iio: common: scmi_sensors: simplify timestamp channel definition
      iio: adc: dln2-adc: simplify timestamp channel definition
      iio: adc: at91_adc: simplify timestamp channel definition
      iio: adc: cc10001_adc: simplify timestamp channel definition
      iio: adc: stm32-adc: simplify timestamp channel definition
      iio: common: cros_ec_sensors: simplify timestamp channel definition
      iio: light: cros_ec_light_prox: simplify timestamp channel definition
      iio: pressure: cros_ec_baro: simplify timestamp channel definition

 drivers/iio/adc/at91_adc.c                            | 12 +++---------
 drivers/iio/adc/cc10001_adc.c                         | 10 ++--------
 drivers/iio/adc/dln2-adc.c                            | 12 +-----------
 drivers/iio/adc/stm32-adc.c                           | 10 ++--------
 drivers/iio/common/cros_ec_sensors/cros_ec_activity.c |  8 +-------
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c  |  8 +-------
 drivers/iio/common/scmi_sensors/scmi_iio.c            | 13 +------------
 drivers/iio/light/cros_ec_light_prox.c                |  8 +-------
 drivers/iio/pressure/cros_ec_baro.c                   |  8 +-------
 9 files changed, 13 insertions(+), 76 deletions(-)
---
base-commit: 8678fb54958893818ddeccd05fea560a4e1fc759
change-id: 20260517-iio-timestamp-cleanup-1ee82f081a70

Best regards,
--  
David Lechner <dlechner@baylibre•com>



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/8] iio: common: scmi_sensors: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 18:17 ` [PATCH 2/8] iio: adc: dln2-adc: " David Lechner
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

In fact, there was an error here as the sign should be 's' instead of
'u' which is now changed to 's' by using IIO_CHAN_SOFT_TIMESTAMP().

If we find that this breaks userspace, we will have to revert this
change, but seems unlikely since the timestamp channel is well-known to
be a signed 64-bit integer globally.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/common/scmi_sensors/scmi_iio.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/iio/common/scmi_sensors/scmi_iio.c b/drivers/iio/common/scmi_sensors/scmi_iio.c
index 5136ad9ada04..86e1782deee5 100644
--- a/drivers/iio/common/scmi_sensors/scmi_iio.c
+++ b/drivers/iio/common/scmi_sensors/scmi_iio.c
@@ -419,17 +419,6 @@ static const struct iio_chan_spec_ext_info scmi_iio_ext_info[] = {
 	{ }
 };
 
-static void scmi_iio_set_timestamp_channel(struct iio_chan_spec *iio_chan,
-					   int scan_index)
-{
-	iio_chan->type = IIO_TIMESTAMP;
-	iio_chan->channel = -1;
-	iio_chan->scan_index = scan_index;
-	iio_chan->scan_type.sign = 'u';
-	iio_chan->scan_type.realbits = 64;
-	iio_chan->scan_type.storagebits = 64;
-}
-
 static void scmi_iio_set_data_channel(struct iio_chan_spec *iio_chan,
 				      enum iio_chan_type type,
 				      enum iio_modifier mod, int scan_index)
@@ -629,7 +618,7 @@ scmi_alloc_iiodev(struct scmi_device *sdev,
 					 "Error in registering sensor update notifier for sensor %s\n",
 					 sensor->sensor_info->name);
 
-	scmi_iio_set_timestamp_channel(&iio_channels[i], i);
+	iio_channels[i] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(i);
 	iiodev->channels = iio_channels;
 	return iiodev;
 }

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/8] iio: adc: dln2-adc: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
  2026-05-17 18:17 ` [PATCH 1/8] iio: common: scmi_sensors: simplify timestamp channel definition David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 18:17 ` [PATCH 3/8] iio: adc: at91_adc: " David Lechner
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/adc/dln2-adc.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
index eb902a946efe..b7250fbe4fae 100644
--- a/drivers/iio/adc/dln2-adc.c
+++ b/drivers/iio/adc/dln2-adc.c
@@ -444,16 +444,6 @@ static int dln2_update_scan_mode(struct iio_dev *indio_dev,
 	lval.scan_type.endianness = IIO_LE;				\
 }
 
-/* Assignment version of IIO_CHAN_SOFT_TIMESTAMP */
-#define IIO_CHAN_SOFT_TIMESTAMP_ASSIGN(lval, _si) {	\
-	lval.type = IIO_TIMESTAMP;			\
-	lval.channel = -1;				\
-	lval.scan_index = _si;				\
-	lval.scan_type.sign = 's';			\
-	lval.scan_type.realbits = 64;			\
-	lval.scan_type.storagebits = 64;		\
-}
-
 static const struct iio_info dln2_adc_info = {
 	.read_raw = dln2_adc_read_raw,
 	.write_raw = dln2_adc_write_raw,
@@ -614,7 +604,7 @@ static int dln2_adc_probe(struct platform_device *pdev)
 
 	for (i = 0; i < chans; ++i)
 		DLN2_ADC_CHAN(dln2->iio_channels[i], i)
-	IIO_CHAN_SOFT_TIMESTAMP_ASSIGN(dln2->iio_channels[i], i);
+	dln2->iio_channels[i] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(i);
 
 	indio_dev->name = DLN2_ADC_MOD_NAME;
 	indio_dev->info = &dln2_adc_info;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/8] iio: adc: at91_adc: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
  2026-05-17 18:17 ` [PATCH 1/8] iio: common: scmi_sensors: simplify timestamp channel definition David Lechner
  2026-05-17 18:17 ` [PATCH 2/8] iio: adc: dln2-adc: " David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 18:17 ` [PATCH 4/8] iio: adc: cc10001_adc: " David Lechner
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/adc/at91_adc.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 6e1930f7c65d..260e3e0c09fc 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -481,7 +481,7 @@ static irqreturn_t at91_adc_9x5_interrupt(int irq, void *private)
 static int at91_adc_channel_init(struct iio_dev *idev)
 {
 	struct at91_adc_state *st = iio_priv(idev);
-	struct iio_chan_spec *chan_array, *timestamp;
+	struct iio_chan_spec *chan_array;
 	int bit, idx = 0;
 	unsigned long rsvd_mask = 0;
 
@@ -519,14 +519,8 @@ static int at91_adc_channel_init(struct iio_dev *idev)
 		chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
 		idx++;
 	}
-	timestamp = chan_array + idx;
-
-	timestamp->type = IIO_TIMESTAMP;
-	timestamp->channel = -1;
-	timestamp->scan_index = idx;
-	timestamp->scan_type.sign = 's';
-	timestamp->scan_type.realbits = 64;
-	timestamp->scan_type.storagebits = 64;
+
+	chan_array[idx] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(idx);
 
 	idev->channels = chan_array;
 	return idev->num_channels;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/8] iio: adc: cc10001_adc: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (2 preceding siblings ...)
  2026-05-17 18:17 ` [PATCH 3/8] iio: adc: at91_adc: " David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 18:17 ` [PATCH 5/8] iio: adc: stm32-adc: " David Lechner
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/adc/cc10001_adc.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/adc/cc10001_adc.c b/drivers/iio/adc/cc10001_adc.c
index 2c51b90b7101..9ca6a6b33740 100644
--- a/drivers/iio/adc/cc10001_adc.c
+++ b/drivers/iio/adc/cc10001_adc.c
@@ -262,7 +262,7 @@ static const struct iio_info cc10001_adc_info = {
 static int cc10001_adc_channel_init(struct iio_dev *indio_dev,
 				    unsigned long channel_map)
 {
-	struct iio_chan_spec *chan_array, *timestamp;
+	struct iio_chan_spec *chan_array;
 	unsigned int bit, idx = 0;
 
 	indio_dev->num_channels = bitmap_weight(&channel_map,
@@ -289,13 +289,7 @@ static int cc10001_adc_channel_init(struct iio_dev *indio_dev,
 		idx++;
 	}
 
-	timestamp = &chan_array[idx];
-	timestamp->type = IIO_TIMESTAMP;
-	timestamp->channel = -1;
-	timestamp->scan_index = idx;
-	timestamp->scan_type.sign = 's';
-	timestamp->scan_type.realbits = 64;
-	timestamp->scan_type.storagebits = 64;
+	chan_array[idx] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(idx);
 
 	indio_dev->channels = chan_array;
 

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/8] iio: adc: stm32-adc: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (3 preceding siblings ...)
  2026-05-17 18:17 ` [PATCH 4/8] iio: adc: cc10001_adc: " David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 18:17 ` [PATCH 6/8] iio: common: cros_ec_sensors: " David Lechner
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/adc/stm32-adc.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 46106200bb86..bf68f28e7c3a 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -2443,14 +2443,8 @@ static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)
 	scan_index = ret;
 
 	if (timestamping) {
-		struct iio_chan_spec *timestamp = &channels[scan_index];
-
-		timestamp->type = IIO_TIMESTAMP;
-		timestamp->channel = -1;
-		timestamp->scan_index = scan_index;
-		timestamp->scan_type.sign = 's';
-		timestamp->scan_type.realbits = 64;
-		timestamp->scan_type.storagebits = 64;
+		channels[scan_index] =
+			(struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(scan_index);
 
 		scan_index++;
 	}

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 6/8] iio: common: cros_ec_sensors: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (4 preceding siblings ...)
  2026-05-17 18:17 ` [PATCH 5/8] iio: adc: stm32-adc: " David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 18:17 ` [PATCH 7/8] iio: light: cros_ec_light_prox: " David Lechner
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

Also drop obvious comment while we're at it.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/common/cros_ec_sensors/cros_ec_activity.c | 8 +-------
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c  | 8 +-------
 2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c b/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c
index 6e38d115b6fe..802c811dcf75 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_activity.c
@@ -279,13 +279,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
 		channel++;
 	}
 
-	/* Timestamp */
-	channel->scan_index = index;
-	channel->type = IIO_TIMESTAMP;
-	channel->channel = -1;
-	channel->scan_type.sign = 's';
-	channel->scan_type.realbits = 64;
-	channel->scan_type.storagebits = 64;
+	*channel = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(index);
 
 	indio_dev->channels = st->channels;
 	indio_dev->num_channels = index + 1;
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index f34e2bbba2d1..bf49453fc051 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -279,13 +279,7 @@ static int cros_ec_sensors_probe(struct platform_device *pdev)
 		}
 	}
 
-	/* Timestamp */
-	channel->type = IIO_TIMESTAMP;
-	channel->channel = -1;
-	channel->scan_index = CROS_EC_SENSOR_MAX_AXIS;
-	channel->scan_type.sign = 's';
-	channel->scan_type.realbits = 64;
-	channel->scan_type.storagebits = 64;
+	*channel = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(CROS_EC_SENSOR_MAX_AXIS);
 
 	indio_dev->channels = state->channels;
 	indio_dev->num_channels = CROS_EC_SENSORS_MAX_CHANNELS;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7/8] iio: light: cros_ec_light_prox: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (5 preceding siblings ...)
  2026-05-17 18:17 ` [PATCH 6/8] iio: common: cros_ec_sensors: " David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 18:17 ` [PATCH 8/8] iio: pressure: cros_ec_baro: " David Lechner
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

Also drop obvious comment while we're at it.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/light/cros_ec_light_prox.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/iio/light/cros_ec_light_prox.c b/drivers/iio/light/cros_ec_light_prox.c
index 815806ceb5c8..6c8746236030 100644
--- a/drivers/iio/light/cros_ec_light_prox.c
+++ b/drivers/iio/light/cros_ec_light_prox.c
@@ -223,14 +223,8 @@ static int cros_ec_light_prox_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	/* Timestamp */
 	channel++;
-	channel->type = IIO_TIMESTAMP;
-	channel->channel = -1;
-	channel->scan_index = 1;
-	channel->scan_type.sign = 's';
-	channel->scan_type.realbits = 64;
-	channel->scan_type.storagebits = 64;
+	*channel = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(1);
 
 	indio_dev->channels = state->channels;
 

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 8/8] iio: pressure: cros_ec_baro: simplify timestamp channel definition
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (6 preceding siblings ...)
  2026-05-17 18:17 ` [PATCH 7/8] iio: light: cros_ec_light_prox: " David Lechner
@ 2026-05-17 18:17 ` David Lechner
  2026-05-17 19:22 ` [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-05-17 18:17 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform, David Lechner

Use IIO_CHAN_SOFT_TIMESTAMP() to define the timestamp channel instead of
manually filling in the struct iio_chan_spec fields. This makes the code
less verbose and mistake-prone.

Also drop obvious comment while we're at it.

Signed-off-by: David Lechner <dlechner@baylibre•com>
---
 drivers/iio/pressure/cros_ec_baro.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/iio/pressure/cros_ec_baro.c b/drivers/iio/pressure/cros_ec_baro.c
index c6b950c596c1..87eb9359928c 100644
--- a/drivers/iio/pressure/cros_ec_baro.c
+++ b/drivers/iio/pressure/cros_ec_baro.c
@@ -170,14 +170,8 @@ static int cros_ec_baro_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	/* Timestamp */
 	channel++;
-	channel->type = IIO_TIMESTAMP;
-	channel->channel = -1;
-	channel->scan_index = 1;
-	channel->scan_type.sign = 's';
-	channel->scan_type.realbits = 64;
-	channel->scan_type.storagebits = 64;
+	*channel = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(1);
 
 	indio_dev->channels = state->channels;
 	indio_dev->num_channels = CROS_EC_BARO_MAX_CHANNELS;

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/8] iio: timestamp declaration cleanup
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (7 preceding siblings ...)
  2026-05-17 18:17 ` [PATCH 8/8] iio: pressure: cros_ec_baro: " David Lechner
@ 2026-05-17 19:22 ` David Lechner
  2026-05-18  7:23   ` Andy Shevchenko
  2026-05-18  7:09 ` Andy Shevchenko
  2026-05-18  7:26 ` Andy Shevchenko
  10 siblings, 1 reply; 16+ messages in thread
From: David Lechner @ 2026-05-17 19:22 UTC (permalink / raw)
  To: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck
  Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-stm32,
	chrome-platform

On 5/17/26 1:17 PM, David Lechner wrote:
> While looking around the code, I noticed that there are a lot of places
> were we are manually filling all of the fields of an IIO timestamp.
> 
> This is error-prone (as seen in the first patch) and more verbose than
> it needs to be.
> 
> I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
> macro for doing a struct assignment. This does require a cast, which
> makes it a bit more verbose, but we were already doing that in to
> drivers, so I went with it anyway.
> 
> If we want to consider alternatives, we could make a iio helper function
> or macro like the first and second patches did.
> 
I should have looked harder for existing alternatives. Just found one
more that avoids the cast via a local variable (in ad4170-4.c):

	/* Add timestamp channel */
	struct iio_chan_spec ts_chan = IIO_CHAN_SOFT_TIMESTAMP(chan_num);

	st->chans[chan_num] = ts_chan;

And similar code is found in ad7192.c.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/8] iio: timestamp declaration cleanup
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (8 preceding siblings ...)
  2026-05-17 19:22 ` [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
@ 2026-05-18  7:09 ` Andy Shevchenko
  2026-05-18  7:14   ` Andy Shevchenko
  2026-05-18  7:26 ` Andy Shevchenko
  10 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2026-05-18  7:09 UTC (permalink / raw)
  To: David Lechner
  Cc: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck, linux-iio,
	linux-kernel, linux-arm-kernel, linux-stm32, chrome-platform

On Sun, May 17, 2026 at 01:17:17PM -0500, David Lechner wrote:
> While looking around the code, I noticed that there are a lot of places
> were we are manually filling all of the fields of an IIO timestamp.
> 
> This is error-prone (as seen in the first patch) and more verbose than
> it needs to be.
> 
> I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
> macro for doing a struct assignment. This does require a cast, which

No, it's *not* a cast. It's a compound literal. And instead of doing this in
every driver, add it to the macro (in a separate patch). Oh, let me just cook
it for you (I added that to several cases in the past).

> makes it a bit more verbose, but we were already doing that in to
> drivers, so I went with it anyway.

> If we want to consider alternatives, we could make a iio helper function
> or macro like the first and second patches did.

-- 
With Best Regards,
Andy Shevchenko




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/8] iio: timestamp declaration cleanup
  2026-05-18  7:09 ` Andy Shevchenko
@ 2026-05-18  7:14   ` Andy Shevchenko
  2026-05-18 14:34     ` David Lechner
  0 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2026-05-18  7:14 UTC (permalink / raw)
  To: David Lechner
  Cc: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck, linux-iio,
	linux-kernel, linux-arm-kernel, linux-stm32, chrome-platform

On Mon, May 18, 2026 at 10:09:48AM +0300, Andy Shevchenko wrote:
> On Sun, May 17, 2026 at 01:17:17PM -0500, David Lechner wrote:
> > While looking around the code, I noticed that there are a lot of places
> > were we are manually filling all of the fields of an IIO timestamp.
> > 
> > This is error-prone (as seen in the first patch) and more verbose than
> > it needs to be.
> > 
> > I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
> > macro for doing a struct assignment. This does require a cast, which
> 
> No, it's *not* a cast. It's a compound literal. And instead of doing this in
> every driver, add it to the macro (in a separate patch). Oh, let me just cook
> it for you (I added that to several cases in the past).

20260518071349.469748-1-andriy.shevchenko@linux•intel.com

> > makes it a bit more verbose, but we were already doing that in to
> > drivers, so I went with it anyway.
> 
> > If we want to consider alternatives, we could make a iio helper function
> > or macro like the first and second patches did.

-- 
With Best Regards,
Andy Shevchenko




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/8] iio: timestamp declaration cleanup
  2026-05-17 19:22 ` [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
@ 2026-05-18  7:23   ` Andy Shevchenko
  0 siblings, 0 replies; 16+ messages in thread
From: Andy Shevchenko @ 2026-05-18  7:23 UTC (permalink / raw)
  To: David Lechner
  Cc: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck, linux-iio,
	linux-kernel, linux-arm-kernel, linux-stm32, chrome-platform

On Sun, May 17, 2026 at 02:22:03PM -0500, David Lechner wrote:
> On 5/17/26 1:17 PM, David Lechner wrote:
> > While looking around the code, I noticed that there are a lot of places
> > were we are manually filling all of the fields of an IIO timestamp.
> > 
> > This is error-prone (as seen in the first patch) and more verbose than
> > it needs to be.
> > 
> > I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
> > macro for doing a struct assignment. This does require a cast, which
> > makes it a bit more verbose, but we were already doing that in to
> > drivers, so I went with it anyway.
> > 
> > If we want to consider alternatives, we could make a iio helper function
> > or macro like the first and second patches did.
> > 
> I should have looked harder for existing alternatives. Just found one
> more that avoids the cast via a local variable (in ad4170-4.c):
> 
> 	/* Add timestamp channel */
> 	struct iio_chan_spec ts_chan = IIO_CHAN_SOFT_TIMESTAMP(chan_num);
> 
> 	st->chans[chan_num] = ts_chan;
> 
> And similar code is found in ad7192.c.

See my patch. The above with my patch applied can be simplified to the
inline use.

-- 
With Best Regards,
Andy Shevchenko




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/8] iio: timestamp declaration cleanup
  2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
                   ` (9 preceding siblings ...)
  2026-05-18  7:09 ` Andy Shevchenko
@ 2026-05-18  7:26 ` Andy Shevchenko
  10 siblings, 0 replies; 16+ messages in thread
From: Andy Shevchenko @ 2026-05-18  7:26 UTC (permalink / raw)
  To: David Lechner
  Cc: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck, linux-iio,
	linux-kernel, linux-arm-kernel, linux-stm32, chrome-platform

On Sun, May 17, 2026 at 01:17:17PM -0500, David Lechner wrote:
> While looking around the code, I noticed that there are a lot of places
> were we are manually filling all of the fields of an IIO timestamp.
> 
> This is error-prone (as seen in the first patch) and more verbose than
> it needs to be.
> 
> I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
> macro for doing a struct assignment. This does require a cast, which
> makes it a bit more verbose, but we were already doing that in to
> drivers, so I went with it anyway.
> 
> If we want to consider alternatives, we could make a iio helper function
> or macro like the first and second patches did.

I like the series, just incorporate my patch, test and issue a v2, I will give
my tag.

-- 
With Best Regards,
Andy Shevchenko




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/8] iio: timestamp declaration cleanup
  2026-05-18  7:14   ` Andy Shevchenko
@ 2026-05-18 14:34     ` David Lechner
  2026-05-18 15:44       ` Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: David Lechner @ 2026-05-18 14:34 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jyoti Bhayana, Jonathan Cameron, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck, linux-iio,
	linux-kernel, linux-arm-kernel, linux-stm32, chrome-platform

On 5/18/26 2:14 AM, Andy Shevchenko wrote:
> On Mon, May 18, 2026 at 10:09:48AM +0300, Andy Shevchenko wrote:
>> On Sun, May 17, 2026 at 01:17:17PM -0500, David Lechner wrote:
>>> While looking around the code, I noticed that there are a lot of places
>>> were we are manually filling all of the fields of an IIO timestamp.
>>>
>>> This is error-prone (as seen in the first patch) and more verbose than
>>> it needs to be.
>>>
>>> I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
>>> macro for doing a struct assignment. This does require a cast, which
>>
>> No, it's *not* a cast. It's a compound literal. And instead of doing this in
>> every driver, add it to the macro (in a separate patch). Oh, let me just cook
>> it for you (I added that to several cases in the past).
> 
> 20260518071349.469748-1-andriy.shevchenko@linux•intel.com

Nice, thanks. I agree this will be the cleanest solution.

> 
>>> makes it a bit more verbose, but we were already doing that in to
>>> drivers, so I went with it anyway.
>>
>>> If we want to consider alternatives, we could make a iio helper function
>>> or macro like the first and second patches did.
> 



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/8] iio: timestamp declaration cleanup
  2026-05-18 14:34     ` David Lechner
@ 2026-05-18 15:44       ` Jonathan Cameron
  0 siblings, 0 replies; 16+ messages in thread
From: Jonathan Cameron @ 2026-05-18 15:44 UTC (permalink / raw)
  To: David Lechner
  Cc: Andy Shevchenko, Jyoti Bhayana, Nuno Sá, Andy Shevchenko,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maxime Coquelin,
	Alexandre Torgue, Benson Leung, Guenter Roeck, linux-iio,
	linux-kernel, linux-arm-kernel, linux-stm32, chrome-platform

On Mon, 18 May 2026 09:34:48 -0500
David Lechner <dlechner@baylibre•com> wrote:

> On 5/18/26 2:14 AM, Andy Shevchenko wrote:
> > On Mon, May 18, 2026 at 10:09:48AM +0300, Andy Shevchenko wrote:  
> >> On Sun, May 17, 2026 at 01:17:17PM -0500, David Lechner wrote:  
> >>> While looking around the code, I noticed that there are a lot of places
> >>> were we are manually filling all of the fields of an IIO timestamp.
> >>>
> >>> This is error-prone (as seen in the first patch) and more verbose than
> >>> it needs to be.
> >>>
> >>> I went with the approach of using the existing IIO_CHAN_SOFT_TIMESTAMP()
> >>> macro for doing a struct assignment. This does require a cast, which  
> >>
> >> No, it's *not* a cast. It's a compound literal. And instead of doing this in
> >> every driver, add it to the macro (in a separate patch). Oh, let me just cook
> >> it for you (I added that to several cases in the past).  
> > 
> > 20260518071349.469748-1-andriy.shevchenko@linux•intel.com  
> 
> Nice, thanks. I agree this will be the cleanest solution.
With that the series looks good to me.

J
> 
> >   
> >>> makes it a bit more verbose, but we were already doing that in to
> >>> drivers, so I went with it anyway.  
> >>  
> >>> If we want to consider alternatives, we could make a iio helper function
> >>> or macro like the first and second patches did.  
> >   
> 



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-05-18 15:45 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-17 18:17 [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
2026-05-17 18:17 ` [PATCH 1/8] iio: common: scmi_sensors: simplify timestamp channel definition David Lechner
2026-05-17 18:17 ` [PATCH 2/8] iio: adc: dln2-adc: " David Lechner
2026-05-17 18:17 ` [PATCH 3/8] iio: adc: at91_adc: " David Lechner
2026-05-17 18:17 ` [PATCH 4/8] iio: adc: cc10001_adc: " David Lechner
2026-05-17 18:17 ` [PATCH 5/8] iio: adc: stm32-adc: " David Lechner
2026-05-17 18:17 ` [PATCH 6/8] iio: common: cros_ec_sensors: " David Lechner
2026-05-17 18:17 ` [PATCH 7/8] iio: light: cros_ec_light_prox: " David Lechner
2026-05-17 18:17 ` [PATCH 8/8] iio: pressure: cros_ec_baro: " David Lechner
2026-05-17 19:22 ` [PATCH 0/8] iio: timestamp declaration cleanup David Lechner
2026-05-18  7:23   ` Andy Shevchenko
2026-05-18  7:09 ` Andy Shevchenko
2026-05-18  7:14   ` Andy Shevchenko
2026-05-18 14:34     ` David Lechner
2026-05-18 15:44       ` Jonathan Cameron
2026-05-18  7:26 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox