Skip to content
Snippets Groups Projects
Commit 439fcb9b authored by Bin Meng's avatar Bin Meng Committed by Tom Rini
Browse files

sf: Fix NULL pointer exception for flashes without lock methods


commit c3c016cf "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: default avatarBin Meng <bmeng.cn@gmail.com>
Reviewed-by: default avatarFabio Estevam <fabio.estevam@freescale.com>
Reviewed-by: default avatarJagan Teki <jteki@openedev.com>
parent 9ac4fc82
No related branches found
No related tags found
No related merge requests found
...@@ -268,9 +268,12 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) ...@@ -268,9 +268,12 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
return -1; return -1;
} }
if (flash->flash_is_locked(flash, offset, len) > 0) { if (flash->flash_is_locked) {
printf("offset 0x%x is protected and cannot be erased\n", offset); if (flash->flash_is_locked(flash, offset, len) > 0) {
return -EINVAL; printf("offset 0x%x is protected and cannot be erased\n",
offset);
return -EINVAL;
}
} }
cmd[0] = flash->erase_cmd; cmd[0] = flash->erase_cmd;
...@@ -315,9 +318,12 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, ...@@ -315,9 +318,12 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
page_size = flash->page_size; page_size = flash->page_size;
if (flash->flash_is_locked(flash, offset, len) > 0) { if (flash->flash_is_locked) {
printf("offset 0x%x is protected and cannot be written\n", offset); if (flash->flash_is_locked(flash, offset, len) > 0) {
return -EINVAL; printf("offset 0x%x is protected and cannot be written\n",
offset);
return -EINVAL;
}
} }
cmd[0] = flash->write_cmd; cmd[0] = flash->write_cmd;
......
...@@ -237,7 +237,7 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, ...@@ -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, static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
bool prot) bool prot)
{ {
if (!flash->flash_lock) if (!flash->flash_lock || !flash->flash_unlock)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (prot) if (prot)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment