Skip to content

Commit 40b1668

Browse files
committed
[nrf fromlist] settings: zms: fix a bug related to the name's ID
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 Upstream PR #: 86170 Signed-off-by: Riadh Ghaddab <[email protected]> (cherry picked from commit c9a33bbefabb262411985ee7237d040bb3cf2fa4)
1 parent 9203fad commit 40b1668

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

subsys/settings/include/settings/settings_zms.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ extern "C" {
6060
#define ZMS_COLLISIONS_MASK GENMASK(CONFIG_SETTINGS_ZMS_MAX_COLLISIONS_BITS, 1)
6161
#define ZMS_HASH_TOTAL_MASK GENMASK(29, 1)
6262
#define ZMS_MAX_COLLISIONS (BIT(CONFIG_SETTINGS_ZMS_MAX_COLLISIONS_BITS) - 1)
63-
#define ZMS_HEADER_HASH 0x80000000
6463

6564
/* some useful macros */
66-
#define ZMS_NAME_HASH_ID(x) (x & ZMS_HASH_TOTAL_MASK)
65+
#define ZMS_NAME_HASH_ID(x) ((x & ZMS_HASH_TOTAL_MASK) | BIT(31))
6766
#define ZMS_UPDATE_COLLISION_NUM(x, y) \
6867
((x & ~ZMS_COLLISIONS_MASK) | ((y << 1) & ZMS_COLLISIONS_MASK))
6968
#define ZMS_COLLISION_NUM(x) ((x & ZMS_COLLISIONS_MASK) >> 1)

subsys/settings/src/settings_zms.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
232232
delete = ((value == NULL) || (val_len == 0));
233233

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

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

0 commit comments

Comments
 (0)