Skip to contentSkip to conversation

i2c: i801: Simplify initialization of i2c_board_info in i801_probe_optional_slaves

PATCH Applied Heiner Kallweit 3 participants 3 messages May 25, 2021 – Jun 20, 2021

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

PATCH 1/1 i2c: i801: Simplify initialization of i2c_board_info in i801_probe_optional_slaves

Why shall we bother to open-code something that the compiler can do for us.

---
 drivers/i2c/busses/i2c-i801.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-i801.c +4 -4
index 9588d5bcf..0c08cfec5 100644
@@ -1291,11 +1291,11 @@ static void i801_probe_optional_slaves(struct i801_priv *priv)
 		return;
 
 	if (apanel_addr) {
-		struct i2c_board_info info;
+		struct i2c_board_info info = {
+			.addr = apanel_addr,
+			.type = "fujitsu_apanel"
+		};
 
-		memset(&info, 0, sizeof(struct i2c_board_info));
-		info.addr = apanel_addr;
-		strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
 		i2c_new_client_device(&priv->adapter, &info);
 	}
 
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Heiner Kallweit

Why shall we bother to open-code something that the compiler can do for us.

I don't know, maybe it wasn't supported by older versions of gcc?

Surprisingly, this makes the binary a tad larger. I wonder why.

Quoted 10 lines
---
 drivers/i2c/busses/i2c-i801.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-i801.c +0 -0
index 9588d5bcf..0c08cfec5 100644

drivers/i2c/busses/i2c-i801.c static void i801_probe_optional_slaves(struct i801_priv *priv) · line 1294

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +1 -1
@@ -1291,11 +1291,11 @@ static void i801_probe_optional_slaves(struct i801_priv *priv)
 		return;
 
 	if (apanel_addr) {
-		struct i2c_board_info info;
+		struct i2c_board_info info = {

Could be declared const now?

drivers/i2c/busses/i2c-i801.c static void i801_probe_optional_slaves(struct i801_priv *priv) · line 1296

Quoted 2 lines
drivers/i2c/busses/i2c-i801.c +2 -0
+			.addr = apanel_addr,
+			.type = "fujitsu_apanel"

We traditionally add a trailing comma on every line, so that adding a line in the future will result in a smaller, more readable patch.

drivers/i2c/busses/i2c-i801.c static void i801_probe_optional_slaves(struct i801_priv *priv) · line 1301

Quoted 8 lines
drivers/i2c/busses/i2c-i801.c +1 -3
+		};
 
-		memset(&info, 0, sizeof(struct i2c_board_info));
-		info.addr = apanel_addr;
-		strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
 		i2c_new_client_device(&priv->adapter, &info);
 	}
 

Other than these minor details, no objection from me.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
Applied
#2 lore raw
In reply to Heiner Kallweit
Quoted 3 lines · Heiner Kallweit

Why shall we bother to open-code something that the compiler can do for us.

Applied to for-next, thanks!

drivers/i2c/busses/i2c-i801.c static void i801_probe_optional_slaves(struct i801_priv *priv) · line 1296

Quoted 1 line
drivers/i2c/busses/i2c-i801.c +1 -0
+			.type = "fujitsu_apanel"

I added the "," here.