diff mbox

spi: atmel: fix incorrect comparison

Message ID 1399391081-16095-1-git-send-email-alexandre.belloni@free-electrons.com (mailing list archive)
State Accepted
Commit b112f0585edd1c10e4986373d93ab0d95d12da82
Headers show

Commit Message

Alexandre Belloni May 6, 2014, 3:44 p.m. UTC
Found using smatch:
drivers/spi/spi-atmel.c:878 atmel_spi_pump_pio_data() warn: unsigned
'as->current_remaining_bytes' is never less than zero.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/spi/spi-atmel.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Nicolas Ferre May 6, 2014, 3:57 p.m. UTC | #1
On 06/05/2014 17:44, Alexandre Belloni :
> Found using smatch:
> drivers/spi/spi-atmel.c:878 atmel_spi_pump_pio_data() warn: unsigned
> 'as->current_remaining_bytes' is never less than zero.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

Yes as the variable is declared as unsigned:

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>


> ---
>  drivers/spi/spi-atmel.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> index 079e6b1b0cdb..39417fd8462f 100644
> --- a/drivers/spi/spi-atmel.c
> +++ b/drivers/spi/spi-atmel.c
> @@ -874,8 +874,9 @@ atmel_spi_pump_pio_data(struct atmel_spi *as, struct spi_transfer *xfer)
>  		spi_readl(as, RDR);
>  	}
>  	if (xfer->bits_per_word > 8) {
> -		as->current_remaining_bytes -= 2;
> -		if (as->current_remaining_bytes < 0)
> +		if (as->current_remaining_bytes > 2)
> +			as->current_remaining_bytes -= 2;
> +		else
>  			as->current_remaining_bytes = 0;
>  	} else {
>  		as->current_remaining_bytes--;
>
Mark Brown May 7, 2014, 7:50 p.m. UTC | #2
On Tue, May 06, 2014 at 05:44:41PM +0200, Alexandre Belloni wrote:
> Found using smatch:
> drivers/spi/spi-atmel.c:878 atmel_spi_pump_pio_data() warn: unsigned
> 'as->current_remaining_bytes' is never less than zero.

Applied, thanks.
diff mbox

Patch

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 079e6b1b0cdb..39417fd8462f 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -874,8 +874,9 @@  atmel_spi_pump_pio_data(struct atmel_spi *as, struct spi_transfer *xfer)
 		spi_readl(as, RDR);
 	}
 	if (xfer->bits_per_word > 8) {
-		as->current_remaining_bytes -= 2;
-		if (as->current_remaining_bytes < 0)
+		if (as->current_remaining_bytes > 2)
+			as->current_remaining_bytes -= 2;
+		else
 			as->current_remaining_bytes = 0;
 	} else {
 		as->current_remaining_bytes--;