From: Dan Carpenter Date: Thu, 15 Aug 2019 08:32:52 +0000 (+0300) Subject: mtd: spi-nor: Fix an error code in spi_nor_read_raw() X-Git-Tag: for-linus-2019-09-27~47^2~12^2~30 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=3e9e38d918bd01068b5ccba17d69a8ae9bf56142;p=linux-block.git 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: f384b352cbf0 ("mtd: spi-nor: parse Serial Flash Discoverable Parameters (SFDP) tables") Signed-off-by: Dan Carpenter Signed-off-by: Tudor Ambarus --- diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 3790830d0d99..ba99d903eda0 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -2907,10 +2907,10 @@ static int spi_nor_read_raw(struct spi_nor *nor, u32 addr, size_t len, u8 *buf) while (len) { ret = spi_nor_read_data(nor, addr, len, buf); - if (!ret || ret > len) - return -EIO; if (ret < 0) return ret; + if (!ret || ret > len) + return -EIO; buf += ret; addr += ret;