* [PATCH v1 0/2] iio: Rework i2c_device_id initialisation
@ 2026-05-12 12:50 Uwe Kleine-König (The Capable Hub)
2026-05-12 12:50 ` [PATCH v1 1/2] iio: Drop unused driver_data in four i2c drivers Uwe Kleine-König (The Capable Hub)
0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-05-12 12:50 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Matteo Martelli, David Lechner, Nuno Sá, Andy Shevchenko,
Mikael Gonella-Bolduc, Linus Walleij, Sakari Ailus, linux-iio,
linux-i2c, linux-kernel, Lars-Peter Clausen, Michael Hennerich,
Puranjay Mohan, Marcelo Schmitt, Antoniu Miclaus,
Ramona Gradinariu, Ariana Lazar, Alex Lanzano,
Jean-Baptiste Maneyrol, Remi Buisson, Lorenzo Bianconi,
Christian Eggers, Tomasz Duszynski, Javier Carrasco,
Andreas Klinger, Waqar Hameed, Sebastian Andrzej Siewior,
Gustavo Vaz, Dixit Parmar, Bartosz Golaszewski, Guenter Roeck,
Chuang Zhu, Kyle Hsieh, Oleksij Rempel, Sander Vanheule,
Romain Gantois, David Jander, Kurt Borja, Tomas Borquez,
Matti Vaittinen, chuguangqing, Shi Hao, Erikas Bitovtas,
Marcus Folkesson
Hello,
this series is a preparation for
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 23ff24080dfd..aebd3a5e90af 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -477,7 +477,11 @@ struct rpmsg_device_id {
struct i2c_device_id {
char name[I2C_NAME_SIZE];
- kernel_ulong_t driver_data; /* Data private to the driver */
+ union {
+ /* Data private to the driver */
+ kernel_ulong_t driver_data;
+ const void *driver_data_ptr;
+ };
};
and this requires that .driver_data is assigned via a named initializer
for static data. This requirement isn't a bad one because named
initializers are also much better readable than list initializers.
Once the union is in place, this allows changes like:
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 8a082ff034dd..b2aac7348d22 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -1429,7 +1429,7 @@ static int kxcjk1013_probe(struct i2c_client *client)
if (id) {
name = id->name;
- data->info = (const struct kx_chipset_info *)(id->driver_data);
+ data->info = id->driver_data_ptr;
} else {
name = iio_get_acpi_device_name_and_data(&client->dev, &ddata);
data->info = ddata;
@@ -1630,11 +1630,11 @@ static const struct dev_pm_ops kxcjk1013_pm_ops = {
};
static const struct i2c_device_id kxcjk1013_id[] = {
- { .name = "kxcjk1013", .driver_data = (kernel_ulong_t)&kxcjk1013_info },
- { .name = "kxcj91008", .driver_data = (kernel_ulong_t)&kxcj91008_info },
- { .name = "kxtj21009", .driver_data = (kernel_ulong_t)&kxtj21009_info },
- { .name = "kxtf9", .driver_data = (kernel_ulong_t)&kxtf9_info },
- { .name = "kx023-1025", .driver_data = (kernel_ulong_t)&kx0231025_info },
+ { .name = "kxcjk1013", .driver_data_ptr = &kxcjk1013_info },
+ { .name = "kxcj91008", .driver_data_ptr = &kxcj91008_info },
+ { .name = "kxtj21009", .driver_data_ptr = &kxtj21009_info },
+ { .name = "kxtf9", .driver_data_ptr = &kxtf9_info },
+ { .name = "kx023-1025", .driver_data_ptr = &kx0231025_info },
{ }
};
MODULE_DEVICE_TABLE(i2c, kxcjk1013_id);
that is an improvement for readability (again!) and it keeps some
properties of the pointers (here: being const) without having to pay
attention for that. (I didn't spot a driver that doesn't have that const
on casting back in drivers/iio, but other subsystems will benefit here,
too.)
My additional motivation for this effort is CHERI[1]. This is a hardware
extension that uses 128 bit pointers but unsigned long is still 64 bit.
So with CHERI you cannot store pointers in unsigned long variables.
The first patch drops a few unused assignments to .driver_data (which is
still better than assigning the values by name) and the second converts
all iio drivers with driver_data to use named initializers.
Best regards
Uwe
[1] https://cheri-alliance.org/discover-cheri/
https://lwn.net/Articles/1037974/
Uwe Kleine-König (The Capable Hub) (2):
iio: Drop unused driver_data in four i2c drivers
iio: Initialize i2c_device_id arrays using member names
drivers/iio/accel/adxl345_i2c.c | 4 +-
drivers/iio/accel/adxl355_i2c.c | 4 +-
drivers/iio/accel/adxl372_i2c.c | 4 +-
drivers/iio/accel/adxl380_i2c.c | 8 +-
drivers/iio/accel/bma180.c | 10 +-
drivers/iio/accel/bmc150-accel-i2c.c | 20 ++--
drivers/iio/accel/bmi088-accel-i2c.c | 6 +-
drivers/iio/accel/da280.c | 6 +-
drivers/iio/accel/fxls8962af-i2c.c | 8 +-
drivers/iio/accel/kxcjk-1013.c | 10 +-
drivers/iio/accel/mc3230.c | 4 +-
drivers/iio/accel/mma8452.c | 12 +--
drivers/iio/adc/ad7091r5.c | 2 +-
drivers/iio/adc/ad799x.c | 16 ++--
drivers/iio/adc/ina2xx-adc.c | 12 +--
drivers/iio/adc/ltc2309.c | 4 +-
drivers/iio/adc/ltc2471.c | 4 +-
drivers/iio/adc/ltc2497.c | 4 +-
drivers/iio/adc/max34408.c | 4 +-
drivers/iio/adc/mcp3422.c | 16 ++--
drivers/iio/adc/pac1921.c | 2 +-
drivers/iio/adc/ti-adc081c.c | 6 +-
drivers/iio/adc/ti-ads1015.c | 6 +-
drivers/iio/adc/ti-ads7138.c | 4 +-
drivers/iio/cdc/ad7150.c | 6 +-
drivers/iio/cdc/ad7746.c | 6 +-
drivers/iio/chemical/atlas-ezo-sensor.c | 6 +-
drivers/iio/chemical/atlas-sensor.c | 10 +-
drivers/iio/chemical/sgp30.c | 4 +-
drivers/iio/chemical/vz89x.c | 4 +-
drivers/iio/dac/ad5064.c | 94 +++++++++----------
drivers/iio/dac/ad5380.c | 32 +++----
drivers/iio/dac/ad5446-i2c.c | 12 +--
drivers/iio/dac/ad5696-i2c.c | 32 +++----
drivers/iio/dac/ds4424.c | 8 +-
drivers/iio/dac/max517.c | 10 +-
drivers/iio/dac/max5821.c | 2 +-
drivers/iio/dac/mcp4725.c | 4 +-
drivers/iio/dac/mcp47feb02.c | 48 +++++-----
drivers/iio/dac/ti-dac5571.c | 22 ++---
drivers/iio/health/max30102.c | 6 +-
drivers/iio/humidity/ens210.c | 12 +--
drivers/iio/humidity/htu21.c | 4 +-
drivers/iio/imu/bmi270/bmi270_i2c.c | 4 +-
.../iio/imu/inv_icm42600/inv_icm42600_i2c.c | 14 +--
.../iio/imu/inv_icm45600/inv_icm45600_i2c.c | 16 ++--
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 36 +++----
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c | 48 +++++-----
drivers/iio/light/apds9160.c | 2 +-
drivers/iio/light/as73211.c | 4 +-
drivers/iio/light/bh1750.c | 10 +-
drivers/iio/light/isl29018.c | 6 +-
drivers/iio/light/ltr501.c | 8 +-
drivers/iio/light/opt3001.c | 4 +-
drivers/iio/light/opt4001.c | 4 +-
drivers/iio/light/si1145.c | 14 +--
drivers/iio/light/tsl2563.c | 8 +-
drivers/iio/light/tsl2583.c | 6 +-
drivers/iio/light/tsl2772.c | 22 ++---
drivers/iio/light/vcnl4000.c | 14 +--
drivers/iio/light/veml6030.c | 6 +-
drivers/iio/magnetometer/ak8975.c | 14 +--
drivers/iio/magnetometer/hmc5843_i2c.c | 8 +-
drivers/iio/magnetometer/yamaha-yas530.c | 8 +-
drivers/iio/potentiometer/ad5272.c | 10 +-
drivers/iio/potentiometer/ds1803.c | 8 +-
drivers/iio/potentiometer/tpl0102.c | 8 +-
drivers/iio/pressure/abp060mg.c | 90 +++++++++++-------
drivers/iio/pressure/bmp280-i2c.c | 12 +--
drivers/iio/pressure/dlhl60d.c | 4 +-
drivers/iio/pressure/ms5611_i2c.c | 4 +-
drivers/iio/pressure/ms5637.c | 8 +-
drivers/iio/pressure/st_pressure_i2c.c | 16 ++--
drivers/iio/proximity/aw96103.c | 4 +-
drivers/iio/proximity/srf08.c | 6 +-
drivers/iio/proximity/sx9310.c | 4 +-
drivers/iio/proximity/sx9324.c | 2 +-
drivers/iio/proximity/sx9360.c | 2 +-
drivers/iio/temperature/tmp117.c | 4 +-
79 files changed, 479 insertions(+), 457 deletions(-)
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v1 1/2] iio: Drop unused driver_data in four i2c drivers
2026-05-12 12:50 [PATCH v1 0/2] iio: Rework i2c_device_id initialisation Uwe Kleine-König (The Capable Hub)
@ 2026-05-12 12:50 ` Uwe Kleine-König (The Capable Hub)
2026-05-12 14:01 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-05-12 12:50 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Matteo Martelli, David Lechner, Nuno Sá, Andy Shevchenko,
Mikael Gonella-Bolduc, Linus Walleij, Sakari Ailus, linux-iio,
linux-i2c, linux-kernel
For the four drivers the .driver_data member of i2c_device_id is
write-only. Drop the explicit assignment.
While touching these arrays use a named initializer to assign the .name
member, which is easier to parse for a human.
Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
---
drivers/iio/adc/pac1921.c | 2 +-
drivers/iio/light/apds9160.c | 2 +-
drivers/iio/light/tsl2563.c | 8 ++++----
drivers/iio/light/tsl2583.c | 6 +++---
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/adc/pac1921.c b/drivers/iio/adc/pac1921.c
index bce7185953ec..68bdd2f30bad 100644
--- a/drivers/iio/adc/pac1921.c
+++ b/drivers/iio/adc/pac1921.c
@@ -1310,7 +1310,7 @@ static int pac1921_probe(struct i2c_client *client)
}
static const struct i2c_device_id pac1921_id[] = {
- { .name = "pac1921", 0 },
+ { .name = "pac1921" },
{ }
};
MODULE_DEVICE_TABLE(i2c, pac1921_id);
diff --git a/drivers/iio/light/apds9160.c b/drivers/iio/light/apds9160.c
index 3da0bdac04cf..8dacb1730429 100644
--- a/drivers/iio/light/apds9160.c
+++ b/drivers/iio/light/apds9160.c
@@ -1572,7 +1572,7 @@ static const struct of_device_id apds9160_of_match[] = {
MODULE_DEVICE_TABLE(of, apds9160_of_match);
static const struct i2c_device_id apds9160_id[] = {
- { "apds9160", 0 },
+ { .name = "apds9160" },
{ }
};
MODULE_DEVICE_TABLE(i2c, apds9160_id);
diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
index f2af1cd7c2d1..7e277bc6a8b1 100644
--- a/drivers/iio/light/tsl2563.c
+++ b/drivers/iio/light/tsl2563.c
@@ -839,10 +839,10 @@ static DEFINE_SIMPLE_DEV_PM_OPS(tsl2563_pm_ops, tsl2563_suspend,
tsl2563_resume);
static const struct i2c_device_id tsl2563_id[] = {
- { "tsl2560", 0 },
- { "tsl2561", 1 },
- { "tsl2562", 2 },
- { "tsl2563", 3 },
+ { .name = "tsl2560" },
+ { .name = "tsl2561" },
+ { .name = "tsl2562" },
+ { .name = "tsl2563" },
{ }
};
MODULE_DEVICE_TABLE(i2c, tsl2563_id);
diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
index 8801a491de77..a0dd122af2cf 100644
--- a/drivers/iio/light/tsl2583.c
+++ b/drivers/iio/light/tsl2583.c
@@ -913,9 +913,9 @@ static DEFINE_RUNTIME_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend,
tsl2583_resume, NULL);
static const struct i2c_device_id tsl2583_idtable[] = {
- { "tsl2580", 0 },
- { "tsl2581", 1 },
- { "tsl2583", 2 },
+ { .name = "tsl2580" },
+ { .name = "tsl2581" },
+ { .name = "tsl2583" },
{ }
};
MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1 1/2] iio: Drop unused driver_data in four i2c drivers
2026-05-12 12:50 ` [PATCH v1 1/2] iio: Drop unused driver_data in four i2c drivers Uwe Kleine-König (The Capable Hub)
@ 2026-05-12 14:01 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-05-12 14:01 UTC (permalink / raw)
To: Uwe Kleine-König (The Capable Hub)
Cc: Matteo Martelli, David Lechner, Nuno Sá, Andy Shevchenko,
Mikael Gonella-Bolduc, Linus Walleij, Sakari Ailus, linux-iio,
linux-i2c, linux-kernel
On Tue, 12 May 2026 14:50:34 +0200
Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com> wrote:
> For the four drivers the .driver_data member of i2c_device_id is
> write-only. Drop the explicit assignment.
>
> While touching these arrays use a named initializer to assign the .name
> member, which is easier to parse for a human.
>
> Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
Given these are obviously a good idea and the other cases I called out
are more complex so probably want their own patches...
Applied to the testing branch of iio.git
Thanks
Jonathan
> ---
> drivers/iio/adc/pac1921.c | 2 +-
> drivers/iio/light/apds9160.c | 2 +-
> drivers/iio/light/tsl2563.c | 8 ++++----
> drivers/iio/light/tsl2583.c | 6 +++---
> 4 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/adc/pac1921.c b/drivers/iio/adc/pac1921.c
> index bce7185953ec..68bdd2f30bad 100644
> --- a/drivers/iio/adc/pac1921.c
> +++ b/drivers/iio/adc/pac1921.c
> @@ -1310,7 +1310,7 @@ static int pac1921_probe(struct i2c_client *client)
> }
>
> static const struct i2c_device_id pac1921_id[] = {
> - { .name = "pac1921", 0 },
> + { .name = "pac1921" },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, pac1921_id);
> diff --git a/drivers/iio/light/apds9160.c b/drivers/iio/light/apds9160.c
> index 3da0bdac04cf..8dacb1730429 100644
> --- a/drivers/iio/light/apds9160.c
> +++ b/drivers/iio/light/apds9160.c
> @@ -1572,7 +1572,7 @@ static const struct of_device_id apds9160_of_match[] = {
> MODULE_DEVICE_TABLE(of, apds9160_of_match);
>
> static const struct i2c_device_id apds9160_id[] = {
> - { "apds9160", 0 },
> + { .name = "apds9160" },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, apds9160_id);
> diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
> index f2af1cd7c2d1..7e277bc6a8b1 100644
> --- a/drivers/iio/light/tsl2563.c
> +++ b/drivers/iio/light/tsl2563.c
> @@ -839,10 +839,10 @@ static DEFINE_SIMPLE_DEV_PM_OPS(tsl2563_pm_ops, tsl2563_suspend,
> tsl2563_resume);
>
> static const struct i2c_device_id tsl2563_id[] = {
> - { "tsl2560", 0 },
> - { "tsl2561", 1 },
> - { "tsl2562", 2 },
> - { "tsl2563", 3 },
> + { .name = "tsl2560" },
> + { .name = "tsl2561" },
> + { .name = "tsl2562" },
> + { .name = "tsl2563" },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, tsl2563_id);
> diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
> index 8801a491de77..a0dd122af2cf 100644
> --- a/drivers/iio/light/tsl2583.c
> +++ b/drivers/iio/light/tsl2583.c
> @@ -913,9 +913,9 @@ static DEFINE_RUNTIME_DEV_PM_OPS(tsl2583_pm_ops, tsl2583_suspend,
> tsl2583_resume, NULL);
>
> static const struct i2c_device_id tsl2583_idtable[] = {
> - { "tsl2580", 0 },
> - { "tsl2581", 1 },
> - { "tsl2583", 2 },
> + { .name = "tsl2580" },
> + { .name = "tsl2581" },
> + { .name = "tsl2583" },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, tsl2583_idtable);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-12 14:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 12:50 [PATCH v1 0/2] iio: Rework i2c_device_id initialisation Uwe Kleine-König (The Capable Hub)
2026-05-12 12:50 ` [PATCH v1 1/2] iio: Drop unused driver_data in four i2c drivers Uwe Kleine-König (The Capable Hub)
2026-05-12 14:01 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox