While being less compact, using named initializers allows to more easily see which members of the structs are assigned which value without having to lookup the declaration of the struct. And it's also more robust against changes to the struct definition.
The mentioned robustness is relevant for a planned change to struct i2c_device_id that replaces .driver_data by an anonymous union. While touching all these arrays, unify usage of whitespace in the list terminator. This patch doesn't modify the compiled arrays, only their representation in source form benefits. The former was confirmed with x86 and arm64 builds. Signed-off-by: Uwe Kleine-König (The Capable Hub) <[email protected]> --- Hello, the mentioned change to i2c_device_id is the following: 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/regulator/ad5398.c b/drivers/regulator/ad5398.c index 0123ca8157a8..dfb0b07500a7 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c @@ -207,8 +207,8 @@ struct ad5398_current_data_format { static const struct ad5398_current_data_format df_10_4_120 = {10, 4, 0, 120000}; static const struct i2c_device_id ad5398_id[] = { - { .name = "ad5398", .driver_data = (kernel_ulong_t)&df_10_4_120 }, - { .name = "ad5821", .driver_data = (kernel_ulong_t)&df_10_4_120 }, + { .name = "ad5398", .driver_data_ptr = &df_10_4_120 }, + { .name = "ad5821", .driver_data_ptr = &df_10_4_120 }, { } }; MODULE_DEVICE_TABLE(i2c, ad5398_id); @@ -219,8 +219,7 @@ static int ad5398_probe(struct i2c_client *client) struct regulator_init_data *init_data = dev_get_platdata(&client->dev); struct regulator_config config = { }; struct ad5398_chip_info *chip; - const struct ad5398_current_data_format *df = - (struct ad5398_current_data_format *)id->driver_data; + const struct ad5398_current_data_format *df = id->driver_data; chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip) 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 backlight driver that benefits, so this is "only" a regulator driver example.) 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. Best regards Uwe [1] https://cheri-alliance.org/discover-cheri/ https://lwn.net/Articles/1037974/ --- drivers/video/backlight/adp8860_bl.c | 6 +++--- drivers/video/backlight/adp8870_bl.c | 2 +- drivers/video/backlight/arcxcnn_bl.c | 2 +- drivers/video/backlight/aw99706.c | 2 +- drivers/video/backlight/bd6107.c | 2 +- drivers/video/backlight/ktz8866.c | 4 ++-- drivers/video/backlight/lm3509_bl.c | 4 ++-- drivers/video/backlight/lm3630a_bl.c | 4 ++-- drivers/video/backlight/lm3639_bl.c | 4 ++-- drivers/video/backlight/lp855x_bl.c | 14 +++++++------- drivers/video/backlight/lv5207lp.c | 2 +- drivers/video/backlight/mp3309c.c | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c index d4bbd7a7406b..09dd67702431 100644 --- a/drivers/video/backlight/adp8860_bl.c +++ b/drivers/video/backlight/adp8860_bl.c @@ -790,9 +790,9 @@ static SIMPLE_DEV_PM_OPS(adp8860_i2c_pm_ops, adp8860_i2c_suspend, adp8860_i2c_resume); static const struct i2c_device_id adp8860_id[] = { - { "adp8860", adp8860 }, - { "adp8861", adp8861 }, - { "adp8863", adp8863 }, + { .name = "adp8860", .driver_data = adp8860 }, + { .name = "adp8861", .driver_data = adp8861 }, + { .name = "adp8863", .driver_data = adp8863 }, { } }; MODULE_DEVICE_TABLE(i2c, adp8860_id); diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c index e09e20492e7c..d009f2c8a11d 100644 --- a/drivers/video/backlight/adp8870_bl.c +++ b/drivers/video/backlight/adp8870_bl.c @@ -962,7 +962,7 @@ static SIMPLE_DEV_PM_OPS(adp8870_i2c_pm_ops, adp8870_i2c_suspend, adp8870_i2c_resume); static const struct i2c_device_id adp8870_id[] = { - { "adp8870" }, + { .name = "adp8870" }, { } }; MODULE_DEVICE_TABLE(i2c, adp8870_id); diff --git a/drivers/video/backlight/arcxcnn_bl.c b/drivers/video/backlight/arcxcnn_bl.c index 1d5a570cfe02..f46eeab02e90 100644 --- a/drivers/video/backlight/arcxcnn_bl.c +++ b/drivers/video/backlight/arcxcnn_bl.c @@ -382,7 +382,7 @@ static const struct of_device_id arcxcnn_dt_ids[] = { MODULE_DEVICE_TABLE(of, arcxcnn_dt_ids); static const struct i2c_device_id arcxcnn_ids[] = { - {"arc2c0608", ARC2C0608}, + { .name = "arc2c0608", .driver_data = ARC2C0608 }, { } }; MODULE_DEVICE_TABLE(i2c, arcxcnn_ids); diff --git a/drivers/video/backlight/aw99706.c b/drivers/video/backlight/aw99706.c index 938f352aaab7..18299faf06ad 100644 --- a/drivers/video/backlight/aw99706.c +++ b/drivers/video/backlight/aw99706.c @@ -443,7 +443,7 @@ static int aw99706_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(aw99706_pm_ops, aw99706_suspend, aw99706_resume); static const struct i2c_device_id aw99706_ids[] = { - { "aw99706" }, + { .name = "aw99706" }, { } }; MODULE_DEVICE_TABLE(i2c, aw99706_ids); diff --git a/drivers/video/backlight/bd6107.c b/drivers/video/backlight/bd6107.c index 74567af84e97..6778b4030b02 100644 --- a/drivers/video/backlight/bd6107.c +++ b/drivers/video/backlight/bd6107.c @@ -179,7 +179,7 @@ static void bd6107_remove(struct i2c_client *client) } static const struct i2c_device_id bd6107_ids[] = { - { "bd6107" }, + { .name = "bd6107" }, { } }; MODULE_DEVICE_TABLE(i2c, bd6107_ids); diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c index 351c2b4d63ed..53c1301dbb8c 100644 --- a/drivers/video/backlight/ktz8866.c +++ b/drivers/video/backlight/ktz8866.c @@ -179,8 +179,8 @@ static void ktz8866_remove(struct i2c_client *client) } static const struct i2c_device_id ktz8866_ids[] = { - { "ktz8866" }, - {} + { .name = "ktz8866" }, + { } }; MODULE_DEVICE_TABLE(i2c, ktz8866_ids); diff --git a/drivers/video/backlight/lm3509_bl.c b/drivers/video/backlight/lm3509_bl.c index 24e1a19ff72d..53136c5e1460 100644 --- a/drivers/video/backlight/lm3509_bl.c +++ b/drivers/video/backlight/lm3509_bl.c @@ -311,8 +311,8 @@ static void lm3509_remove(struct i2c_client *client) } static const struct i2c_device_id lm3509_id[] = { - { LM3509_NAME }, - {} + { .name = LM3509_NAME }, + { } }; MODULE_DEVICE_TABLE(i2c, lm3509_id); diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c index 37651c2b9393..8f49e59ce374 100644 --- a/drivers/video/backlight/lm3630a_bl.c +++ b/drivers/video/backlight/lm3630a_bl.c @@ -596,8 +596,8 @@ static void lm3630a_remove(struct i2c_client *client) } static const struct i2c_device_id lm3630a_id[] = { - { LM3630A_NAME }, - {} + { .name = LM3630A_NAME }, + { } }; MODULE_DEVICE_TABLE(i2c, lm3630a_id); diff --git a/drivers/video/backlight/lm3639_bl.c b/drivers/video/backlight/lm3639_bl.c index 37ccc631c498..ea748b80b737 100644 --- a/drivers/video/backlight/lm3639_bl.c +++ b/drivers/video/backlight/lm3639_bl.c @@ -403,8 +403,8 @@ static void lm3639_remove(struct i2c_client *client) } static const struct i2c_device_id lm3639_id[] = { - { LM3639_NAME }, - {} + { .name = LM3639_NAME }, + { } }; MODULE_DEVICE_TABLE(i2c, lm3639_id); diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index d191560ce285..43a2123d3a4d 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -570,13 +570,13 @@ static const struct of_device_id lp855x_dt_ids[] __maybe_unused = { MODULE_DEVICE_TABLE(of, lp855x_dt_ids); static const struct i2c_device_id lp855x_ids[] = { - {"lp8550", LP8550}, - {"lp8551", LP8551}, - {"lp8552", LP8552}, - {"lp8553", LP8553}, - {"lp8555", LP8555}, - {"lp8556", LP8556}, - {"lp8557", LP8557}, + { .name = "lp8550", .driver_data = LP8550 }, + { .name = "lp8551", .driver_data = LP8551 }, + { .name = "lp8552", .driver_data = LP8552 }, + { .name = "lp8553", .driver_data = LP8553 }, + { .name = "lp8555", .driver_data = LP8555 }, + { .name = "lp8556", .driver_data = LP8556 }, + { .name = "lp8557", .driver_data = LP8557 }, { } }; MODULE_DEVICE_TABLE(i2c, lp855x_ids); diff --git a/drivers/video/backlight/lv5207lp.c b/drivers/video/backlight/lv5207lp.c index a205f004eab2..e643ab9c3536 100644 --- a/drivers/video/backlight/lv5207lp.c +++ b/drivers/video/backlight/lv5207lp.c @@ -131,7 +131,7 @@ static void lv5207lp_remove(struct i2c_client *client) } static const struct i2c_device_id lv5207lp_ids[] = { - { "lv5207lp" }, + { .name = "lv5207lp" }, { } }; MODULE_DEVICE_TABLE(i2c, lv5207lp_ids); diff --git a/drivers/video/backlight/mp3309c.c b/drivers/video/backlight/mp3309c.c index 9337110ce6e5..413cfe27dfd9 100644 --- a/drivers/video/backlight/mp3309c.c +++ b/drivers/video/backlight/mp3309c.c @@ -400,7 +400,7 @@ static const struct of_device_id mp3309c_match_table[] = { MODULE_DEVICE_TABLE(of, mp3309c_match_table); static const struct i2c_device_id mp3309c_id[] = { - { "mp3309c" }, + { .name = "mp3309c" }, { } }; MODULE_DEVICE_TABLE(i2c, mp3309c_id); base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731 -- 2.47.3
