Skip to contentSkip to conversation

iio: Introduce and use aligned_s64 type

PATCH In review Andy Shevchenko 2 participants 8 messages Sep 3, 2024 – Sep 9, 2024

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

v2 cover iio: Introduce and use aligned_s64 type

Instead of having open coded idea of aligned member, use a newly defined type like it's done in, e.g., u64 case. Update a few IIO drivers to show how to use it.

v2 (took only one year from v1, not bad!):
- avoided touching unrelated comments, code lines, etc. (Jonathan)
- used kernel internal type for the in-kernel code (Jonathan)

Andy Shevchenko (3):
types: Complement the aligned types with signed 64-bit one
iio: imu: st_lsm6dsx: Use aligned data type for timestamp
iio: hid-sensor: Use aligned data type for timestamp

 drivers/iio/accel/hid-sensor-accel-3d.c              | 2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c                | 2 +-
 drivers/iio/humidity/hid-sensor-humidity.c           | 2 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h              | 3 +--
 drivers/iio/light/hid-sensor-als.c                   | 2 +-
 drivers/iio/orientation/hid-sensor-incl-3d.c         | 2 +-
 drivers/iio/orientation/hid-sensor-rotation.c        | 2 +-
 drivers/iio/position/hid-sensor-custom-intel-hinge.c | 2 +-
 drivers/iio/pressure/hid-sensor-press.c              | 2 +-
 drivers/iio/temperature/hid-sensor-temperature.c     | 2 +-
 include/linux/types.h                                | 3 ++-
 include/uapi/linux/types.h                           | 1 +
 12 files changed, 13 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH v2 1/3 types: Complement the aligned types with signed 64-bit one

Some user may want to use aligned signed 64-bit type. Provide it for them.

---
 include/linux/types.h      | 3 ++-
 include/uapi/linux/types.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
include/linux/types.h +2 -1
index 2bc8766ba20c..2d7b9ae8714c 100644
@@ -115,8 +115,9 @@ typedef u64			u_int64_t;
 typedef s64			int64_t;
 #endif
 
-/* this is a special 64bit data type that is 8-byte aligned */
+/* These are the special 64-bit data types that are 8-byte aligned */
 #define aligned_u64		__aligned_u64
+#define aligned_s64		__aligned_s64
 #define aligned_be64		__aligned_be64
 #define aligned_le64		__aligned_le64
 
include/uapi/linux/types.h +1 -0
index 6375a0684052..48b933938877 100644
@@ -53,6 +53,7 @@ typedef __u32 __bitwise __wsum;
  * No conversions are necessary between 32-bit user-space and a 64-bit kernel.
  */
 #define __aligned_u64 __u64 __attribute__((aligned(8)))
+#define __aligned_s64 __s64 __attribute__((aligned(8)))
 #define __aligned_be64 __be64 __attribute__((aligned(8)))
 #define __aligned_le64 __le64 __attribute__((aligned(8)))
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#2 lore raw

PATCH v2 2/3 iio: imu: st_lsm6dsx: Use aligned data type for timestamp

In reply to Andy Shevchenko

Use __aligned_s64 for the timestamp field.

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +1 -2
index a3b93566533b..d5e2771042bd 100644
@@ -444,10 +444,9 @@ struct st_lsm6dsx_hw {
 	const struct st_lsm6dsx_settings *settings;
 
 	struct iio_mount_matrix orientation;
-	/* Ensure natural alignment of buffer elements */
 	struct {
 		__le16 channels[3];
-		s64 ts __aligned(8);
+		aligned_s64 ts;
 	} scan[ST_LSM6DSX_ID_MAX];
 };
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#3 lore raw

Re: [PATCH v2 2/3] iio: imu: st_lsm6dsx: Use aligned data type for timestamp

Quoted 1 line · Andy Shevchenko

Use __aligned_s64 for the timestamp field.

Oh, heck. I forgot to change the commit message...

...

drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h struct st_lsm6dsx_hw { · line 447

Quoted 1 line
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +0 -1
-	/* Ensure natural alignment of buffer elements */

...and for some reason this haven't been updated to be not removed.

I have updated locally, but will wait for other comments, maybe it's the only problem and Jonathan can fix whilst applying.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH v2 3/3 iio: hid-sensor: Use aligned data type for timestamp

In reply to Andy Shevchenko

Use aligned_s64 for the timestamp field.

Note, the actual data is signed, hence with this we also amend that. While at it, drop redundant __alignment directive.

---
 drivers/iio/accel/hid-sensor-accel-3d.c              | 2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c                | 2 +-
 drivers/iio/humidity/hid-sensor-humidity.c           | 2 +-
 drivers/iio/light/hid-sensor-als.c                   | 2 +-
 drivers/iio/orientation/hid-sensor-incl-3d.c         | 2 +-
 drivers/iio/orientation/hid-sensor-rotation.c        | 2 +-
 drivers/iio/position/hid-sensor-custom-intel-hinge.c | 2 +-
 drivers/iio/pressure/hid-sensor-press.c              | 2 +-
 drivers/iio/temperature/hid-sensor-temperature.c     | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +1 -1
index 9b7a73a4c48a..431a12171504 100644
@@ -28,7 +28,7 @@ struct accel_3d_state {
 	/* Ensure timestamp is naturally aligned */
 	struct {
 		u32 accel_val[3];
-		s64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
drivers/iio/gyro/hid-sensor-gyro-3d.c +1 -1
index 59a38bf9459b..d6562bd425f2 100644
@@ -27,7 +27,7 @@ struct gyro_3d_state {
 	struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
 	struct {
 		u32 gyro_val[GYRO_3D_CHANNEL_MAX];
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
drivers/iio/humidity/hid-sensor-humidity.c +1 -1
index bf6d2636a85e..eb1c022f73c8 100644
@@ -18,7 +18,7 @@ struct hid_humidity_state {
 	struct hid_sensor_hub_attribute_info humidity_attr;
 	struct {
 		s32 humidity_data;
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
drivers/iio/light/hid-sensor-als.c +1 -1
index 260281194f61..0c1d97aecd71 100644
@@ -31,7 +31,7 @@ struct als_state {
 	struct iio_chan_spec channels[CHANNEL_SCAN_INDEX_MAX + 1];
 	struct {
 		u32 illum[CHANNEL_SCAN_INDEX_MAX];
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
drivers/iio/orientation/hid-sensor-incl-3d.c +1 -1
index 8943d5c78bc0..f5e5fb68caf8 100644
@@ -29,7 +29,7 @@ struct incl_3d_state {
 	struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX];
 	struct {
 		u32 incl_val[INCLI_3D_CHANNEL_MAX];
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
drivers/iio/orientation/hid-sensor-rotation.c +1 -1
index 5e8cadd5177a..501c312ce752 100644
@@ -20,7 +20,7 @@ struct dev_rot_state {
 	struct hid_sensor_hub_attribute_info quaternion;
 	struct {
 		s32 sampled_vals[4] __aligned(16);
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
drivers/iio/position/hid-sensor-custom-intel-hinge.c +1 -1
index 76e173850a35..6239e2f72a05 100644
@@ -39,7 +39,7 @@ struct hinge_state {
 	const char *labels[CHANNEL_SCAN_INDEX_MAX];
 	struct {
 		u32 hinge_val[3];
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 
 	int scale_pre_decml;
drivers/iio/pressure/hid-sensor-press.c +1 -1
index 956045e2db29..0419bb3c3494 100644
@@ -24,7 +24,7 @@ struct press_state {
 	struct hid_sensor_hub_attribute_info press_attr;
 	struct {
 		u32 press_data;
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
drivers/iio/temperature/hid-sensor-temperature.c +1 -1
index 0143fd478933..d2209cd5b98c 100644
@@ -18,7 +18,7 @@ struct temperature_state {
 	struct hid_sensor_hub_attribute_info temperature_attr;
 	struct {
 		s32 temperature_data;
-		u64 timestamp __aligned(8);
+		aligned_s64 timestamp;
 	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer
#5 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · On Tue, 3 Sep 2024 20:59:03 +0300 Andy Shevchenko…

Instead of having open coded idea of aligned member, use a newly defined type like it's done in, e.g., u64 case. Update a few IIO drivers to show how to use it.

v2 (took only one year from v1, not bad!):

:)

Applied with that tweak for patch 2 that you called out.

Will probably be next cycle though before these go upstream (so think of this as queuing them up very early for 6.13 :)

Quoted 22 lines

- avoided touching unrelated comments, code lines, etc. (Jonathan)
- used kernel internal type for the in-kernel code (Jonathan)

Andy Shevchenko (3):
types: Complement the aligned types with signed 64-bit one
iio: imu: st_lsm6dsx: Use aligned data type for timestamp
iio: hid-sensor: Use aligned data type for timestamp

 drivers/iio/accel/hid-sensor-accel-3d.c              | 2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c                | 2 +-
 drivers/iio/humidity/hid-sensor-humidity.c           | 2 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h              | 3 +--
 drivers/iio/light/hid-sensor-als.c                   | 2 +-
 drivers/iio/orientation/hid-sensor-incl-3d.c         | 2 +-
 drivers/iio/orientation/hid-sensor-rotation.c        | 2 +-
 drivers/iio/position/hid-sensor-custom-intel-hinge.c | 2 +-
 drivers/iio/pressure/hid-sensor-press.c              | 2 +-
 drivers/iio/temperature/hid-sensor-temperature.c     | 2 +-
 include/linux/types.h                                | 3 ++-
 include/uapi/linux/types.h                           | 1 +
 12 files changed, 13 insertions(+), 12 deletions(-)
#6 lore raw
Quoted 11 lines · Jonathan Cameron
Quoted 5 lines · On Tue, 3 Sep 2024 20:59:03 +0300 Andy Shevchenko…

Instead of having open coded idea of aligned member, use a newly defined type like it's done in, e.g., u64 case. Update a few IIO drivers to show how to use it.

v2 (took only one year from v1, not bad!):

:)

Applied with that tweak for patch 2 that you called out.

Please, also do
s/__aligned_s64/aligned_s64/
in the commit message there.

Quoted 2 lines

Will probably be next cycle though before these go upstream (so think of this as queuing them up very early for 6.13 :)

Sure, thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#7 lore raw
Quoted 8 lines · On Mon, 9 Sep 2024 12:20:38 +0300 Andy Shevchenko…
Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Tue, 3 Sep 2024 20:59:03 +0300 Andy Shevchenko…

Instead of having open coded idea of aligned member, use a newly defined type like it's done in, e.g., u64 case. Update a few IIO drivers to show how to use it.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

v2 (took only one year from v1, not bad!):

:)

Applied with that tweak for patch 2 that you called out.

Please, also do
s/__aligned_s64/aligned_s64/
in the commit message there.

done I think

Quoted 6 lines
Quoted 3 lines

Will probably be next cycle though before these go upstream (so think of this as queuing them up very early for 6.13 :)

Sure, thanks!