[PATCH] mtd: spi: flash_is_unlocked return values fix
Stanislav Bolshakov
Stanislav.Bolshakov at synopsys.com
Fri Oct 27 15:49:24 CEST 2023
In accordance with the name of the function 'flash_is_unlocked()',
it is implied that the return value will be either 'true' or 'false'.
Moreover, calling this function from other parts of the program is
based precisely on this fact. The value of the pointer to the actual
called function 'flash_is_unlocked()' depends on the memory manufacturer
and can be stm_is_unlocked() or sst26_is_unlocked(). These two
functions have inconsistent return values. This patch fixes this
inconsistency.
---
drivers/mtd/spi/spi-nor-core.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index db20feb4da..100fce624b 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -1373,18 +1373,21 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
* Check if a region of the flash is (completely) unlocked. See stm_lock() for
* more info.
*
- * Returns 1 if entire region is unlocked, 0 if any portion is locked, and
- * negative on errors.
+ * Returns 1 if entire region is unlocked, 0 if any portion is locked or
+ * on errors.
*/
static int stm_is_unlocked(struct spi_nor *nor, loff_t ofs, uint64_t len)
{
int status;
+ int rv;
status = read_sr(nor);
if (status < 0)
- return status;
+ return 0;
- return stm_is_unlocked_sr(nor, ofs, len, status);
+ rv = stm_is_unlocked_sr(nor, ofs, len, status);
+
+ return (rv == 1) ? 1 : 0;
}
#endif /* CONFIG_SPI_FLASH_STMICRO */
@@ -1617,11 +1620,13 @@ static int sst26_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
}
/*
- * Returns EACCES (positive value) if region is (partially) locked, 0 if region
- * is completely unlocked, and negative on errors.
+ * Returns 1 if region is completely unlocked
+ * and 0 on errors or if region is (partially) locked.
*/
static int sst26_is_unlocked(struct spi_nor *nor, loff_t ofs, uint64_t len)
{
+ int rv;
+
/*
* is_unlocked function is used for check before reading or erasing
* flash region, so offset and length might be not 64k aligned, so
@@ -1631,7 +1636,8 @@ static int sst26_is_unlocked(struct spi_nor *nor, loff_t ofs, uint64_t len)
ofs -= ofs & (SZ_64K - 1);
len = len & (SZ_64K - 1) ? (len & ~(SZ_64K - 1)) + SZ_64K : len;
- return !sst26_lock_ctl(nor, ofs, len, SST26_CTL_CHECK);
+ rv = sst26_lock_ctl(nor, ofs, len, SST26_CTL_CHECK);
+ return (rv == 0) ? 1 : 0;
}
static int sst_write_byteprogram(struct spi_nor *nor, loff_t to, size_t len,
--
2.30.2
More information about the U-Boot
mailing list