From 2ed2ec1711b13dd9a28bdc29ce8cba13ca7d503f Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Tue, 29 Jan 2019 15:20:01 +1100 Subject: [PATCH] drivers/memory/spiflash: Rework wait_sr to fix uninit'd variable 'sr'. --- drivers/memory/spiflash.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/memory/spiflash.c b/drivers/memory/spiflash.c index c0b55591be..22775d5416 100644 --- a/drivers/memory/spiflash.c +++ b/drivers/memory/spiflash.c @@ -128,19 +128,14 @@ STATIC void mp_spiflash_write_cmd_addr(mp_spiflash_t *self, uint8_t cmd, uint32_ STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) { uint8_t sr; - for (; timeout; --timeout) { + do { sr = mp_spiflash_read_cmd(self, CMD_RDSR, 1); if ((sr & mask) == val) { - break; + return 0; // success } - } - if ((sr & mask) == val) { - return 0; // success - } else if (timeout == 0) { - return -MP_ETIMEDOUT; - } else { - return -MP_EIO; - } + } while (timeout--); + + return -MP_ETIMEDOUT; } STATIC int mp_spiflash_wait_wel1(mp_spiflash_t *self) {