* [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data
@ 2026-11-27 10:45 Uwe Kleine-König
2026-11-27 11:06 ` Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2026-11-27 10:45 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Robin van der Gracht, Geert Uytterhoeven, Danilo Krummrich,
Andrew Morton, Takashi Sakamoto, Randy Dunlap, Wang Jun,
Bjorn Helgaas, Kees Cook, Pawel Zalewski, linux-kernel
While being less compact, using designated 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.
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 <u.kleine-koenig@baylibre.com>
---
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 an auxdisplay driver that benefits,
so this is "only" a regulator driver example.)
There are no further changes necessary to drivers below
drivers/auxdisplay for other similar changes to other *_device_id.
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/auxdisplay/ht16k33.c | 6 +++---
drivers/auxdisplay/lcd2s.c | 2 +-
drivers/auxdisplay/max6959.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/auxdisplay/ht16k33.c b/drivers/auxdisplay/ht16k33.c
index 83dee9f8a8a5..ba70c8ef0dd5 100644
--- a/drivers/auxdisplay/ht16k33.c
+++ b/drivers/auxdisplay/ht16k33.c
@@ -742,9 +742,9 @@ static void ht16k33_remove(struct i2c_client *client)
}
static const struct i2c_device_id ht16k33_i2c_match[] = {
- { "3108", DISP_QUAD_7SEG },
- { "3130", DISP_QUAD_14SEG },
- { "ht16k33", DISP_MATRIX },
+ { .name = "3108", .driver_data = DISP_QUAD_7SEG },
+ { .name = "3130", .driver_data = DISP_QUAD_14SEG },
+ { .name = "ht16k33", .driver_data = DISP_MATRIX },
{ }
};
MODULE_DEVICE_TABLE(i2c, ht16k33_i2c_match);
diff --git a/drivers/auxdisplay/lcd2s.c b/drivers/auxdisplay/lcd2s.c
index 7b65f4306fae..f198208e4531 100644
--- a/drivers/auxdisplay/lcd2s.c
+++ b/drivers/auxdisplay/lcd2s.c
@@ -354,7 +354,7 @@ static void lcd2s_i2c_remove(struct i2c_client *i2c)
}
static const struct i2c_device_id lcd2s_i2c_id[] = {
- { "lcd2s" },
+ { .name = "lcd2s" },
{ }
};
MODULE_DEVICE_TABLE(i2c, lcd2s_i2c_id);
diff --git a/drivers/auxdisplay/max6959.c b/drivers/auxdisplay/max6959.c
index c31341637515..035aded09991 100644
--- a/drivers/auxdisplay/max6959.c
+++ b/drivers/auxdisplay/max6959.c
@@ -161,7 +161,7 @@ static int max6959_resume(struct device *dev)
static DEFINE_SIMPLE_DEV_PM_OPS(max6959_pm_ops, max6959_suspend, max6959_resume);
static const struct i2c_device_id max6959_i2c_id[] = {
- { "max6959" },
+ { .name = "max6959" },
{ }
};
MODULE_DEVICE_TABLE(i2c, max6959_i2c_id);
base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data
2026-11-27 10:45 [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data Uwe Kleine-König
@ 2026-11-27 11:06 ` Andy Shevchenko
2026-11-27 11:20 ` Geert Uytterhoeven
2026-11-27 11:59 ` Andy Shevchenko
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-11-27 11:06 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Andy Shevchenko, Robin van der Gracht, Geert Uytterhoeven,
Danilo Krummrich, Andrew Morton, Takashi Sakamoto, Randy Dunlap,
Wang Jun, Bjorn Helgaas, Kees Cook, Pawel Zalewski, linux-kernel
On Fri, Nov 27, 2026 at 11:45:51AM +0100, Uwe Kleine-König wrote:
> While being less compact, using designated 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.
>
> This patch doesn't modify the compiled arrays, only their representation
> in source form benefits. The former was confirmed with x86 and arm64
> builds.
I'm fine with this. Geert, do you have a chance to look at and give a tag?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data
2026-11-27 10:45 [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data Uwe Kleine-König
2026-11-27 11:06 ` Andy Shevchenko
@ 2026-11-27 11:20 ` Geert Uytterhoeven
2026-11-27 11:59 ` Andy Shevchenko
2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2026-11-27 11:20 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Robin van der Gracht, Danilo Krummrich, Andrew Morton,
Takashi Sakamoto, Randy Dunlap, Wang Jun, Bjorn Helgaas,
Kees Cook, Pawel Zalewski, linux-kernel, Andy Shevchenko
On Fri, Nov 27, 2026, at 11:45, Uwe Kleine-König wrote:
> While being less compact, using designated 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.
>
> 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 <u.kleine-koenig@baylibre.com>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data
2026-11-27 10:45 [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data Uwe Kleine-König
2026-11-27 11:06 ` Andy Shevchenko
2026-11-27 11:20 ` Geert Uytterhoeven
@ 2026-11-27 11:59 ` Andy Shevchenko
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-11-27 11:59 UTC (permalink / raw)
To: Andy Shevchenko, Uwe Kleine-König
Cc: Robin van der Gracht, Geert Uytterhoeven, Danilo Krummrich,
Andrew Morton, Takashi Sakamoto, Randy Dunlap, Wang Jun,
Bjorn Helgaas, Kees Cook, Pawel Zalewski, linux-kernel
On Fri, 27 Nov 2026 11:45:51 +0100, Uwe Kleine-König wrote:
> While being less compact, using designated 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.
>
> [...]
Applied, thanks!
[1/1] auxdisplay: Use designated initializers for arrays of i2c_device_data
commit: ae50e64cd87a9a285f2b40c59c89ade0d2b57833
Best regards,
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-27 11:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 10:45 [PATCH v1] auxdisplay: Use designated initializers for arrays of i2c_device_data Uwe Kleine-König
2026-11-27 11:06 ` Andy Shevchenko
2026-11-27 11:20 ` Geert Uytterhoeven
2026-11-27 11:59 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®