Skip to contentSkip to conversation

sf: Fix NULL pointer exception for flashes without lock methods

PATCH In review Bin Meng 4 participants 5 messages Nov 13, 2015 Memory technology devices (MTD)

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/1 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.

---

 drivers/mtd/spi/sf_ops.c | 18 ++++++++++++------
 include/spi_flash.h      |  2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/mtd/spi/sf_ops.c +12 -6
index d832464..384224d 100644
@@ -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;
include/spi_flash.h +1 -1
index 0ae0062..f25b3e7 100644
@@ -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)
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH 1/1 sf: Fix NULL pointer exception for flashes without lock methods

Quoted 6 lines · Bin Meng

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.

Thanks for the fix.

author
#2 lore raw

PATCH 1/1 sf: Fix NULL pointer exception for flashes without lock methods

Hi Tom,

Quoted 11 lines · Fabio Estevam
Quoted 6 lines · Bin Meng

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.

Thanks for the fix.

Could you please apply this directly as this fix booting crash at least on Chromebook Link?

Regards,
Bin

#3 lore raw

PATCH 1/1 sf: Fix NULL pointer exception for flashes without lock methods

Quoted 10 lines · Bin Meng

Hi Tom,

Quoted 6 lines · Fabio Estevam
Quoted 5 lines · Bin Meng

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.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Thanks for the fix.

Could you please apply this directly as this fix booting crash at least on Chromebook Link?

#4 lore raw
In reply to Bin Meng
Quoted 8 lines · Bin Meng

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.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151113/4ac55502/attachment.sig>