Skip to content

Commit

Permalink
storage/stream_flash: Initialize settings at point of use
Browse files Browse the repository at this point in the history
The commit moves Settigns initialization out of stream_flash
initialization function into: stream_flash_progress_clear
 stream_flash_progress_load and stream_flash_progress_save.

This slightly increases code size (~56 bytes on Arm) but allows
to initialize Stream Flash even if Settings subsystem fails
to initialize and continue providing its basic functionality.
  • Loading branch information
de-nordic committed Nov 25, 2024
1 parent c9dc581 commit c55e711
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions subsys/storage/stream/stream_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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\"",
Expand All @@ -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));

Check notice on line 375 in subsys/storage/stream/stream_flash.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/storage/stream/stream_flash.c:375 - rc = settings_save_one(settings_key, - &ctx->bytes_written, + rc = settings_save_one(settings_key, &ctx->bytes_written,
}

if (rc != 0) {
LOG_ERR("Error %d while storing progress for \"%s\"",
Expand All @@ -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\"",
Expand Down

0 comments on commit c55e711

Please sign in to comment.