Check return of BlockDevice::init() in TDBStore.

Return value was ignored, and TDBStore:init() ended up in a
MBED_ERROR() phase after that.

TDBStore API was limited to allow returning of only two separate
errors, which may end up hiding the actual return value. Change
the documentation slightly to allow returning of original error
code from the underlying block device.

Fixes #11591
pull/11595/head
Seppo Takalo 2019-09-30 11:02:49 +03:00
parent a1961de8a2
commit 513891d4f6
2 changed files with 18 additions and 3 deletions

View File

@ -1019,7 +1019,10 @@ int TDBStore::init()
_size = (size_t) -1;
_buff_bd = new BufferedBlockDevice(_bd);
_buff_bd->init();
ret = _buff_bd->init();
if (ret) {
goto fail;
}
// Underlying BD must have flash attributes, i.e. have an erase value
if (_bd->get_erase_value() == -1) {
@ -1140,6 +1143,19 @@ end:
_is_initialized = true;
_mutex.unlock();
return ret;
fail:
delete[] ram_table;
delete _buff_bd;
delete[] _work_buf;
delete[] _key_buf;
delete reinterpret_cast<inc_set_handle_t *>(_inc_set_handle);
_ram_table = nullptr;
_buff_bd = nullptr;
_work_buf = nullptr;
_key_buf = nullptr;
_inc_set_handle = nullptr;
_mutex.unlock();
return ret;
}
int TDBStore::deinit()

View File

@ -61,8 +61,7 @@ public:
* the available data and clean corrupted and erroneous records.
*
* @returns MBED_SUCCESS Success.
* MBED_ERROR_READ_FAILED Unable to read from media.
* MBED_ERROR_WRITE_FAILED Unable to write to media.
* @returns Negative error code on failure.
*/
virtual int init();