Skip to content

Commit 174d005

Browse files
committed
settings: zms: add more robustness to the save function
When a power off happens after writing the settings name and before writing the linked list node we cannot write the settings name again in the future. Fix this by writing the linked list node before writing the name. When loading all settings, we already delete linked list node that do not have any name or value written. Signed-off-by: Riadh Ghaddab <[email protected]>
1 parent 7cf22a0 commit 174d005

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

subsys/settings/src/settings_zms.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
513513

514514
/* write the name if required */
515515
if (write_name) {
516-
rc = zms_write(&cf->cf_zms, name_hash, name, strlen(name));
517-
if (rc < 0) {
518-
return rc;
519-
}
516+
/* First let's update the linked list */
520517
#ifdef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
521518
if (ll_node_exist) {
522519
goto no_ll_update;
@@ -570,10 +567,16 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
570567
cf->ll_cache[cf->ll_cache_next - 2] = settings_element;
571568
}
572569
#endif
573-
}
574570
#ifdef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
575571
no_ll_update:
576572
#endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
573+
/* Now let's write the name */
574+
rc = zms_write(&cf->cf_zms, name_hash, name, strlen(name));
575+
if (rc < 0) {
576+
return rc;
577+
}
578+
}
579+
577580
#ifdef CONFIG_SETTINGS_ZMS_NAME_CACHE
578581
/* Add the flags of the written settings entry in cache */
579582
cache_flags = 0;

0 commit comments

Comments
 (0)