Skip to content

Commit aedc600

Browse files
committed
TDBStore: call BlockDevice::erase() regarless of erase value
From the documentations of `BlockDevice::get_erase_value()`: -1 if you can't rely on the value of the erased storage and `BlockDevice::program()`: The blocks must have been erased prior to being programmed So, `BlockDevice::erase()` should always be called regardless of erase value.
1 parent fb4e5e8 commit aedc600

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

storage/kvstore/tdbstore/source/TDBStore.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,12 @@ int TDBStore::erase_area(uint8_t area, uint32_t offset, uint32_t size)
174174
{
175175
uint32_t bd_offset = _area_params[area].address + offset;
176176

177-
if (_buff_bd->get_erase_value() != -1) {
178-
return _buff_bd->erase(bd_offset, size);
179-
} else {
177+
int ret = _buff_bd->erase(bd_offset, size);
178+
if (ret) {
179+
return ret;
180+
}
181+
182+
if (_buff_bd->get_erase_value() == -1) {
180183
// We need to simulate erase to wipe records, as our block device
181184
// may not do it. Program in chunks of _work_buf_size if the minimum
182185
// program size is too small (e.g. one-byte) to avoid performance
@@ -186,7 +189,7 @@ int TDBStore::erase_area(uint8_t area, uint32_t offset, uint32_t size)
186189
memset(_work_buf, 0xFF, _work_buf_size);
187190
while (size) {
188191
uint32_t chunk = std::min<uint32_t>(_work_buf_size, size);
189-
int ret = _buff_bd->program(_work_buf, bd_offset, chunk);
192+
ret = _buff_bd->program(_work_buf, bd_offset, chunk);
190193
if (ret) {
191194
return ret;
192195
}

0 commit comments

Comments
 (0)