Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage/stream_flash: Initialize settings at point of use #81867

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions subsys/storage/stream/stream_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,6 @@ int stream_flash_init(struct stream_flash_ctx *ctx, const struct device *fdev,
return -EFAULT;
}

#ifdef CONFIG_STREAM_FLASH_PROGRESS
int rc = settings_subsys_init();

if (rc != 0) {
LOG_ERR("Error %d initializing settings subsystem", rc);
return rc;
}
#endif

struct _inspect_flash inspect_flash_ctx = {
.buf_len = buf_len,
.total_size = 0
Expand Down Expand Up @@ -328,6 +319,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)
Expand All @@ -336,9 +336,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\"",
Expand All @@ -355,9 +358,12 @@ 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\"",
Expand All @@ -374,7 +380,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\"",
Expand Down
Loading