Skip to content

Commit

Permalink
Check return of BlockDevice::init() in TDBStore.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Seppo Takalo committed Sep 30, 2019
1 parent a1961de commit 664969d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 7 additions & 1 deletion features/storage/kvstore/tdbstore/TDBStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1140,6 +1143,9 @@ int TDBStore::init()
_is_initialized = true;
_mutex.unlock();
return ret;
fail:
mutex.unlock();
return ret;
}

int TDBStore::deinit()
Expand Down
3 changes: 1 addition & 2 deletions features/storage/kvstore/tdbstore/TDBStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class TDBStore : public KVStore {
* 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();

Expand Down

0 comments on commit 664969d

Please sign in to comment.