On 08/15/2019 11:32 AM, Dan Carpenter wrote: > External E-Mail > > > 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 <dan.carpenter@xxxxxxxxxx> Reviewed-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxxxxx> > --- > drivers/mtd/spi-nor/spi-nor.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c > index 63af87609bac..986b0754495d 100644 > --- a/drivers/mtd/spi-nor/spi-nor.c > +++ b/drivers/mtd/spi-nor/spi-nor.c > @@ -2903,10 +2903,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; > ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/