Merge pull request #8986 from davidsaada/david_tdbstore_fixes

Fix a few bugs in TDBStore and KV config
pull/7596/head
Cruz Monrreal 2018-12-10 10:16:37 -06:00 committed by GitHub
commit eec536b332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 12 deletions

View File

@ -572,6 +572,12 @@ int _storage_config_TDB_INTERNAL()
return MBED_ERROR_INVALID_ARGUMENT;
}
ret = kvstore_config.internal_bd->deinit();
if (ret != MBED_SUCCESS) {
tr_error("KV Config: Fail to deinit internal BlockDevice.");
return MBED_ERROR_FAILED_OPERATION;
}
static TDBStore tdb_internal(kvstore_config.internal_bd);
kvstore_config.internal_store = &tdb_internal;
@ -737,7 +743,7 @@ int _storage_config_tdb_external_common()
if (_calculate_blocksize_match_tdbstore(kvstore_config.external_bd) != MBED_SUCCESS) {
tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
return MBED_ERROR_INVALID_ARGUMENT;
return MBED_ERROR_INVALID_SIZE;
}
static TDBStore tdb_external(kvstore_config.external_bd);

View File

@ -78,8 +78,6 @@ exit:
void KVMap::deinit_partition(kv_map_entry_t *partition)
{
free(partition->partition_name);
if (partition->kv_config == NULL) {
return;
}
@ -88,22 +86,15 @@ void KVMap::deinit_partition(kv_map_entry_t *partition)
partition->kv_config->external_store->deinit();
}
// TODO: this should be removed after FS APIs are standardized
if (partition->kv_config->external_fs != NULL) {
partition->kv_config->external_fs->unmount();
}
if (partition->kv_config->external_bd != NULL) {
partition->kv_config->external_bd->deinit();
}
if (partition->kv_config->internal_store != NULL) {
partition->kv_config->internal_store->deinit();
}
if (partition->kv_config->internal_bd != NULL) {
partition->kv_config->internal_bd->deinit();
}
if (partition->kv_config->kvstore_main_instance != NULL) {
partition->kv_config->kvstore_main_instance->deinit();
}

View File

@ -22,7 +22,6 @@
#include <string.h>
#include <stdio.h>
#include "mbed_error.h"
#include "mbed_assert.h"
#include "mbed_wait_api.h"
#include "MbedCRC.h"
@ -228,6 +227,11 @@ int TDBStore::read_record(uint8_t area, uint32_t offset, char *key,
total_size = key_size + data_size;
// Make sure our read sizes didn't cause any wraparounds
if ((total_size < key_size) || (total_size < data_size)) {
return MBED_ERROR_INVALID_DATA_DETECTED;
}
if (offset + total_size >= _size) {
return MBED_ERROR_INVALID_DATA_DETECTED;
}
@ -883,6 +887,7 @@ int TDBStore::build_ram_table()
if (ret == MBED_ERROR_ITEM_NOT_FOUND) {
// Key doesn't exist, need to add it to RAM table
ret = MBED_SUCCESS;
if (flags & delete_flag) {
continue;
@ -946,6 +951,10 @@ int TDBStore::init()
_mutex.lock();
if (_is_initialized) {
goto end;
}
_max_keys = initial_max_keys;
ram_table = new ram_table_entry_t[_max_keys];