diff --git a/subsys/bluetooth/mesh/app_keys.c b/subsys/bluetooth/mesh/app_keys.c index fd644be7c0a..cf5451fc837 100644 --- a/subsys/bluetooth/mesh/app_keys.c +++ b/subsys/bluetooth/mesh/app_keys.c @@ -665,12 +665,12 @@ void bt_mesh_app_key_pending_store(void) continue; } + update->valid = 0U; + if (update->clear) { clear_app_key(update->key_idx); } else { store_app_key(update->key_idx); } - - update->valid = 0U; } } diff --git a/subsys/bluetooth/mesh/cdb.c b/subsys/bluetooth/mesh/cdb.c index 89c5fe3d53b..58c9d70abc2 100644 --- a/subsys/bluetooth/mesh/cdb.c +++ b/subsys/bluetooth/mesh/cdb.c @@ -1023,27 +1023,29 @@ static void store_cdb_pending_nodes(void) for (i = 0; i < ARRAY_SIZE(cdb_node_updates); ++i) { struct node_update *update = &cdb_node_updates[i]; + uint16_t addr; if (update->addr == BT_MESH_ADDR_UNASSIGNED) { continue; } - LOG_DBG("addr: 0x%04x, clear: %d", update->addr, update->clear); + addr = update->addr; + update->addr = BT_MESH_ADDR_UNASSIGNED; + + LOG_DBG("addr: 0x%04x, clear: %d", addr, update->clear); if (update->clear) { - clear_cdb_node(update->addr); + clear_cdb_node(addr); } else { struct bt_mesh_cdb_node *node; - node = bt_mesh_cdb_node_get(update->addr); + node = bt_mesh_cdb_node_get(addr); if (node) { store_cdb_node(node); } else { - LOG_WRN("Node 0x%04x not found", update->addr); + LOG_WRN("Node 0x%04x not found", addr); } } - - update->addr = BT_MESH_ADDR_UNASSIGNED; } } @@ -1058,6 +1060,8 @@ static void store_cdb_pending_keys(void) continue; } + update->valid = 0U; + if (update->clear) { if (update->app_key) { clear_cdb_app_key(update->key_idx); @@ -1085,8 +1089,6 @@ static void store_cdb_pending_keys(void) } } } - - update->valid = 0U; } } diff --git a/subsys/bluetooth/mesh/subnet.c b/subsys/bluetooth/mesh/subnet.c index ebf0ee07510..f3b05ecbf82 100644 --- a/subsys/bluetooth/mesh/subnet.c +++ b/subsys/bluetooth/mesh/subnet.c @@ -831,12 +831,12 @@ void bt_mesh_subnet_pending_store(void) continue; } + update->valid = 0U; + if (update->clear) { clear_net_key(update->key_idx); } else { store_subnet(update->key_idx); } - - update->valid = 0U; } }