diff --git a/nimble/host/mesh/src/access.c b/nimble/host/mesh/src/access.c index 7ac52e18d..25d7355c8 100644 --- a/nimble/host/mesh/src/access.c +++ b/nimble/host/mesh/src/access.c @@ -803,7 +803,7 @@ void bt_mesh_model_tree_walk(struct bt_mesh_model *root, void *user_data) { struct bt_mesh_model *m = root; - uint32_t depth = 0; + int 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 @@ -812,7 +812,8 @@ void bt_mesh_model_tree_walk(struct bt_mesh_model *root, bool skip = false; do { - if (!skip && cb(m, depth, user_data) == BT_MESH_WALK_STOP) { + if (!skip && + cb(m, (uint32_t)depth, user_data) == BT_MESH_WALK_STOP) { return; } #if MYNEWT_VAL(BLE_MESH_MODEL_EXTENSIONS) @@ -828,7 +829,7 @@ void bt_mesh_model_tree_walk(struct bt_mesh_model *root, skip = false; } #endif - } while (m); + } while (m && depth > 0); } #if MYNEWT_VAL(BLE_MESH_MODEL_EXTENSIONS)