mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-29 04:07:23 +00:00
mesh: Fix model tree walk procedure
`bt_mesh_model_tree_walk()` was too simplistic and did not track visited nodes which caused it to fall into infinite loop. Moreover the double next jump could skip a level causing depth value to be invalid. this is port of 3908638bab5966ac2e989a099a64141dff1116e1
This commit is contained in:
committed by
Łukasz Rymanowski
parent
61c3b30593
commit
a02cb16190
@@ -804,23 +804,31 @@ void bt_mesh_model_tree_walk(struct bt_mesh_model *root,
|
||||
{
|
||||
struct bt_mesh_model *m = root;
|
||||
uint32_t depth = 0;
|
||||
/* 'skip' is set to true when we ascend from child to parent node.
|
||||
* In that case, we want to skip calling the callback on the parent
|
||||
* node and we don't want to descend onto a child node as those
|
||||
* nodes have already been visited.
|
||||
*/
|
||||
bool skip = false;
|
||||
|
||||
do {
|
||||
if (cb(m, depth, user_data) == BT_MESH_WALK_STOP) {
|
||||
if (!skip && cb(m, depth, user_data) == BT_MESH_WALK_STOP) {
|
||||
return;
|
||||
}
|
||||
#if MYNEWT_VAL(BLE_MESH_MODEL_EXTENSIONS)
|
||||
if (m->extends) {
|
||||
if (!skip && m->extends) {
|
||||
m = m->extends;
|
||||
depth++;
|
||||
} else if (m->flags & BT_MESH_MOD_NEXT_IS_PARENT) {
|
||||
m = m->next->next;
|
||||
m = m->next;
|
||||
depth--;
|
||||
skip = true;
|
||||
} else {
|
||||
m = m->next;
|
||||
skip = false;
|
||||
}
|
||||
#endif
|
||||
} while (m && m != root);
|
||||
} while (m);
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_MESH_MODEL_EXTENSIONS)
|
||||
|
||||
Reference in New Issue
Block a user