Skip to content

Commit b6bab75

Browse files
committed
bluetooth: mesh: settings load optimization
Signed-off-by: Riadh Ghaddab <[email protected]>
1 parent f8d05f3 commit b6bab75

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

subsys/bluetooth/mesh/access.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,28 +2425,26 @@ static void comp_data_clear(void)
24252425
atomic_clear_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY);
24262426
}
24272427

2428-
static int read_comp_cb(const char *key, size_t len, settings_read_cb read_cb,
2429-
void *cb_arg, void *param)
2428+
static ssize_t read_comp(const char *key, struct net_buf_simple *buf)
24302429
{
2431-
struct net_buf_simple *buf = param;
2430+
ssize_t ret = 0;
2431+
ssize_t value_len;
24322432

2433-
if (len > net_buf_simple_tailroom(buf)) {
2433+
ret = settings_get_val_len(key);
2434+
if (ret > net_buf_simple_tailroom(buf)) {
24342435
return -ENOBUFS;
2436+
} else if (ret <= 0) {
2437+
return -ENOENT;
24352438
}
24362439

2437-
len = read_cb(cb_arg, net_buf_simple_tail(buf), len);
2438-
if (len > 0) {
2439-
net_buf_simple_add(buf, len);
2440-
}
2441-
2442-
return -EALREADY;
2440+
return settings_load_one(key, net_buf_simple_tail(buf), value_len);
24432441
}
24442442

24452443
int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page)
24462444
{
24472445
size_t original_len = buf->len;
2446+
ssize_t bytes_read;
24482447
int i;
2449-
int err;
24502448

24512449
if (!IS_ENABLED(CONFIG_BT_SETTINGS)) {
24522450
return -ENOTSUP;
@@ -2462,11 +2460,12 @@ int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page)
24622460
return -ENOENT;
24632461
}
24642462

2465-
err = settings_load_subtree_direct(comp_data_pages[i].path, read_comp_cb, buf);
2466-
2467-
if (err) {
2468-
LOG_ERR("Failed reading composition data: %d", err);
2469-
return err;
2463+
bytes_read = read_comp(comp_data_pages[i].path, buf);
2464+
if (bytes_read > 0) {
2465+
net_buf_simple_add(buf, len);
2466+
} else {
2467+
LOG_ERR("Failed reading composition data: %d", bytes_read);
2468+
return bytes_read;
24702469
}
24712470
if (buf->len == original_len) {
24722471
return -ENOENT;
@@ -2553,18 +2552,20 @@ int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset)
25532552
{
25542553
NET_BUF_SIMPLE_DEFINE(stored_buf, CONFIG_BT_MESH_MODELS_METADATA_PAGE_LEN);
25552554
size_t original_len = buf->len;
2556-
int err;
2555+
ssize_t bytes_read;
25572556

25582557
if (!IS_ENABLED(CONFIG_BT_SETTINGS)) {
25592558
return -ENOTSUP;
25602559
}
25612560

25622561
net_buf_simple_init(&stored_buf, 0);
25632562

2564-
err = settings_load_subtree_direct("bt/mesh/metadata", read_comp_cb, &stored_buf);
2565-
if (err) {
2563+
bytes_read = read_comp("bt/mesh/metadata", &stored_buf);
2564+
if (bytes_read > 0) {
2565+
net_buf_simple_add(&stored_buf, len);
2566+
} else {
25662567
LOG_ERR("Failed reading models metadata: %d", err);
2567-
return err;
2568+
return bytes_read;
25682569
}
25692570

25702571
/* First two bytes are total length */

0 commit comments

Comments
 (0)