diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index e19bea6259..7b08dd6c6e 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -52,7 +52,9 @@ No changes since the latest nRF Connect SDK Bare Metal release. Libraries ========= -No changes since the latest nRF Connect SDK Bare Metal release. +* :ref:`lib_bm_zms` library: + + * Updated the :c:func:`bm_zms_register` function to return ``-EINVAL`` when passing ``NULL`` input parameters. Samples ======= diff --git a/include/bm_zms.h b/include/bm_zms.h index fceb2baea5..7c41e5b68f 100644 --- a/include/bm_zms.h +++ b/include/bm_zms.h @@ -9,6 +9,7 @@ #define ZEPHYR_INCLUDE_FS_BM_ZMS_H_ #include +#include #include #include @@ -111,7 +112,8 @@ typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt); * @param fs Pointer to the file system structure. * * @retval 0 on success. - * @retval negative number on failure. + * @retval -ENOMEM if no more callback slots are available. + * @retval -EINVAL if @p fs or @p cb are NULL. */ int bm_zms_register(struct bm_zms_fs *fs, bm_zms_cb_t cb); @@ -135,7 +137,7 @@ int bm_zms_mount(struct bm_zms_fs *fs); * @param fs Pointer to the file system. * * @retval 0 if the clear operation is queued successfully. - * @retval -EACCES if `fs` is not mounted. + * @retval -EACCES if @p fs is not mounted. * @retval -EIO if there is an internal error. */ int bm_zms_clear(struct bm_zms_fs *fs); @@ -157,7 +159,7 @@ int bm_zms_clear(struct bm_zms_fs *fs); * On error, returns negative value of error codes defined in `errno.h`. * @retval -EACCES if BM_ZMS is still not initialized. * @retval -EIO if there is an internal error. - * @retval -EINVAL if `len` is invalid. + * @retval -EINVAL if @p len is invalid. */ ssize_t bm_zms_write(struct bm_zms_fs *fs, uint32_t id, const void *data, size_t len); @@ -188,7 +190,7 @@ int bm_zms_delete(struct bm_zms_fs *fs, uint32_t id); * @retval Number of bytes read (> 0) on success. * @retval -EACCES if BM_ZMS is still not initialized. * @retval -EIO if there is a memory read/write error. - * @retval -ENOENT if there is no entry with the given `id`. + * @retval -ENOENT if there is no entry with the given @p id. */ ssize_t bm_zms_read(struct bm_zms_fs *fs, uint32_t id, void *data, size_t len); @@ -208,7 +210,7 @@ ssize_t bm_zms_read(struct bm_zms_fs *fs, uint32_t id, void *data, size_t len); * @retval Number of bytes read (> 0) on success. * @retval -EACCES if BM_ZMS is still not initialized. * @retval -EIO if there is a memory read/write error. - * @retval -ENOENT if there is no entry with the given `id` and history counter. + * @retval -ENOENT if there is no entry with the given @p id and history counter. */ ssize_t bm_zms_read_hist(struct bm_zms_fs *fs, uint32_t id, void *data, size_t len, uint32_t cnt); @@ -220,10 +222,10 @@ ssize_t bm_zms_read_hist(struct bm_zms_fs *fs, uint32_t id, void *data, size_t l * * @return Data length contained in the ATE. On success, it will be equal to the number of bytes * in the ATE. On error, returns negative value of error codes defined in `errno.h`. - * @retval Length of the entry with the given `id` (> 0) on success. + * @retval Length of the entry with the given @p id (> 0) on success. * @retval -EACCES if BM_ZMS is still not initialized. * @retval -EIO if there is a memory read/write error. - * @retval -ENOENT if there is no entry with the given id and history counter. + * @retval -ENOENT if there is no entry with the given @p id and history counter. */ ssize_t bm_zms_get_data_length(struct bm_zms_fs *fs, uint32_t id); diff --git a/lib/bm_zms/bm_zms.c b/lib/bm_zms/bm_zms.c index f40c7f8894..e7c3ea30d9 100644 --- a/lib/bm_zms/bm_zms.c +++ b/lib/bm_zms/bm_zms.c @@ -322,6 +322,10 @@ int bm_zms_register(struct bm_zms_fs *fs, bm_zms_cb_t cb) { int i; + if (!fs || !cb) { + return -EINVAL; + } + for (i = 0; i < CONFIG_BM_ZMS_MAX_USERS; i++) { if (zms_cb_table[i] == NULL) { break; diff --git a/samples/peripherals/bm_zms/src/main.c b/samples/peripherals/bm_zms/src/main.c index 0683543221..9c8da44908 100644 --- a/samples/peripherals/bm_zms/src/main.c +++ b/samples/peripherals/bm_zms/src/main.c @@ -72,10 +72,10 @@ static int delete_and_verify_items(struct bm_zms_fs *fs, uint32_t id) return 0; error1: - LOG_INF("Error while deleting item rc=%d", rc); + LOG_ERR("Error while deleting item rc=%d", rc); return rc; error2: - LOG_INF("Error, Delete failed item should not be present"); + LOG_ERR("Error, Delete failed item should not be present"); return -1; } @@ -85,25 +85,25 @@ static int delete_basic_items(struct bm_zms_fs *fs) rc = delete_and_verify_items(fs, IP_ADDRESS_ID); if (rc) { - LOG_INF("Error while deleting item %x rc=%d", IP_ADDRESS_ID, rc); + LOG_ERR("Error while deleting item %x rc=%d", IP_ADDRESS_ID, rc); return rc; } wait_for_ongoing_writes(); rc = delete_and_verify_items(fs, KEY_VALUE_ID); if (rc) { - LOG_INF("Error while deleting item %x rc=%d", KEY_VALUE_ID, rc); + LOG_ERR("Error while deleting item %x rc=%d", KEY_VALUE_ID, rc); return rc; } wait_for_ongoing_writes(); rc = delete_and_verify_items(fs, CNT_ID); if (rc) { - LOG_INF("Error while deleting item %x rc=%d", CNT_ID, rc); + LOG_ERR("Error while deleting item %x rc=%d", CNT_ID, rc); return rc; } wait_for_ongoing_writes(); rc = delete_and_verify_items(fs, LONG_DATA_ID); if (rc) { - LOG_INF("Error while deleting item %x rc=%d", LONG_DATA_ID, rc); + LOG_ERR("Error while deleting item %x rc=%d", LONG_DATA_ID, rc); } wait_for_ongoing_writes(); @@ -125,7 +125,7 @@ void bm_zms_sample_handler(bm_zms_evt_t const *p_evt) nvm_is_full = true; return; } - LOG_INF("BM_ZMS Error received %d", p_evt->result); + LOG_ERR("BM_ZMS Error received %d", p_evt->result); } else { LOG_WRN("Unhandled BM_ZMS event ID %u", p_evt->id); } @@ -167,7 +167,7 @@ int main(void) for (i = 0; i < CONFIG_BM_ZMS_ITERATIONS_MAX; i++) { rc = bm_zms_mount(&fs); if (rc) { - LOG_INF("Storage Init failed, rc=%d", rc); + LOG_ERR("Storage Init failed, rc=%d", rc); goto idle; } wait_for_init(); @@ -188,7 +188,7 @@ int main(void) LOG_INF("Adding IP_ADDRESS %s at id %u", buf, IP_ADDRESS_ID); rc = bm_zms_write(&fs, IP_ADDRESS_ID, &buf, strlen(buf)); if (rc < 0) { - LOG_INF("Error while writing Entry rc=%d", rc); + LOG_ERR("Error while writing Entry rc=%d", rc); goto idle; } wait_for_ongoing_writes(); @@ -205,7 +205,7 @@ int main(void) LOG_INF("Adding key/value at id %x", KEY_VALUE_ID); rc = bm_zms_write(&fs, KEY_VALUE_ID, &key, sizeof(key)); if (rc < 0) { - LOG_INF("Error while writing Entry rc=%d", rc); + LOG_ERR("Error while writing Entry rc=%d", rc); goto idle; } wait_for_ongoing_writes(); @@ -217,14 +217,14 @@ int main(void) if (rc > 0) { /* item was found, show it */ LOG_INF("Id: %d, loop_cnt: %u", CNT_ID, i_cnt); if ((i > 0) && (i_cnt != (i - 1))) { - LOG_INF("Error loop_cnt %u must be %d", i_cnt, i - 1); + LOG_ERR("Error loop_cnt %u must be %d", i_cnt, i - 1); goto idle; } } LOG_INF("Adding counter at id %u", CNT_ID); rc = bm_zms_write(&fs, CNT_ID, &i, sizeof(i)); if (rc < 0) { - LOG_INF("Error while writing Entry rc=%d", rc); + LOG_ERR("Error while writing Entry rc=%d", rc); goto idle; } wait_for_ongoing_writes(); @@ -243,7 +243,7 @@ int main(void) LOG_INF("Adding Longarray at id %d", LONG_DATA_ID); rc = bm_zms_write(&fs, LONG_DATA_ID, &longarray, sizeof(longarray)); if (rc < 0) { - LOG_INF("Error while writing Entry rc=%d", rc); + LOG_ERR("Error while writing Entry rc=%d", rc); goto idle; } wait_for_ongoing_writes(); @@ -258,7 +258,7 @@ int main(void) } if (i != CONFIG_BM_ZMS_ITERATIONS_MAX) { - LOG_INF("Error: Something went wrong at iteration %u rc=%d", i, rc); + LOG_ERR("Error: Something went wrong at iteration %u rc=%d", i, rc); goto idle; } @@ -275,11 +275,11 @@ int main(void) /* Calculate free space and verify that it is 0 */ free_space = bm_zms_calc_free_space(&fs); if (free_space < 0) { - LOG_INF("Error while computing free space, rc=%d", free_space); + LOG_ERR("Error while computing free space, rc=%d", free_space); goto idle; } if (free_space > 0) { - LOG_INF("Error: free_space should be 0, computed %u", free_space); + LOG_ERR("Error: free_space should be 0, computed %u", free_space); goto idle; } LOG_INF("Memory is full let's delete all items"); @@ -287,13 +287,13 @@ int main(void) for (uint32_t n = 0; n < id; n++) { rc = delete_and_verify_items(&fs, n); if (rc) { - LOG_INF("Error deleting at id %u", n); + LOG_ERR("Error deleting at id %u", n); goto idle; } } rc = delete_basic_items(&fs); if (rc) { - LOG_INF("Error deleting basic items"); + LOG_ERR("Error deleting basic items"); goto idle; } @@ -302,7 +302,7 @@ int main(void) */ free_space = bm_zms_calc_free_space(&fs); if (free_space < 0) { - LOG_INF("Error while computing free space, rc=%d", free_space); + LOG_ERR("Error while computing free space, rc=%d", free_space); goto idle; } LOG_INF("Free space in storage is %u bytes", free_space); @@ -310,7 +310,8 @@ int main(void) /* Let's clean the storage now */ rc = bm_zms_clear(&fs); if (rc < 0) { - LOG_INF("Error while cleaning the storage, rc=%d", rc); + LOG_ERR("Error while cleaning the storage, rc=%d", rc); + goto idle; } LOG_INF("BM_ZMS sample finished Successfully"); diff --git a/tests/lib/bm_zms/src/main.c b/tests/lib/bm_zms/src/main.c index 1f227c2592..630d8f5dc7 100644 --- a/tests/lib/bm_zms/src/main.c +++ b/tests/lib/bm_zms/src/main.c @@ -116,6 +116,12 @@ ZTEST_F(bm_zms, test_bm_zms_register) { int err; + err = bm_zms_register(NULL, &bm_zms_test_handler); + zassert_true(err == -EINVAL, "bm_zms_register unexpected failure"); + + err = bm_zms_register(&fixture->fs, NULL); + zassert_true(err == -EINVAL, "bm_zms_register unexpected failure"); + err = bm_zms_register(&fixture->fs, &bm_zms_test_handler); zassert_true(err == 0, "bm_zms_register call failure"); }