From aa5d20aaefa267360e24839fddb46811a03ca57c Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 13 May 2022 15:44:30 +0000 Subject: [PATCH] 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 --- include/zephyr/storage/flash_map.h | 3 ++- subsys/storage/flash_map/flash_map.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/zephyr/storage/flash_map.h b/include/zephyr/storage/flash_map.h index dda7f78a513..1cac47bebf5 100644 --- a/include/zephyr/storage/flash_map.h +++ b/include/zephyr/storage/flash_map.h @@ -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. * * @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); diff --git a/subsys/storage/flash_map/flash_map.c b/subsys/storage/flash_map/flash_map.c index d36f8d5db31..2821df5ad7e 100644 --- a/subsys/storage/flash_map/flash_map.c +++ b/subsys/storage/flash_map/flash_map.c @@ -37,7 +37,12 @@ int flash_area_open(uint8_t id, const struct flash_area **fap) return -ENOENT; } + if (device_get_binding(area->fa_dev_name) == NULL) { + return -ENODEV; + } + *fap = area; + return 0; }