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:
parent
7f2edeef6c
commit
e3ba01ec76
2 changed files with 6 additions and 1 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue