storage/flash_map: Return -ENODEV from flash_area_open

The commit adds check, to flash_area_open, whether there is any
device driver attached and returns -ENODEV if there isn't any.
This works around a problem where flash_area_open succeeds but
consecutive read/write causes crash.
It is enough to check the condition, and return error, here as
the flash_area_open has to precede, and be checked for success,
any read/write operations.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
Dominik Ermel 2022-05-13 15:44:30 +00:00 committed by Carles Cufí
commit aa5d20aaef
2 changed files with 7 additions and 1 deletions

View file

@ -118,7 +118,8 @@ int flash_area_check_int_sha256(const struct flash_area *fa,
* @p ID is unknown, it will be NULL on output. * @p ID is unknown, it will be NULL on output.
* *
* @return 0 on success, -EACCES if the flash_map is not available , * @return 0 on success, -EACCES if the flash_map is not available ,
* -ENOENT if @p ID is unknown. * -ENOENT if @p ID is unknown, -EDEV if there is not driver attached
* to the area.
*/ */
int flash_area_open(uint8_t id, const struct flash_area **fa); int flash_area_open(uint8_t id, const struct flash_area **fa);

View file

@ -37,7 +37,12 @@ int flash_area_open(uint8_t id, const struct flash_area **fap)
return -ENOENT; return -ENOENT;
} }
if (device_get_binding(area->fa_dev_name) == NULL) {
return -ENODEV;
}
*fap = area; *fap = area;
return 0; return 0;
} }