Add missing ext_flash_close() and make order in xmem_erase() more sensible
@@ -115,6 +115,7 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
rv = ext_flash_write(NULL, addr + j, to_write, tmp_buf);
if(!rv) {
PRINTF("Could not write flash memory!\n");
+ ext_flash_close(NULL);
return size - remain;
}
}
@@ -128,14 +129,6 @@ xmem_erase(long size, unsigned long addr)
{
int rv;
- rv = ext_flash_open(NULL);
-
- if(!rv) {
- PRINTF("Could not open flash to save config\n");
- ext_flash_close(NULL);
- return -1;
- }
-
if(size % EXT_ERASE_UNIT_SIZE != 0) {
PRINTF("xmem_erase: bad size\n");
return -1;
@@ -146,6 +139,14 @@ xmem_erase(long size, unsigned long addr)
return -1;
}
+ rv = ext_flash_open(NULL);
+
+ if(!rv) {
+ PRINTF("Could not open flash to erase\n");
+ ext_flash_close(NULL);
+ return -1;
+ }
+
rv = ext_flash_erase(NULL, addr, size);
ext_flash_close(NULL);
