Skip to content

Commit 3eb8d6e

Browse files
author
Seppo Takalo
committed
BufferedBlockDevice: Sync all the buffers on deinit()
Make sure that all data has been written on the underlying storage when we do deinit().
1 parent 8ab3984 commit 3eb8d6e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

features/storage/blockdevice/BufferedBlockDevice.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ int BufferedBlockDevice::deinit()
7676
return BD_ERROR_OK;
7777
}
7878

79+
// Flush out all data from buffers
80+
int err = sync();
81+
if (err) {
82+
return err;
83+
}
84+
7985
uint32_t val = core_util_atomic_decr_u32(&_init_ref_count, 1);
8086

8187
if (val) {
@@ -208,7 +214,6 @@ int BufferedBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
208214
if (ret) {
209215
return ret;
210216
}
211-
_write_cache_addr = aligned_addr;
212217
}
213218

214219
// 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)
247252
if (ret) {
248253
return ret;
249254
}
255+
invalidate_write_cache();
250256
ret = _bd->sync();
251257
if (ret) {
252258
return ret;
253259
}
254-
invalidate_write_cache();
255260
} else {
256261
_write_cache_valid = true;
257262
}

0 commit comments

Comments
 (0)