subsys/storage/flash_map: detect missing flash device

If the flash device is not configured, return an error rather than
dereferencing a null device pointer.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2019-07-20 16:56:01 -05:00 committed by Kumar Gala
commit e3ba01ec76
2 changed files with 6 additions and 1 deletions

View file

@ -80,7 +80,9 @@ int settings_backend_init(void)
rc = flash_area_get_sectors(DT_FLASH_AREA_STORAGE_ID, &cnt, rc = flash_area_get_sectors(DT_FLASH_AREA_STORAGE_ID, &cnt,
settings_fcb_area); settings_fcb_area);
if (rc != 0 && rc != -ENOMEM) { if (rc == -ENODEV) {
return rc;
} else if (rc != 0 && rc != -ENOMEM) {
k_panic(); k_panic();
} }

View file

@ -139,6 +139,9 @@ flash_page_cb cb, struct layout_data *cb_data)
cb_data->status = 0; cb_data->status = 0;
flash_dev = device_get_binding(fa->fa_dev_name); flash_dev = device_get_binding(fa->fa_dev_name);
if (flash_dev == NULL) {
return -ENODEV;
}
flash_page_foreach(flash_dev, cb, cb_data); flash_page_foreach(flash_dev, cb, cb_data);