Commit a3cf3f80 authored by Artur Tynecki's avatar Artur Tynecki Committed by David Brown
Browse files

mbed: Fix calling to BlockDevice::size before initialization



These changes fixes a bug that can cause an uninitialized BlockDevice
to be queried for its size. In some cases, this can return unexpected
results (eg: 0). Move setting block device size after its
initialization.
Co-created: @AGlass0fMilk - George Beckstein

Signed-off-by: default avatarArtur Tynecki <artur.tynecki@mobica.com>
Signed-off-by: default avatarGeorge Beckstein <george.beckstein@gmail.com>
parent 6822365e
...@@ -91,15 +91,22 @@ int flash_area_open(uint8_t id, const struct flash_area** fapp) { ...@@ -91,15 +91,22 @@ int flash_area_open(uint8_t id, const struct flash_area** fapp) {
fap->fa_device_id = 0; // not relevant fap->fa_device_id = 0; // not relevant
mbed::BlockDevice* bd = flash_map_bd[id]; mbed::BlockDevice* bd = flash_map_bd[id];
fap->fa_size = (uint32_t) bd->size();
/* Only initialize if this isn't a nested call to open the flash area */ /* Only initialize if this isn't a nested call to open the flash area */
if (open_count[id] == 1) { if (open_count[id] == 1) {
MCUBOOT_LOG_DBG("initializing flash area %d...", id); MCUBOOT_LOG_DBG("initializing flash area %d...", id);
return bd->init(); int ret = bd->init();
if (ret)
{
MCUBOOT_LOG_ERR("initializing flash area failed %d", ret);
return ret;
}
} else { } else {
return 0; return 0;
} }
fap->fa_size = (uint32_t) bd->size();
return 0;
} }
void flash_area_close(const struct flash_area* fap) { void flash_area_close(const struct flash_area* fap) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment