From: Peter Delevoryas <peter@pjd.dev>
To: peter@pjd.dev, patrick@stwcx.xyz, joel@jms.id.au,
openbmc@lists.ozlabs.org
Subject: [PATCH 1/1] tpm_tis_i2c: Fix -Wdeclaration-after-statement
Date: Mon, 25 Jul 2022 15:51:51 -0700 [thread overview]
Message-ID: <20220725225151.393384-2-peter@pjd.dev> (raw)
In-Reply-To: <20220725225151.393384-1-peter@pjd.dev>
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@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 = ®,
- },
- {
- .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
next prev parent reply other threads:[~2022-07-25 22:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 22:51 [PATCH 0/1] tpm_tis_i2c: Fix -Wdeclaration-after-statement Peter Delevoryas
2022-07-25 22:51 ` Peter Delevoryas [this message]
2022-07-29 0:21 ` Joel Stanley
2022-07-29 2:49 ` Peter Delevoryas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220725225151.393384-2-peter@pjd.dev \
--to=peter@pjd.dev \
--cc=joel@jms.id.au \
--cc=openbmc@lists.ozlabs.org \
--cc=patrick@stwcx.xyz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.