Re: [PATCH] i2c: rockchip: fix transfer return value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> ---
> 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@xxxxxxxxxxxxxxxxxxx
> 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux