git: b6a2aba959c8 - main - rk_i2c_transfer: fix off-by-one in check for last message

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Wed, 15 Dec 2021 11:16:42 UTC
The branch main has been updated by avg:

URL: https://cgit.FreeBSD.org/src/commit/?id=b6a2aba959c8b30d740c653c96c01fb90a3073f7

commit b6a2aba959c8b30d740c653c96c01fb90a3073f7
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2021-12-15 08:44:43 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2021-12-15 11:15:50 +0000

    rk_i2c_transfer: fix off-by-one in check for last message
    
    This also fixes an access beyond msgs array.
    
    MFC after:      1 week
---
 sys/arm64/rockchip/rk_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/arm64/rockchip/rk_i2c.c b/sys/arm64/rockchip/rk_i2c.c
index 5ee1b8e96744..55cea8895c43 100644
--- a/sys/arm64/rockchip/rk_i2c.c
+++ b/sys/arm64/rockchip/rk_i2c.c
@@ -539,7 +539,7 @@ rk_i2c_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
 			}
 		}
 		/* last message ? */
-		last_msg = (i > nmsgs - 1) ||
+		last_msg = (i >= nmsgs - 1) ||
 		    !(msgs[i + 1].flags & IIC_M_NOSTART);
 		rk_i2c_start_xfer(sc, msgs + i, last_msg);