From: Mark Brown Date: Thu, 21 May 2026 11:30:11 +0000 (+0100) Subject: ASoC: Rework initialization of i2c_device_ids X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=456aae6c963e4c63b571249869e6cd7366546504;p=thirdparty%2Fkernel%2Flinux.git ASoC: Rework initialization of i2c_device_ids Uwe Kleine-König (The Capable Hub) says: 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; + }; }; /* pci_epf */ 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. The union added to struct i2c_device_id enables further cleanups 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 are 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 find a good example in sound/soc, so an iio driver was used to demonstrate the gain.) 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 empty remove callbacks that I found while working on patch #2. The second converts all hwmon drivers to use named initializers. Link: https://patch.msgid.link/cover.1778692164.git.u.kleine-koenig@baylibre.com --- 456aae6c963e4c63b571249869e6cd7366546504