Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand Down
16 changes: 9 additions & 7 deletions include/bm_zms.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define ZEPHYR_INCLUDE_FS_BM_ZMS_H_

#include <sys/types.h>
#include <zephyr/sys/atomic.h>
#include <stdbool.h>
#include <bm_storage.h>

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions lib/bm_zms/bm_zms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/bm_zms/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment on lines +120 to 126
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can probably be cleaned a bit like this. Could be left as a separate PR.

Suggested change
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");
zassert_equal(-EINVAL, err);
err = bm_zms_register(&fixture->fs, NULL);
zassert_equal(-EINVAL, err);
err = bm_zms_register(&fixture->fs, &bm_zms_test_handler);
zassert_ok(err, "bm_zms_register call failure");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be separate

}
Expand Down