[PATCH 1/1] tpm_tis_i2c: Fix -Wdeclaration-after-statement

Peter Delevoryas peter at pjd.dev
Tue Jul 26 08:51:51 AEST 2022


If I try to build with CONFIG_TCG_TIS_I2C=y, I get the following
warning:

../drivers/char/tpm/tpm_tis_i2c.c: In function ‘tpm_tis_i2c_write_bytes’:
../drivers/char/tpm/tpm_tis_i2c.c:114:17: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  114 |                 struct i2c_msg msgs[] = {
      |                 ^~~~~~

This just refactors the code slightly to avoid the warning. It shouldn't
really be any different behavior. In fact, I think the first call to
i2c_transfer() is wrong: it's sending 2 messages but only populating the
first one? That doesn't seem right. But, I'm not testing this change, so
I'll leave the behavior as-is.

Signed-off-by: Peter Delevoryas <peter at pjd.dev>
---
 drivers/char/tpm/tpm_tis_i2c.c | 36 ++++++++++++----------------------
 1 file changed, 13 insertions(+), 23 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_i2c.c b/drivers/char/tpm/tpm_tis_i2c.c
index 12984a3be327..0bc8a1cea554 100644
--- a/drivers/char/tpm/tpm_tis_i2c.c
+++ b/drivers/char/tpm/tpm_tis_i2c.c
@@ -101,6 +101,7 @@ static int tpm_tis_i2c_write_bytes(struct tpm_tis_data *data, u32 addr,
 				   u16 len, const u8 *value)
 {
 	struct tpm_tis_i2c_phy *phy = to_tpm_tis_i2c_phy(data);
+	struct i2c_msg msgs[2];
 	int ret = 0;
 	int i = 0;
 
@@ -111,14 +112,10 @@ static int tpm_tis_i2c_write_bytes(struct tpm_tis_data *data, u32 addr,
 		phy->iobuf[0] = address_to_register(addr);
 		memcpy(phy->iobuf + 1, value, len);
 
-		struct i2c_msg msgs[] = {
-			{
-				.addr = phy->i2c_client->addr,
-				.len = len + 1,
-				.buf = phy->iobuf,
-			},
-		};
-
+		memset(msgs, 0, sizeof(msgs));
+		msgs[0].addr = phy->i2c_client->addr;
+		msgs[0].len = len + 1;
+		msgs[0].buf = phy->iobuf;
 		do {
 			ret = i2c_transfer(phy->i2c_client->adapter,
 					   msgs, ARRAY_SIZE(msgs));
@@ -127,21 +124,14 @@ static int tpm_tis_i2c_write_bytes(struct tpm_tis_data *data, u32 addr,
 		} while (ret < 0 && i++ < TPM_RETRY);
 	} else {
 		u8 reg = address_to_register(addr);
-
-		struct i2c_msg msgs[] = {
-			{
-				.addr = phy->i2c_client->addr,
-				.len = sizeof(reg),
-				.buf = &reg,
-			},
-			{
-				.addr = phy->i2c_client->addr,
-				.len = len,
-				.buf = (u8 *)value,
-				.flags = I2C_M_NOSTART,
-			},
-		};
-
+		memset(msgs, 0, sizeof(msgs));
+		msgs[0].addr = phy->i2c_client->addr;
+		msgs[0].len = sizeof(reg);
+		msgs[0].buf = ®
+		msgs[1].addr = phy->i2c_client->addr;
+		msgs[1].len = len;
+		msgs[1].buf = (u8 *)value;
+		msgs[1].flags = I2C_M_NOSTART;
 		do {
 			ret = i2c_transfer(phy->i2c_client->adapter, msgs,
 					   ARRAY_SIZE(msgs));
-- 
2.37.1



More information about the openbmc mailing list