[Cryptech-Commits] [sw/stm32] 01/02: Don't return from flash write calls until WIP flag clears.

git at cryptech.is git at cryptech.is
Tue Nov 1 17:41:20 UTC 2016


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch ksng
in repository sw/stm32.

commit fd3a9b8f032d5a696d0c7e283fdd2f7f0771306e
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Tue Nov 1 12:17:44 2016 -0400

    Don't return from flash write calls until WIP flag clears.
    
    Absence of this check created a nasty race condition in
    sw/libhal/ks_flash.c, which didn't show up until we had test code
    which attempted to delete a long series of keys in quick succession.
    
    I'm not aware of any sane reason why we would ever want to skip this
    check, so it's unconditional and applies to all of the SPI flash code,
    not just the keystore flash code.
---
 spiflash_n25q128.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/spiflash_n25q128.c b/spiflash_n25q128.c
index 728db7e..0c2abd7 100644
--- a/spiflash_n25q128.c
+++ b/spiflash_n25q128.c
@@ -356,6 +356,12 @@ int n25q128_write_data(struct spiflash_ctx *ctx, uint32_t offset, const uint8_t
 	 */
     }
 
+    /*
+     * Wait until last write finishes.
+     */
+
+    if (! _wait_while_wip(ctx, 1000)) return -7;
+
     return 1;
 }
 



More information about the Commits mailing list