* [PATCH 0/2] i2c: smbus: small cleanups in emulation function
@ 2021-01-12 15:12 Wolfram Sang
2021-01-12 15:12 ` [PATCH 1/2] i2c: smbus: don't abuse loop variable Wolfram Sang
2021-01-12 15:12 ` [PATCH 2/2] i2c: smbus: improve naming in i2c_smbus_xfer_emulated() Wolfram Sang
0 siblings, 2 replies; 5+ messages in thread
From: Wolfram Sang @ 2021-01-12 15:12 UTC (permalink / raw)
To: linux-i2c; +Cc: linux-renesas-soc, Wolfram Sang
To prepare for some bigger refactoring, remove those two minor nuisances
first.
Wolfram Sang (2):
i2c: smbus: don't abuse loop variable
i2c: smbus: improve naming in i2c_smbus_xfer_emulated()
drivers/i2c/i2c-core-smbus.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
--
2.29.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] i2c: smbus: don't abuse loop variable
2021-01-12 15:12 [PATCH 0/2] i2c: smbus: small cleanups in emulation function Wolfram Sang
@ 2021-01-12 15:12 ` Wolfram Sang
2021-01-28 9:15 ` Wolfram Sang
2021-01-12 15:12 ` [PATCH 2/2] i2c: smbus: improve naming in i2c_smbus_xfer_emulated() Wolfram Sang
1 sibling, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2021-01-12 15:12 UTC (permalink / raw)
To: linux-i2c; +Cc: linux-renesas-soc, Wolfram Sang
Don't use 'i' to carry data, make a specific variable for it. After the
move to memcpy recently, we can even remove 'i'.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/i2c-core-smbus.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index bf6bfe7c5cfe..6cda46913d89 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -324,7 +324,6 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
int num = read_write == I2C_SMBUS_READ ? 2 : 1;
- int i;
u8 partial_pec = 0;
int status;
struct i2c_msg msg[2] = {
@@ -340,6 +339,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
.buf = msgbuf1,
},
};
+ bool wants_pec = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
+ && size != I2C_SMBUS_I2C_BLOCK_DATA);
msgbuf0[0] = command;
switch (size) {
@@ -443,9 +444,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
return -EOPNOTSUPP;
}
- i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
- && size != I2C_SMBUS_I2C_BLOCK_DATA);
- if (i) {
+ if (wants_pec) {
/* Compute PEC if first message is a write */
if (!(msg[0].flags & I2C_M_RD)) {
if (num == 1) /* Write only */
@@ -468,7 +467,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
status = 0;
/* Check PEC if last message is a read */
- if (i && (msg[num-1].flags & I2C_M_RD)) {
+ if (wants_pec && (msg[num-1].flags & I2C_M_RD)) {
status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
if (status < 0)
goto cleanup;
--
2.29.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] i2c: smbus: improve naming in i2c_smbus_xfer_emulated()
2021-01-12 15:12 [PATCH 0/2] i2c: smbus: small cleanups in emulation function Wolfram Sang
2021-01-12 15:12 ` [PATCH 1/2] i2c: smbus: don't abuse loop variable Wolfram Sang
@ 2021-01-12 15:12 ` Wolfram Sang
2021-01-28 9:15 ` Wolfram Sang
1 sibling, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2021-01-12 15:12 UTC (permalink / raw)
To: linux-i2c; +Cc: linux-renesas-soc, Wolfram Sang
This may be just taste, but I think 'nmsgs' is way more readable than a
generic 'num' variable. Also, fix spaces around operators while here.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/i2c-core-smbus.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index 6cda46913d89..d2d32c0fd8c3 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -323,7 +323,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
*/
unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
- int num = read_write == I2C_SMBUS_READ ? 2 : 1;
+ int nmsgs = read_write == I2C_SMBUS_READ ? 2 : 1;
u8 partial_pec = 0;
int status;
struct i2c_msg msg[2] = {
@@ -349,13 +349,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
/* Special case: The read/write field is used as data */
msg[0].flags = flags | (read_write == I2C_SMBUS_READ ?
I2C_M_RD : 0);
- num = 1;
+ nmsgs = 1;
break;
case I2C_SMBUS_BYTE:
if (read_write == I2C_SMBUS_READ) {
/* Special case: only a read! */
msg[0].flags = I2C_M_RD | flags;
- num = 1;
+ nmsgs = 1;
}
break;
case I2C_SMBUS_BYTE_DATA:
@@ -376,7 +376,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
}
break;
case I2C_SMBUS_PROC_CALL:
- num = 2; /* Special case */
+ nmsgs = 2; /* Special case */
read_write = I2C_SMBUS_READ;
msg[0].len = 3;
msg[1].len = 2;
@@ -403,7 +403,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
}
break;
case I2C_SMBUS_BLOCK_PROC_CALL:
- num = 2; /* Another special case */
+ nmsgs = 2; /* Another special case */
read_write = I2C_SMBUS_READ;
if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
dev_err(&adapter->dev,
@@ -447,28 +447,28 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
if (wants_pec) {
/* Compute PEC if first message is a write */
if (!(msg[0].flags & I2C_M_RD)) {
- if (num == 1) /* Write only */
+ if (nmsgs == 1) /* Write only */
i2c_smbus_add_pec(&msg[0]);
else /* Write followed by read */
partial_pec = i2c_smbus_msg_pec(0, &msg[0]);
}
/* Ask for PEC if last message is a read */
- if (msg[num-1].flags & I2C_M_RD)
- msg[num-1].len++;
+ if (msg[nmsgs - 1].flags & I2C_M_RD)
+ msg[nmsgs - 1].len++;
}
- status = __i2c_transfer(adapter, msg, num);
+ status = __i2c_transfer(adapter, msg, nmsgs);
if (status < 0)
goto cleanup;
- if (status != num) {
+ if (status != nmsgs) {
status = -EIO;
goto cleanup;
}
status = 0;
/* Check PEC if last message is a read */
- if (wants_pec && (msg[num-1].flags & I2C_M_RD)) {
- status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
+ if (wants_pec && (msg[nmsgs - 1].flags & I2C_M_RD)) {
+ status = i2c_smbus_check_pec(partial_pec, &msg[nmsgs - 1]);
if (status < 0)
goto cleanup;
}
--
2.29.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] i2c: smbus: don't abuse loop variable
2021-01-12 15:12 ` [PATCH 1/2] i2c: smbus: don't abuse loop variable Wolfram Sang
@ 2021-01-28 9:15 ` Wolfram Sang
0 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2021-01-28 9:15 UTC (permalink / raw)
To: linux-i2c; +Cc: linux-renesas-soc
[-- Attachment #1: Type: text/plain, Size: 294 bytes --]
On Tue, Jan 12, 2021 at 04:12:29PM +0100, Wolfram Sang wrote:
> Don't use 'i' to carry data, make a specific variable for it. After the
> move to memcpy recently, we can even remove 'i'.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] i2c: smbus: improve naming in i2c_smbus_xfer_emulated()
2021-01-12 15:12 ` [PATCH 2/2] i2c: smbus: improve naming in i2c_smbus_xfer_emulated() Wolfram Sang
@ 2021-01-28 9:15 ` Wolfram Sang
0 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2021-01-28 9:15 UTC (permalink / raw)
To: linux-i2c; +Cc: linux-renesas-soc
[-- Attachment #1: Type: text/plain, Size: 315 bytes --]
On Tue, Jan 12, 2021 at 04:12:30PM +0100, Wolfram Sang wrote:
> This may be just taste, but I think 'nmsgs' is way more readable than a
> generic 'num' variable. Also, fix spaces around operators while here.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-01-28 9:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 15:12 [PATCH 0/2] i2c: smbus: small cleanups in emulation function Wolfram Sang
2021-01-12 15:12 ` [PATCH 1/2] i2c: smbus: don't abuse loop variable Wolfram Sang
2021-01-28 9:15 ` Wolfram Sang
2021-01-12 15:12 ` [PATCH 2/2] i2c: smbus: improve naming in i2c_smbus_xfer_emulated() Wolfram Sang
2021-01-28 9:15 ` Wolfram Sang
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.