[PATCH v1] usb: misc: Use named initializers for struct i2c_device_id

Uwe Kleine-König (The Capable Hub) posted 1 patch 6 days, 14 hours ago
drivers/usb/misc/usb251xb.c | 18 +++++++++---------
drivers/usb/misc/usb3503.c  |  2 +-
drivers/usb/misc/usb4604.c  |  2 +-
3 files changed, 11 insertions(+), 11 deletions(-)
[PATCH v1] usb: misc: Use named initializers for struct i2c_device_id
Posted by Uwe Kleine-König (The Capable Hub) 6 days, 14 hours ago
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.

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) <u.kleine-koenig@baylibre.com>
---
Hello,

this patch is part of a bigger quest to use named initializers for
mainly struct i2c_device_id::driver_data to be able to modify
i2c_device_id. See e.g.
https://lore.kernel.org/all/20260518111203.639603-2-u.kleine-koenig@baylibre.com/
for the details.

This patch here isn't critical for this quest, as no driver makes use of
.driver_data, so apart from the better readability this is only about
consistency with other subsystems.

Best regards
Uwe

 drivers/usb/misc/usb251xb.c | 18 +++++++++---------
 drivers/usb/misc/usb3503.c  |  2 +-
 drivers/usb/misc/usb4604.c  |  2 +-
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 7c0778631bea..fb0693742f01 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -746,15 +746,15 @@ static int usb251xb_i2c_resume(struct device *dev)
 static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_i2c_pm_ops, usb251xb_i2c_suspend, usb251xb_i2c_resume);
 
 static const struct i2c_device_id usb251xb_id[] = {
-	{ "usb2422" },
-	{ "usb2512b" },
-	{ "usb2512bi" },
-	{ "usb2513b" },
-	{ "usb2513bi" },
-	{ "usb2514b" },
-	{ "usb2514bi" },
-	{ "usb2517" },
-	{ "usb2517i" },
+	{ .name = "usb2422" },
+	{ .name = "usb2512b" },
+	{ .name = "usb2512bi" },
+	{ .name = "usb2513b" },
+	{ .name = "usb2513bi" },
+	{ .name = "usb2514b" },
+	{ .name = "usb2514bi" },
+	{ .name = "usb2517" },
+	{ .name = "usb2517i" },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(i2c, usb251xb_id);
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
index 322e59381b78..759770a13260 100644
--- a/drivers/usb/misc/usb3503.c
+++ b/drivers/usb/misc/usb3503.c
@@ -390,7 +390,7 @@ static SIMPLE_DEV_PM_OPS(usb3503_platform_pm_ops, usb3503_platform_suspend,
 		usb3503_platform_resume);
 
 static const struct i2c_device_id usb3503_id[] = {
-	{ USB3503_I2C_NAME },
+	{ .name = USB3503_I2C_NAME },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, usb3503_id);
diff --git a/drivers/usb/misc/usb4604.c b/drivers/usb/misc/usb4604.c
index c9a2fb3518ae..2ae9656715e0 100644
--- a/drivers/usb/misc/usb4604.c
+++ b/drivers/usb/misc/usb4604.c
@@ -135,7 +135,7 @@ static SIMPLE_DEV_PM_OPS(usb4604_i2c_pm_ops, usb4604_i2c_suspend,
 		usb4604_i2c_resume);
 
 static const struct i2c_device_id usb4604_id[] = {
-	{ "usb4604" },
+	{ .name = "usb4604" },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, usb4604_id);

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
-- 
2.47.3

Re: [PATCH v1] usb: misc: Use named initializers for struct i2c_device_id
Posted by Richard Leitner 6 days, 14 hours ago
On Mon, May 18, 2026 at 03:55:36PM +0200, Uwe Kleine-König (The Capable Hub) wrote:
> 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.
> 
> 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) <u.kleine-koenig@baylibre.com>
> ---
> Hello,
> 
> this patch is part of a bigger quest to use named initializers for
> mainly struct i2c_device_id::driver_data to be able to modify
> i2c_device_id. See e.g.
> https://lore.kernel.org/all/20260518111203.639603-2-u.kleine-koenig@baylibre.com/
> for the details.
> 
> This patch here isn't critical for this quest, as no driver makes use of
> .driver_data, so apart from the better readability this is only about
> consistency with other subsystems.
> 
> Best regards
> Uwe
> 
>  drivers/usb/misc/usb251xb.c | 18 +++++++++---------
>  drivers/usb/misc/usb3503.c  |  2 +-
>  drivers/usb/misc/usb4604.c  |  2 +-
>  3 files changed, 11 insertions(+), 11 deletions(-)

Reviewed-by: Richard Leitner <richard.leitner@linux.dev>

> 
> diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> index 7c0778631bea..fb0693742f01 100644
> --- a/drivers/usb/misc/usb251xb.c
> +++ b/drivers/usb/misc/usb251xb.c
> @@ -746,15 +746,15 @@ static int usb251xb_i2c_resume(struct device *dev)
>  static DEFINE_SIMPLE_DEV_PM_OPS(usb251xb_i2c_pm_ops, usb251xb_i2c_suspend, usb251xb_i2c_resume);
>  
>  static const struct i2c_device_id usb251xb_id[] = {
> -	{ "usb2422" },
> -	{ "usb2512b" },
> -	{ "usb2512bi" },
> -	{ "usb2513b" },
> -	{ "usb2513bi" },
> -	{ "usb2514b" },
> -	{ "usb2514bi" },
> -	{ "usb2517" },
> -	{ "usb2517i" },
> +	{ .name = "usb2422" },
> +	{ .name = "usb2512b" },
> +	{ .name = "usb2512bi" },
> +	{ .name = "usb2513b" },
> +	{ .name = "usb2513bi" },
> +	{ .name = "usb2514b" },
> +	{ .name = "usb2514bi" },
> +	{ .name = "usb2517" },
> +	{ .name = "usb2517i" },
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(i2c, usb251xb_id);
> diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
> index 322e59381b78..759770a13260 100644
> --- a/drivers/usb/misc/usb3503.c
> +++ b/drivers/usb/misc/usb3503.c
> @@ -390,7 +390,7 @@ static SIMPLE_DEV_PM_OPS(usb3503_platform_pm_ops, usb3503_platform_suspend,
>  		usb3503_platform_resume);
>  
>  static const struct i2c_device_id usb3503_id[] = {
> -	{ USB3503_I2C_NAME },
> +	{ .name = USB3503_I2C_NAME },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, usb3503_id);
> diff --git a/drivers/usb/misc/usb4604.c b/drivers/usb/misc/usb4604.c
> index c9a2fb3518ae..2ae9656715e0 100644
> --- a/drivers/usb/misc/usb4604.c
> +++ b/drivers/usb/misc/usb4604.c
> @@ -135,7 +135,7 @@ static SIMPLE_DEV_PM_OPS(usb4604_i2c_pm_ops, usb4604_i2c_suspend,
>  		usb4604_i2c_resume);
>  
>  static const struct i2c_device_id usb4604_id[] = {
> -	{ "usb4604" },
> +	{ .name = "usb4604" },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, usb4604_id);
> 
> base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
> -- 
> 2.47.3
>