[PATCH] i2c: rockchip: fix transfer return value

Ahmad Fatoum a.fatoum at pengutronix.de
Tue May 10 08:36:57 PDT 2022


barebox (and kernel) API is for i2c_adapter::master_xfer to return the
number of successfully transmitted messages and a negative value on
error. This was not observed in the Rockchip driver, fix this.

Reported-by: Matthias Fend <matthias.fend at emfend.at>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
Only compile-tested, but change looks innocuous enough.
---
 drivers/i2c/busses/i2c-rockchip.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rockchip.c b/drivers/i2c/busses/i2c-rockchip.c
index 4990735a4b11..ca339053356c 100644
--- a/drivers/i2c/busses/i2c-rockchip.c
+++ b/drivers/i2c/busses/i2c-rockchip.c
@@ -375,15 +375,17 @@ i2c_exit:
 	return err;
 }
 
-static int rockchip_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msg,
+static int rockchip_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
 			     int nmsgs)
 {
 	struct rk_i2c *i2c = to_rk_i2c(adapter);
 	struct device_d *dev = &adapter->dev;
-	int ret;
+	int i, ret = 0;
 
 	dev_dbg(dev, "i2c_xfer: %d messages\n", nmsgs);
-	for (; nmsgs > 0; nmsgs--, msg++) {
+	for (i = 0; i < nmsgs; i++) {
+		struct i2c_msg *msg = &msgs[i];
+
 		dev_dbg(dev, "i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len);
 		if (msg->flags & I2C_M_RD) {
 			ret = rk_i2c_read(i2c, msg->addr, 0, 0, msg->buf,
@@ -395,14 +397,15 @@ static int rockchip_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msg,
 		if (ret) {
 			dev_dbg(dev, "i2c_write: error sending: %pe\n",
 				ERR_PTR(ret));
-			return -EREMOTEIO;
+			ret = -EREMOTEIO;
+			break;
 		}
 	}
 
 	rk_i2c_send_stop_bit(i2c);
 	rk_i2c_disable(i2c);
 
-	return 0;
+	return ret < 0 ? ret : nmsgs;
 }
 
 static int rk_i2c_probe(struct device_d *dev)
-- 
2.30.2




More information about the barebox mailing list