mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] i2c: rockchip: fix transfer return value
@ 2022-05-10 15:36 Ahmad Fatoum
  2022-05-11  6:45 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-05-10 15:36 UTC (permalink / raw)
  To: barebox; +Cc: Matthias Fend, Ahmad Fatoum

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@emfend.at>
Signed-off-by: Ahmad Fatoum <a.fatoum@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] i2c: rockchip: fix transfer return value
  2022-05-10 15:36 [PATCH] i2c: rockchip: fix transfer return value Ahmad Fatoum
@ 2022-05-11  6:45 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-05-11  6:45 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, Matthias Fend

On Tue, May 10, 2022 at 05:36:57PM +0200, Ahmad Fatoum wrote:
> 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@emfend.at>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Only compile-tested, but change looks innocuous enough.
> ---
>  drivers/i2c/busses/i2c-rockchip.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)

Applied, thanks

Sascha

> 
> 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
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-11  6:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 15:36 [PATCH] i2c: rockchip: fix transfer return value Ahmad Fatoum
2022-05-11  6:45 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox