]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: mctp-i2c: fix duplicate reception of old data
authorJian Zhang <zhangjian.3032@bytedance.com>
Thu, 8 Jan 2026 10:18:29 +0000 (18:18 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 13 Jan 2026 03:22:36 +0000 (19:22 -0800)
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>
Link: https://patch.msgid.link/20260108101829.1140448-1-zhangjian.3032@bytedance.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/mctp/mctp-i2c.c

index f782d93f826efcbde86137822895ab67c3b721c0..ecda1cc36391ce50a6b28e6a9e13c3b344f8f993 100644 (file)
@@ -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++;