Skip to content

Commit 457ade4

Browse files
rghaddabkartben
authored andcommitted
settings: zms: code style clean up
Clean some parts of the code and refactor it to avoid multiple nested conditions. Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
1 parent 7f716f1 commit 457ade4

File tree

4 files changed

+166
-162
lines changed

4 files changed

+166
-162
lines changed

include/zephyr/settings/settings.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ struct settings_store_itf {
469469
/**< Loads values from storage limited to subtree defined by subtree.
470470
*
471471
* Parameters:
472-
* - cs - Corresponding backend handler node,
473-
* - arg - Structure that holds additional data for data loading.
472+
* - cs[in] - Corresponding backend handler node,
473+
* - arg[in] - Structure that holds additional data for data loading.
474474
*
475475
* @note
476476
* Backend is expected not to provide duplicates of the entities.
@@ -484,50 +484,50 @@ struct settings_store_itf {
484484
/**< Loads one value from storage that corresponds to the key defined by name.
485485
*
486486
* Parameters:
487-
* - cs - Corresponding backend handler node.
488-
* - name - Key in string format.
489-
* - buf - Buffer where data should be copied.
490-
* - buf_len - Length of buf.
487+
* - cs[in] - Corresponding backend handler node.
488+
* - name[in] - Key in string format.
489+
* - buf[in] - Buffer where data should be copied.
490+
* - buf_len[in] - Length of buf.
491491
*/
492492

493493
ssize_t (*csi_get_val_len)(struct settings_store *cs, const char *name);
494494
/**< Gets the value's length associated to the Key defined by name.
495495
* It returns 0 if the Key/Value doesn't exist.
496496
*
497497
* Parameters:
498-
* - cs - Corresponding backend handler node.
499-
* - name - Key in string format.
498+
* - cs[in] - Corresponding backend handler node.
499+
* - name[in] - Key in string format.
500500
*/
501501

502502
int (*csi_save_start)(struct settings_store *cs);
503503
/**< Handler called before an export operation.
504504
*
505505
* Parameters:
506-
* - cs - Corresponding backend handler node
506+
* - cs[in] - Corresponding backend handler node
507507
*/
508508

509509
int (*csi_save)(struct settings_store *cs, const char *name,
510510
const char *value, size_t val_len);
511511
/**< Save a single key-value pair to storage.
512512
*
513513
* Parameters:
514-
* - cs - Corresponding backend handler node
515-
* - name - Key in string format
516-
* - value - Binary value
517-
* - val_len - Length of value in bytes.
514+
* - cs[in] - Corresponding backend handler node
515+
* - name[in] - Key in string format
516+
* - value[in] - Binary value
517+
* - val_len[in] - Length of value in bytes.
518518
*/
519519

520520
int (*csi_save_end)(struct settings_store *cs);
521521
/**< Handler called after an export operation.
522522
*
523523
* Parameters:
524-
* - cs - Corresponding backend handler node
524+
* - cs[in] - Corresponding backend handler node
525525
*/
526526

527527
/**< Get pointer to the storage instance used by the backend.
528528
*
529529
* Parameters:
530-
* - cs - Corresponding backend handler node
530+
* - cs[in] - Corresponding backend handler node
531531
*/
532532
void *(*csi_storage_get)(struct settings_store *cs);
533533
};

subsys/settings/include/settings/settings_zms.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
* The ZMS entry ID for the setting's value is determined implicitly based on
2121
* the ID of the ZMS entry for the setting's name, once that is found. The
2222
* difference between name and value ID is constant and equal to
23-
* ZMS_NAME_ID_OFFSET.
23+
* ZMS_DATA_ID_OFFSET.
2424
*
2525
* Setting's name is hashed into 29 bits minus hash_collisions_bits.
2626
* The 2 MSB_bits have always the same value 10, the LL_bit for the name's hash is 0
@@ -68,6 +68,9 @@ extern "C" {
6868
((x & ~ZMS_COLLISIONS_MASK) | ((y << 1) & ZMS_COLLISIONS_MASK))
6969
#define ZMS_COLLISION_NUM(x) ((x & ZMS_COLLISIONS_MASK) >> 1)
7070
#define ZMS_NAME_ID_FROM_HASH(x) ((x & ZMS_HASH_TOTAL_MASK) | BIT(31))
71+
#define ZMS_DATA_ID_FROM_HASH(x) (ZMS_NAME_ID_FROM_HASH(x) + ZMS_DATA_ID_OFFSET)
72+
#define ZMS_DATA_ID_FROM_NAME(x) (x + ZMS_DATA_ID_OFFSET)
73+
#define ZMS_DATA_ID_FROM_LL_NODE(x) (ZMS_NAME_ID_FROM_LL_NODE(x) + ZMS_DATA_ID_OFFSET)
7174

7275
struct settings_hash_linked_list {
7376
uint32_t previous_hash;

0 commit comments

Comments
 (0)