diff options
author | Bin Meng <bmeng.cn@gmail.com> | 2015-11-13 02:46:26 -0800 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2015-11-13 09:47:22 -0500 |
commit | 439fcb9b4f717f5a583014acb3e75b789564867c (patch) | |
tree | 896aa273c728253b8a6061c7d6710a7bc4bba13a /drivers/mtd/spi | |
parent | 9ac4fc82071ce346e3885118242ff45d22f69b82 (diff) | |
download | u-boot-imx-439fcb9b4f717f5a583014acb3e75b789564867c.zip u-boot-imx-439fcb9b4f717f5a583014acb3e75b789564867c.tar.gz u-boot-imx-439fcb9b4f717f5a583014acb3e75b789564867c.tar.bz2 |
sf: Fix NULL pointer exception for flashes without lock methods
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>
Diffstat (limited to 'drivers/mtd/spi')
-rw-r--r-- | drivers/mtd/spi/sf_ops.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index d832464..384224d 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -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; |