Skip to content

Commit

Permalink
settings: zms: fix a bug related to the name's ID
Browse files Browse the repository at this point in the history
To avoid collisions between IDs used by settings and IDs used directly
by subsystems using ZMS API, the MSB is always set to 1 for Setting's
name ID written to ZMS backend

Signed-off-by: Riadh Ghaddab <[email protected]>
(cherry picked from commit c9a33bbefabb262411985ee7237d040bb3cf2fa4)
  • Loading branch information
rghaddab committed Feb 24, 2025
1 parent c1e1bca commit 1d4f77e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions subsys/settings/include/settings/settings_zms.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ extern "C" {
#define ZMS_COLLISIONS_MASK GENMASK(CONFIG_SETTINGS_ZMS_MAX_COLLISIONS_BITS, 1)
#define ZMS_HASH_TOTAL_MASK GENMASK(29, 1)
#define ZMS_MAX_COLLISIONS (BIT(CONFIG_SETTINGS_ZMS_MAX_COLLISIONS_BITS) - 1)
#define ZMS_HEADER_HASH 0x80000000

/* some useful macros */
#define ZMS_NAME_HASH_ID(x) (x & ZMS_HASH_TOTAL_MASK)
#define ZMS_NAME_HASH_ID(x) ((x & ZMS_HASH_TOTAL_MASK) | BIT(31))
#define ZMS_UPDATE_COLLISION_NUM(x, y) \
((x & ~ZMS_COLLISIONS_MASK) | ((y << 1) & ZMS_COLLISIONS_MASK))
#define ZMS_COLLISION_NUM(x) ((x & ZMS_COLLISIONS_MASK) >> 1)
Expand Down
2 changes: 2 additions & 0 deletions subsys/settings/src/settings_zms.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
delete = ((value == NULL) || (val_len == 0));

name_hash = sys_hash32(name, strlen(name)) & ZMS_HASH_MASK;
/* MSB is always 1 */
name_hash |= BIT(31);

/* Let's find out if there is no hash collisions in the storage */
write_name = true;
Expand Down

0 comments on commit 1d4f77e

Please sign in to comment.