2023-07-26 08:48:28

by Tam Nguyen

[permalink] [raw]
Subject: [PATCH v2 1/2] i2c: designware: Correct length byte validation logic

From: Quan Nguyen <[email protected]>

Commit 0daede80f870 ("i2c: designware: Convert driver to using regmap API")
changes the logic to validate the whole 32-bit return value of
DW_IC_DATA_CMD register instead of 8-bit LSB without reason.

Later, commit f53f15ba5a85 ("i2c: designware: Get right data length"),
introduced partial fix but not enough because the "tmp > 0" still test
tmp as 32-bit value and is wrong in case the IC_DATA_CMD[11] is set.

Revert the logic to just before commit 0daede80f870
("i2c: designware: Convert driver to using regmap API").

Fixes: f53f15ba5a85 ("i2c: designware: Get right data length")
Fixes: 0daede80f870 ("i2c: designware: Convert driver to using regmap API")
Cc: [email protected]
Signed-off-by: Tam Nguyen <[email protected]>
Signed-off-by: Quan Nguyen <[email protected]>
---
drivers/i2c/busses/i2c-designware-master.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 55ea91a63382..e96276d1b002 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -526,9 +526,10 @@ i2c_dw_read(struct dw_i2c_dev *dev)
u32 flags = msgs[dev->msg_read_idx].flags;

regmap_read(dev->map, DW_IC_DATA_CMD, &tmp);
+ tmp &= DW_IC_DATA_CMD_DAT;
/* Ensure length byte is a valid value */
if (flags & I2C_M_RECV_LEN &&
- (tmp & DW_IC_DATA_CMD_DAT) <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {
+ tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) {
len = i2c_dw_recv_len(dev, tmp);
}
*buf++ = tmp;
--
2.25.1



2023-07-27 11:28:18

by Jarkko Nikula

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] i2c: designware: Correct length byte validation logic

On 7/26/23 11:00, Tam Nguyen wrote:
> From: Quan Nguyen <[email protected]>
>
> Commit 0daede80f870 ("i2c: designware: Convert driver to using regmap API")
> changes the logic to validate the whole 32-bit return value of
> DW_IC_DATA_CMD register instead of 8-bit LSB without reason.
>
> Later, commit f53f15ba5a85 ("i2c: designware: Get right data length"),
> introduced partial fix but not enough because the "tmp > 0" still test
> tmp as 32-bit value and is wrong in case the IC_DATA_CMD[11] is set.
>
> Revert the logic to just before commit 0daede80f870
> ("i2c: designware: Convert driver to using regmap API").
>
> Fixes: f53f15ba5a85 ("i2c: designware: Get right data length")
> Fixes: 0daede80f870 ("i2c: designware: Convert driver to using regmap API")
> Cc: [email protected]
> Signed-off-by: Tam Nguyen <[email protected]>
> Signed-off-by: Quan Nguyen <[email protected]>
> ---
> drivers/i2c/busses/i2c-designware-master.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
Acked-by: Jarkko Nikula <[email protected]>

2023-08-14 14:11:35

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] i2c: designware: Correct length byte validation logic

On Wed, Jul 26, 2023 at 03:00:00PM +0700, Tam Nguyen wrote:
> From: Quan Nguyen <[email protected]>
>
> Commit 0daede80f870 ("i2c: designware: Convert driver to using regmap API")
> changes the logic to validate the whole 32-bit return value of
> DW_IC_DATA_CMD register instead of 8-bit LSB without reason.
>
> Later, commit f53f15ba5a85 ("i2c: designware: Get right data length"),
> introduced partial fix but not enough because the "tmp > 0" still test
> tmp as 32-bit value and is wrong in case the IC_DATA_CMD[11] is set.
>
> Revert the logic to just before commit 0daede80f870
> ("i2c: designware: Convert driver to using regmap API").
>
> Fixes: f53f15ba5a85 ("i2c: designware: Get right data length")
> Fixes: 0daede80f870 ("i2c: designware: Convert driver to using regmap API")
> Cc: [email protected]
> Signed-off-by: Tam Nguyen <[email protected]>
> Signed-off-by: Quan Nguyen <[email protected]>

Applied to for-current, thanks!


Attachments:
(No filename) (0.99 kB)
signature.asc (849.00 B)
Download all attachments