]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
spi: cadence_qspi: Off by 1 in test for timeout
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Tue, 12 Aug 2025 11:34:38 +0000 (12:34 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 28 Oct 2025 16:27:40 +0000 (10:27 -0600)
In cadence_qspi_apb_exec_flash_cmd the test for a timeout uses a
post-decrement on the variable retry which will result in a value of -1
after the loop exit, or it would if the variable were signed.
To fix this make retry a signed variable and test its value for being
equal to -1.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
drivers/spi/cadence_qspi_apb.c

index 4696c09f754b2361c568b30778bbcbdb58c8df5b..0d4bc685f5dbf57f1389d2854a310ce357f32a16 100644 (file)
@@ -354,7 +354,7 @@ void cadence_qspi_apb_controller_init(struct cadence_spi_priv *priv)
 
 int cadence_qspi_apb_exec_flash_cmd(void *reg_base, unsigned int reg)
 {
-       unsigned int retry = CQSPI_REG_RETRY;
+       int retry = CQSPI_REG_RETRY;
 
        /* Write the CMDCTRL without start execution. */
        writel(reg, reg_base + CQSPI_REG_CMDCTRL);
@@ -369,7 +369,7 @@ int cadence_qspi_apb_exec_flash_cmd(void *reg_base, unsigned int reg)
                udelay(1);
        }
 
-       if (!retry) {
+       if (retry == -1) {
                printf("QSPI: flash command execution timeout\n");
                return -EIO;
        }