mtd: spi-nor: Fix an error code in spi_nor_read_raw()

The problem is that if "ret" is negative then when we check if
"ret > len", that condition is going to be true because of type
promotion.  So this patch re-orders the code to check for negatives
first and preserve those error codes.

Fixes: f384b352cb ("mtd: spi-nor: parse Serial Flash Discoverable Parameters (SFDP) tables")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
This commit is contained in:
Dan Carpenter 2019-08-15 11:32:52 +03:00 committed by Tudor Ambarus
parent 4262ee88f0
commit 3e9e38d918
No known key found for this signature in database
GPG Key ID: 4B554F47A58D14E9
1 changed files with 2 additions and 2 deletions

View File

@ -2907,10 +2907,10 @@ static int spi_nor_read_raw(struct spi_nor *nor, u32 addr, size_t len, u8 *buf)
while (len) { while (len) {
ret = spi_nor_read_data(nor, addr, len, buf); ret = spi_nor_read_data(nor, addr, len, buf);
if (!ret || ret > len)
return -EIO;
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!ret || ret > len)
return -EIO;
buf += ret; buf += ret;
addr += ret; addr += ret;