]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
sf: Fix NULL pointer exception for flashes without lock methods
authorBin Meng <bmeng.cn@gmail.com>
Fri, 13 Nov 2015 10:46:26 +0000 (02:46 -0800)
committerTom Rini <trini@konsulko.com>
Fri, 13 Nov 2015 14:47:22 +0000 (09:47 -0500)
commit c3c016c "sf: Add SPI NOR protection mechanism" introduced
flash_lock()/flash_unlock()/flash_is_locked() methods for SPI flash,
but not every flash driver supplies these. We should test these
methods against NULL before actually calling them.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com>
Reviewed-by: Jagan Teki <jteki@openedev.com>
drivers/mtd/spi/sf_ops.c
include/spi_flash.h

index d8324645b2cbe8a9b51e7a4109d4b6beeac79e72..384224d75a74b6dc4b51ce3de32c86043fe9cb85 100644 (file)
@@ -268,9 +268,12 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
                return -1;
        }
 
-       if (flash->flash_is_locked(flash, offset, len) > 0) {
-               printf("offset 0x%x is protected and cannot be erased\n", offset);
-               return -EINVAL;
+       if (flash->flash_is_locked) {
+               if (flash->flash_is_locked(flash, offset, len) > 0) {
+                       printf("offset 0x%x is protected and cannot be erased\n",
+                              offset);
+                       return -EINVAL;
+               }
        }
 
        cmd[0] = flash->erase_cmd;
@@ -315,9 +318,12 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 
        page_size = flash->page_size;
 
-       if (flash->flash_is_locked(flash, offset, len) > 0) {
-               printf("offset 0x%x is protected and cannot be written\n", offset);
-               return -EINVAL;
+       if (flash->flash_is_locked) {
+               if (flash->flash_is_locked(flash, offset, len) > 0) {
+                       printf("offset 0x%x is protected and cannot be written\n",
+                              offset);
+                       return -EINVAL;
+               }
        }
 
        cmd[0] = flash->write_cmd;
index 0ae0062d12f5efbd2bfc132e2061c2342254e9e2..f25b3e7819c641b6a7f1f6231d01b1fea95e35c8 100644 (file)
@@ -237,7 +237,7 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
 static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
                                        bool prot)
 {
-       if (!flash->flash_lock)
+       if (!flash->flash_lock || !flash->flash_unlock)
                return -EOPNOTSUPP;
 
        if (prot)