[PATCH] net: mctp-i2c: fix duplicate reception of old data

Jian Zhang posted 1 patch 1 month ago
drivers/net/mctp/mctp-i2c.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] net: mctp-i2c: fix duplicate reception of old data
Posted by Jian Zhang 1 month ago
The MCTP I2C slave callback did not handle I2C_SLAVE_READ_REQUESTED
events. As a result, i2c read event will trigger repeated reception of
old data, reset rx_pos when a read request is received.

Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
---
 drivers/net/mctp/mctp-i2c.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/mctp/mctp-i2c.c b/drivers/net/mctp/mctp-i2c.c
index f782d93f826e..ecda1cc36391 100644
--- a/drivers/net/mctp/mctp-i2c.c
+++ b/drivers/net/mctp/mctp-i2c.c
@@ -242,6 +242,9 @@ static int mctp_i2c_slave_cb(struct i2c_client *client,
 		return 0;
 
 	switch (event) {
+	case I2C_SLAVE_READ_REQUESTED:
+		midev->rx_pos = 0;
+		break;
 	case I2C_SLAVE_WRITE_RECEIVED:
 		if (midev->rx_pos < MCTP_I2C_BUFSZ) {
 			midev->rx_buffer[midev->rx_pos] = *val;
@@ -279,6 +282,9 @@ static int mctp_i2c_recv(struct mctp_i2c_dev *midev)
 	size_t recvlen;
 	int status;
 
+	if (midev->rx_pos == 0)
+		return 0;
+
 	/* + 1 for the PEC */
 	if (midev->rx_pos < MCTP_I2C_MINLEN + 1) {
 		ndev->stats.rx_length_errors++;
-- 
2.20.1
Re: [PATCH] net: mctp-i2c: fix duplicate reception of old data
Posted by Jeremy Kerr 1 month ago
Hi Jian,

> The MCTP I2C slave callback did not handle I2C_SLAVE_READ_REQUESTED
> events. As a result, i2c read event will trigger repeated reception
> of old data, reset rx_pos when a read request is received.

Makes sense. You're just invoking any i2c read from the peer controller
to trigger this, is that right?

Cheers,


Jeremy
Re: [PATCH] net: mctp-i2c: fix duplicate reception of old data
Posted by Jian Zhang 1 month ago
Hi Jeremy,
 
> > The MCTP I2C slave callback did not handle I2C_SLAVE_READ_REQUESTED
> > events. As a result, i2c read event will trigger repeated reception
> > of old data, reset rx_pos when a read request is received.
> 
> Makes sense. You're just invoking any i2c read from the peer controller
> to trigger this, is that right?

Yes, the peer just send a i2c read, like `i2cdetect -r -y 4`.

Jian.