Skip to contentSkip to conversation

net: dsa: Use named initializers for struct i2c_device_id

PATCH Applied Uwe Kleine-König (The Capable Hub) 3 participants 3 messages May 19 – May 21

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: Use named initializers for struct i2c_device_id

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.

This patch doesn't modify the compiled arrays, only their representation in source form benefits. The former was confirmed with x86 and arm64 builds.

While touching these arrays, unify usage of whitespace in the list terminator.

---
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/[email protected]/
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.

Please tell me if I should split per driver.

Best regards
Uwe

---
 drivers/net/dsa/lan9303_i2c.c           | 2 +-
 drivers/net/dsa/microchip/ksz9477_i2c.c | 4 ++--
 drivers/net/dsa/xrs700x/xrs700x_i2c.c   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/dsa/lan9303_i2c.c +1 -1
index c62d27cdc117..3a09f3907f44 100644
@@ -89,7 +89,7 @@ static void lan9303_i2c_shutdown(struct i2c_client *client)
 /*-------------------------------------------------------------------------*/
 
 static const struct i2c_device_id lan9303_i2c_id[] = {
-	{ "lan9303" },
+	{ .name = "lan9303" },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(i2c, lan9303_i2c_id);
drivers/net/dsa/microchip/ksz9477_i2c.c +2 -2
index a2beb27459f1..6940608a65c3 100644
@@ -80,8 +80,8 @@ static void ksz9477_i2c_shutdown(struct i2c_client *i2c)
 }
 
 static const struct i2c_device_id ksz9477_i2c_id[] = {
-	{ "ksz9477-switch" },
-	{}
+	{ .name = "ksz9477-switch" },
+	{ }
 };
 
 MODULE_DEVICE_TABLE(i2c, ksz9477_i2c_id);
drivers/net/dsa/xrs700x/xrs700x_i2c.c +2 -2
index 9b731dea78c1..e6a7839c4a04 100644
@@ -127,8 +127,8 @@ static void xrs700x_i2c_shutdown(struct i2c_client *i2c)
 }
 
 static const struct i2c_device_id xrs700x_i2c_id[] = {
-	{ "xrs700x-switch" },
-	{}
+	{ .name = "xrs700x-switch" },
+	{ }
 };
 
 MODULE_DEVICE_TABLE(i2c, xrs700x_i2c_id);

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731

Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Uwe Kleine-König (The Capable Hub)

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.

Quoted 8 lines

This patch doesn't modify the compiled arrays, only their representation in source form benefits. The former was confirmed with x86 and arm64 builds.

While touching these arrays, unify usage of whitespace in the list terminator.

Andrew

#2 lore raw
In reply to Uwe Kleine-König (The Capable Hub)
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 19 May 2026 16:57:22 +0200 you 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.

This patch doesn't modify the compiled arrays, only their representation in source form benefits. The former was confirmed with x86 and arm64 builds.

[...]

Here is the summary with links:
- [v1,net-next] net: dsa: Use named initializers for struct i2c_device_id

    https://git.kernel.org/netdev/net-next/c/af998e3688b7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html