diff mbox series

[U-Boot,v2,1/2] xilinx_xiic: Fix fill tx fifo loop

Message ID 20190625132929.97027-1-tomas.melin@vaisala.com
State Superseded
Delegated to: Heiko Schocher
Headers show
Series [U-Boot,v2,1/2] xilinx_xiic: Fix fill tx fifo loop | expand

Commit Message

Tomas Melin June 25, 2019, 1:29 p.m. UTC
Comparison should be against the actual message length, not loop index.

len is used for stopping while loop, pos is position in message.
stop should be sent when entire message is sent, not when
len and pos meet.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---

Changes in v2:
- Added reasoning to commit message

 drivers/i2c/xilinx_xiic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marek Vasut June 25, 2019, 3:14 p.m. UTC | #1
On 6/25/19 3:29 PM, Melin Tomas wrote:
> Comparison should be against the actual message length, not loop index.
> 
> len is used for stopping while loop, pos is position in message.
> stop should be sent when entire message is sent, not when
> len and pos meet.

Thanks. Just be careful to clamp the transfer length to 65535 bytes,
otherwise you'll hit another overflow.

> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
> ---
> 
> Changes in v2:
> - Added reasoning to commit message
> 
>  drivers/i2c/xilinx_xiic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/xilinx_xiic.c b/drivers/i2c/xilinx_xiic.c
> index 83114ed510..e4ca0ab936 100644
> --- a/drivers/i2c/xilinx_xiic.c
> +++ b/drivers/i2c/xilinx_xiic.c
> @@ -149,7 +149,7 @@ static void xiic_fill_tx_fifo(struct xilinx_xiic_priv *priv,
>  	while (len--) {
>  		u16 data = msg->buf[pos++];
>  
> -		if (pos == len && nmsgs == 1) {
> +		if ((msg->len - pos == 0) && nmsgs == 1) {
>  			/* last message in transfer -> STOP */
>  			data |= XIIC_TX_DYN_STOP_MASK;
>  		}
>
diff mbox series

Patch

diff --git a/drivers/i2c/xilinx_xiic.c b/drivers/i2c/xilinx_xiic.c
index 83114ed510..e4ca0ab936 100644
--- a/drivers/i2c/xilinx_xiic.c
+++ b/drivers/i2c/xilinx_xiic.c
@@ -149,7 +149,7 @@  static void xiic_fill_tx_fifo(struct xilinx_xiic_priv *priv,
 	while (len--) {
 		u16 data = msg->buf[pos++];
 
-		if (pos == len && nmsgs == 1) {
+		if ((msg->len - pos == 0) && nmsgs == 1) {
 			/* last message in transfer -> STOP */
 			data |= XIIC_TX_DYN_STOP_MASK;
 		}