Skip to content
Permalink
Browse files

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>
  • Loading branch information...
pabigot authored and galak committed Jul 20, 2019
1 parent 7f2edee commit e3ba01ec76bcfcde36091ff75161730d17f8bb5e
Showing with 6 additions and 1 deletion.
  1. +3 −1 subsys/settings/src/settings_init.c
  2. +3 −0 subsys/storage/flash_map/flash_map.c
@@ -80,7 +80,9 @@ int settings_backend_init(void)

rc = flash_area_get_sectors(DT_FLASH_AREA_STORAGE_ID, &cnt,
settings_fcb_area);
if (rc != 0 && rc != -ENOMEM) {
if (rc == -ENODEV) {
return rc;
} else if (rc != 0 && rc != -ENOMEM) {
k_panic();
}

@@ -139,6 +139,9 @@ flash_page_cb cb, struct layout_data *cb_data)
cb_data->status = 0;

flash_dev = device_get_binding(fa->fa_dev_name);
if (flash_dev == NULL) {
return -ENODEV;
}

flash_page_foreach(flash_dev, cb, cb_data);

0 comments on commit e3ba01e

Please sign in to comment.
You can’t perform that action at this time.