diff --git a/subsys/storage/stream/stream_flash.c b/subsys/storage/stream/stream_flash.c index 63455af6d2899de..2ed383db32e0117 100644 --- a/subsys/storage/stream/stream_flash.c +++ b/subsys/storage/stream/stream_flash.c @@ -328,6 +328,15 @@ int stream_flash_init(struct stream_flash_ctx *ctx, const struct device *fdev, } #ifdef CONFIG_STREAM_FLASH_PROGRESS +static int stream_flash_settings_init(void) +{ + int rc = settings_subsys_init(); + + if (rc != 0) { + LOG_ERR("Error %d initializing settings subsystem", rc); + } + return rc; +} int stream_flash_progress_load(struct stream_flash_ctx *ctx, const char *settings_key) @@ -336,9 +345,12 @@ int stream_flash_progress_load(struct stream_flash_ctx *ctx, return -EFAULT; } - int rc = settings_load_subtree_direct(settings_key, - settings_direct_loader, - (void *) ctx); + int rc = stream_flash_settings_init(); + + if (rc == 0) { + rc = settings_load_subtree_direct(settings_key, settings_direct_loader, + (void *)ctx); + } if (rc != 0) { LOG_ERR("Error %d while loading progress for \"%s\"", @@ -355,9 +367,13 @@ int stream_flash_progress_save(const struct stream_flash_ctx *ctx, return -EFAULT; } - int rc = settings_save_one(settings_key, - &ctx->bytes_written, - sizeof(ctx->bytes_written)); + int rc = stream_flash_settings_init(); + + if (rc == 0) { + rc = settings_save_one(settings_key, + &ctx->bytes_written, + sizeof(ctx->bytes_written)); + } if (rc != 0) { LOG_ERR("Error %d while storing progress for \"%s\"", @@ -374,7 +390,11 @@ int stream_flash_progress_clear(const struct stream_flash_ctx *ctx, return -EFAULT; } - int rc = settings_delete(settings_key); + int rc = stream_flash_settings_init(); + + if (rc == 0) { + rc = settings_delete(settings_key); + } if (rc != 0) { LOG_ERR("Error %d while deleting progress for \"%s\"",