From 3eb8d6eb1d5ad9f3869284606f3dc4ce878d20e8 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Mon, 18 Nov 2019 17:18:03 +0200 Subject: [PATCH] BufferedBlockDevice: Sync all the buffers on deinit() Make sure that all data has been written on the underlying storage when we do deinit(). --- features/storage/blockdevice/BufferedBlockDevice.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/features/storage/blockdevice/BufferedBlockDevice.cpp b/features/storage/blockdevice/BufferedBlockDevice.cpp index 56b0e3172b..2a27049317 100644 --- a/features/storage/blockdevice/BufferedBlockDevice.cpp +++ b/features/storage/blockdevice/BufferedBlockDevice.cpp @@ -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; }