BufferedBlockDevice: Sync all the buffers on deinit()

Make sure that all data has been written on the underlying
storage when we do deinit().
pull/11986/head
Seppo Takalo 2019-11-18 17:18:03 +02:00
parent 8ab3984d33
commit 3eb8d6eb1d
1 changed files with 7 additions and 2 deletions

View File

@ -76,6 +76,12 @@ int BufferedBlockDevice::deinit()
return BD_ERROR_OK;
}
// Flush out all data from buffers
int err = sync();
if (err) {
return err;
}
uint32_t val = core_util_atomic_decr_u32(&_init_ref_count, 1);
if (val) {
@ -208,7 +214,6 @@ int BufferedBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
if (ret) {
return ret;
}
_write_cache_addr = aligned_addr;
}
// Write logic: Keep data in cache as long as we don't reach the end of the program unit.
@ -247,11 +252,11 @@ int BufferedBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
if (ret) {
return ret;
}
invalidate_write_cache();
ret = _bd->sync();
if (ret) {
return ret;
}
invalidate_write_cache();
} else {
_write_cache_valid = true;
}