From e6c4f265a34ff79bfdb430bcdd2fab7d56d2c43f Mon Sep 17 00:00:00 2001 From: Mirko Covizzi Date: Mon, 17 Nov 2025 15:02:35 +0100 Subject: [PATCH 1/2] subsys: fs: bm_zms: remove global callbacks array Removes global callbacks array and replaces with callback member inside `struct bm_zms_fs`. This fixes a bug where registering multiple callbacks on the same `struct bm_zms_fs` would update the user reference number incrementally and saturate the global callbacks array. When calling `bm_zms_clear`, this would only reset to NULL the last callback set, leaving the rest still set. This update makes it so that there can only be one callback per each `struct bm_zms_fs` instance, mirroring the behavior of other libraries. Due to this change, also removes the `BM_ZMS_MAX_USERS` Kconfig option. Also removes the member `cb_registred` in the struct `bm_zms_init_flags` since it is not used anymore. Signed-off-by: Mirko Covizzi --- .../release_notes/release_notes_changelog.rst | 3 +++ include/bm/fs/bm_zms.h | 22 ++++++++---------- subsys/fs/bm_zms/Kconfig | 6 ----- subsys/fs/bm_zms/bm_zms.c | 23 ++++--------------- 4 files changed, 17 insertions(+), 37 deletions(-) diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index ebffc06962..3cb3993320 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -132,6 +132,9 @@ Libraries * The :c:func:`bm_zms_active_sector_free_space` function to return ``-EFAULT`` when the input parameter ``fs`` is ``NULL``. * The :c:func:`bm_zms_mount` function to expect an additional input parameter of type pointer to struct :c:struct:`bm_zms_fs_config` for configuring a Zephyr Memory Storage file system instance at initialization. + * Removed the :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option. Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`. + * Removed the :c:member:`bm_zms_init_flags.cb_registred` member since it was not used anymore. + * :ref:`lib_peer_manager` library: * Updated: diff --git a/include/bm/fs/bm_zms.h b/include/bm/fs/bm_zms.h index 56e0b3beff..8b051ac756 100644 --- a/include/bm/fs/bm_zms.h +++ b/include/bm/fs/bm_zms.h @@ -25,7 +25,7 @@ extern "C" { */ /** - * @defgroup bm_zms_data_structures BM_ZMS data structures + * @defgroup bm_zms_data_types BM_ZMS data types * @ingroup bm_zms * @{ */ @@ -60,9 +60,15 @@ typedef struct { struct bm_zms_init_flags { volatile bool initialized; /* true when the storage is initialized. */ volatile bool initializing; /* true when initialization is ongoing. */ - bool cb_registred; /* true when the user callback is registred. */ } __packed; +/** + * @brief Bare Metal ZMS event handler function prototype. + * + * @param p_evt The event. + */ +typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt); + /** Zephyr Memory Storage file system structure */ struct bm_zms_fs { /** File system offset in flash. */ @@ -91,8 +97,8 @@ struct bm_zms_fs { struct bm_storage zms_bm_storage; /** Number of writes currently handled by the storage system. */ atomic_t ongoing_writes; - /** The user number that identifies the callback for an event. */ - uint32_t user_num; + /** User callback for propagating events. */ + bm_zms_cb_t user_cb; #if CONFIG_BM_ZMS_LOOKUP_CACHE /** Lookup table used to cache ATE addresses of written IDs. */ uint64_t lookup_cache[CONFIG_BM_ZMS_LOOKUP_CACHE_SIZE]; @@ -121,13 +127,6 @@ struct bm_zms_fs_config { * @{ */ -/** - *@brief Bare Metal ZMS event handler function prototype. - * - * @param p_evt The event. - */ -typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt); - /** * @brief Register a callback to BM_ZMS for handling events. * @@ -136,7 +135,6 @@ typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt); * * @retval 0 on success. * @retval -EFAULT if @p fs or @p cb are NULL. - * @retval -ENOMEM if no more callback slots are available. */ int bm_zms_register(struct bm_zms_fs *fs, bm_zms_cb_t cb); diff --git a/subsys/fs/bm_zms/Kconfig b/subsys/fs/bm_zms/Kconfig index d56e7ffbc6..4afbc366f1 100644 --- a/subsys/fs/bm_zms/Kconfig +++ b/subsys/fs/bm_zms/Kconfig @@ -50,12 +50,6 @@ config BM_ZMS_CUSTOM_BLOCK_SIZE help Changes the internal buffer size of BM_ZMS. -config BM_ZMS_MAX_USERS - int "BM_ZMS maximum users" - default 8 - help - Defines the maximum number of event handlers that can be registred by the user. - config BM_ZMS_OP_QUEUE_SIZE int "BM_ZMS operations queue size" default 16 diff --git a/subsys/fs/bm_zms/bm_zms.c b/subsys/fs/bm_zms/bm_zms.c index b17ae207f0..866bf6556c 100644 --- a/subsys/fs/bm_zms/bm_zms.c +++ b/subsys/fs/bm_zms/bm_zms.c @@ -51,9 +51,6 @@ static int bm_zms_clear_execute(void); */ static atomic_t queued_op_cnt; -/* The table of app callback functions. */ -static bm_zms_cb_t zms_cb_table[CONFIG_BM_ZMS_MAX_USERS]; - /* Queue of bm_zms operations. */ RING_BUF_DECLARE(zms_fifo, CONFIG_BM_ZMS_OP_QUEUE_SIZE * sizeof(zms_op_t)); @@ -97,8 +94,8 @@ static void event_prepare(bm_zms_evt_t *p_evt) static void event_send(bm_zms_evt_t const *const p_evt, struct bm_zms_fs *fs) { - if (zms_cb_table[fs->user_num] != NULL) { - zms_cb_table[fs->user_num](p_evt); + if (fs->user_cb != NULL) { + fs->user_cb(p_evt); } } @@ -188,7 +185,7 @@ static void queue_process(void) /* bm_zms needs to be reinitialized after clearing */ cur_op.fs->init_flags.initialized = false; cur_op.fs->init_flags.initializing = false; - zms_cb_table[cur_op.fs->user_num] = NULL; + cur_op.fs->user_cb = NULL; cur_op.op_completed = true; result = 0; } else { @@ -325,23 +322,11 @@ static void zms_event_handler(struct bm_storage_evt *p_evt) int bm_zms_register(struct bm_zms_fs *fs, bm_zms_cb_t cb) { - int i; - if (!fs || !cb) { return -EFAULT; } - for (i = 0; i < CONFIG_BM_ZMS_MAX_USERS; i++) { - if (zms_cb_table[i] == NULL) { - break; - } - } - if (i == CONFIG_BM_ZMS_MAX_USERS) { - return -ENOMEM; - } - zms_cb_table[i] = cb; - fs->user_num = i; - fs->init_flags.cb_registred = true; + fs->user_cb = cb; return 0; } From 00a1b4470a91fd45c3508bdc5b71fdf37f0e81d8 Mon Sep 17 00:00:00 2001 From: Mirko Covizzi Date: Tue, 18 Nov 2025 10:12:51 +0100 Subject: [PATCH 2/2] include: bm: fs: bm_zms: cleanup Doxygen Cleans up Doxygen. Signed-off-by: Mirko Covizzi --- include/bm/fs/bm_zms.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bm/fs/bm_zms.h b/include/bm/fs/bm_zms.h index 8b051ac756..d0c3448529 100644 --- a/include/bm/fs/bm_zms.h +++ b/include/bm/fs/bm_zms.h @@ -130,8 +130,8 @@ struct bm_zms_fs_config { /** * @brief Register a callback to BM_ZMS for handling events. * - * @param cb Pointer to the event handler callback. * @param fs Pointer to the file system structure. + * @param cb Pointer to the event handler callback. * * @retval 0 on success. * @retval -EFAULT if @p fs or @p cb are NULL.