Skip to contentSkip to conversation

iio: common: cros_ec_sensors: use sensor_scale union member for CALIBSCALE

PATCH In review Arnav Kapoor 5 participants 7 messages Oct 11 – Oct 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: common: cros_ec_sensors: use sensor_scale union member for CALIBSCALE

The IIO_CHAN_INFO_CALIBSCALE read and write paths send MOTIONSENSE_CMD_SENSOR_SCALE, but set the flags through the sensor_offset member of the request union, while the scale values in the write path are filled through sensor_scale.

This only works because the sensor_offset and sensor_scale structs of struct ec_params_motion_sense happen to place flags at the same offset. Use the sensor_scale member that matches the command, so all fields of the request are set through the same struct.

No functional change.

Assisted-by LLM

---
Compile-tested only (W=1); I don't have ChromeOS EC hardware. Both union members place flags at the same offset, so the generated host command is unchanged.

 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +2 -3
index 551b86236abc..2839714f5bc8 100644
@@ -70,7 +70,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_CALIBSCALE:
 		st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_SCALE;
-		st->core.param.sensor_offset.flags = 0;
+		st->core.param.sensor_scale.flags = 0;
 
 		ret = cros_ec_motion_send_host_cmd(&st->core, 0);
 		if (ret == -EPROTO || ret == -EOPNOTSUPP) {
@@ -178,8 +178,7 @@ static int cros_ec_sensors_write(struct iio_dev *indio_dev,
 		/* Send to EC for each axis, even if not complete */
 
 		st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_SCALE;
-		st->core.param.sensor_offset.flags =
-			MOTION_SENSE_SET_OFFSET;
+		st->core.param.sensor_scale.flags = MOTION_SENSE_SET_OFFSET;
 		for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
 			st->core.param.sensor_scale.scale[i] =
 				st->core.calib[i].scale;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Sun, 11 Oct 2026 10:24:08 +0530 Arnav Kapoor <[email protected]> wrote:

The IIO_CHAN_INFO_CALIBSCALE read and write paths send MOTIONSENSE_CMD_SENSOR_SCALE, but set the flags through the sensor_offset member of the request union, while the scale values in the write path are filled through sensor_scale.

This only works because the sensor_offset and sensor_scale structs of struct ec_params_motion_sense happen to place flags at the same offset. Use the sensor_scale member that matches the command, so all fields of the request are set through the same struct.

Quoted 5 lines

No functional change.

Assisted-by LLM

---

Please add a Fixes tag. Otherwise looks good to me!

Signature · 2 lines
Kind regards,
Joshua Crofts
#2 lore raw
Quoted 3 lines · Joshua Crofts

Please add a Fixes tag. Otherwise looks good to me!

Thanks for the review. The mismatch was introduced when CALIBSCALE support was added:

Fixes ed1f2e85da79 ("iio: cros_ec: Add calibscale for 3d MEMS")

Jonathan, could you pick this up when applying, or would you prefer a v2?

Thanks,
Arnav

#3 lore raw
Quoted 11 lines · Arnav Kapoor
Quoted 3 lines · Joshua Crofts

Please add a Fixes tag. Otherwise looks good to me!

Thanks for the review. The mismatch was introduced when CALIBSCALE support was added:

Fixes ed1f2e85da79 ("iio: cros_ec: Add calibscale for 3d MEMS")

Jonathan, could you pick this up when applying, or would you prefer a v2?

No need to resend, b4 will scan the whole email thread for the tags.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
Quoted 6 lines · On Tue, 13 Oct 2026 22:55:27 +0300 Andy Shevchenko…
Quoted 5 lines · Arnav Kapoor
Quoted 3 lines · Joshua Crofts

Please add a Fixes tag. Otherwise looks good to me!

Quoted 8 lines
Quoted 6 lines

Thanks for the review. The mismatch was introduced when CALIBSCALE support was added:

Fixes ed1f2e85da79 ("iio: cros_ec: Add calibscale for 3d MEMS")

Jonathan, could you pick this up when applying, or would you prefer a v2?

No need to resend, b4 will scan the whole email thread for the tags.

If it could put them in the right order for 'late' fixes tags it would be perfect (easy fix though so don't resend!)

Quoted 1 line

This driver tends to be well maintained so whilst I'm fine with the change I'll wait a bit for a tag from one of the maintainers.

Jonathan

Reviewed-by
#5 lore raw
Quoted 16 lines · Jonathan Cameron
Quoted 13 lines · On Tue, 13 Oct 2026 22:55:27 +0300 Andy Shevchenko…
Quoted 11 lines · Arnav Kapoor
Quoted 3 lines · Joshua Crofts

Please add a Fixes tag. Otherwise looks good to me!

Thanks for the review. The mismatch was introduced when CALIBSCALE support was added:

Fixes ed1f2e85da79 ("iio: cros_ec: Add calibscale for 3d MEMS")

Jonathan, could you pick this up when applying, or would you prefer a v2?

Quoted 7 lines
Quoted 1 line

No need to resend, b4 will scan the whole email thread for the tags.

If it could put them in the right order for 'late' fixes tags it would be perfect (easy fix though so don't resend!)

Quoted 1 line

This driver tends to be well maintained so whilst I'm fine with the change I'll wait a bit for a tag from one of the maintainers.

Sorry for the delay, I somehow missed this in my inbox.

maintainer
#6 lore raw
Quoted 22 lines · On Sun, 18 Oct 2026 07:05:12 +0000 Tzung-Bi Shih <[email protected]> wrote:
Quoted 21 lines · Jonathan Cameron
Quoted 6 lines · On Tue, 13 Oct 2026 22:55:27 +0300 Andy Shevchenko…
Quoted 5 lines · Arnav Kapoor
Quoted 3 lines · Joshua Crofts

Please add a Fixes tag. Otherwise looks good to me!

Quoted 8 lines
Quoted 6 lines

Thanks for the review. The mismatch was introduced when CALIBSCALE support was added:

Fixes ed1f2e85da79 ("iio: cros_ec: Add calibscale for 3d MEMS")

Jonathan, could you pick this up when applying, or would you prefer a v2?

No need to resend, b4 will scan the whole email thread for the tags.

If it could put them in the right order for 'late' fixes tags it would be perfect (easy fix though so don't resend!)

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

This driver tends to be well maintained so whilst I'm fine with the change I'll wait a bit for a tag from one of the maintainers.

Sorry for the delay, I somehow missed this in my inbox.

Thanks!

Applied to the fixes-togreg branch of iio.git.
I considered taking this one the slow path given it 'works' today but given we are very early in the cycle seems nicer to just get it cleaned up.

I dropped the Assisted-by LLM bit given guidance on that has changed again since this was sent.

Jonathan