]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
sf: Correct data types in stm_is_locked_sr()
authorMarek Vasut <marex@denx.de>
Fri, 11 Mar 2016 02:20:16 +0000 (03:20 +0100)
committerJagan Teki <jteki@openedev.com>
Sat, 12 Mar 2016 14:25:42 +0000 (19:55 +0530)
The stm_is_locked_sr() function is picked from Linux kernel. For reason
unknown, the 64bit data types used by the function and present in Linux
were replaced with 32bit unsigned ones, which causes trouble.

The testcase performed was done using ST M25P80 chip.
The command used was:
 => sf protect unlock 0 0x10000

The call chain starts in stm_unlock(), which calls stm_is_locked_sr()
with negative ofs argument. This works fine in Linux, where the "ofs"
is loff_t, which is signed long long, while this fails in U-Boot, where
"ofs" is u32 (unsigned int). Because of this signedness problem, the
expression past the return statement to be incorrectly evaluated to 1,
which in turn propagates back to stm_unlock() and results in -EINVAL.

The correction is very simple, just use the correctly sized data types
with correct signedness in the function to make it work as intended.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Reviewed-by: Jagan Teki <jteki@openedev.com>
drivers/mtd/spi/spi_flash.c

index 2ae2e3c8c9ad592713a4a5fd4c9448c343f98745..44d9e9ba01056aacaae85918925bb893144e6f7e 100644 (file)
@@ -665,7 +665,7 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
 
 #if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
 static void stm_get_locked_range(struct spi_flash *flash, u8 sr, loff_t *ofs,
-                                u32 *len)
+                                u64 *len)
 {
        u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
        int shift = ffs(mask) - 1;
@@ -685,11 +685,11 @@ static void stm_get_locked_range(struct spi_flash *flash, u8 sr, loff_t *ofs,
 /*
  * Return 1 if the entire region is locked, 0 otherwise
  */
-static int stm_is_locked_sr(struct spi_flash *flash, u32 ofs, u32 len,
+static int stm_is_locked_sr(struct spi_flash *flash, loff_t ofs, u64 len,
                            u8 sr)
 {
        loff_t lock_offs;
-       u32 lock_len;
+       u64 lock_len;
 
        stm_get_locked_range(flash, sr, &lock_offs, &lock_len);