From 0beffcd022027f320148a896b9dc7cf5012d247b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Wed, 18 Nov 2020 09:05:00 +0100 Subject: [PATCH] msh: Permit model walk from any model Fixes bug where applications that disable model extensions end up in an infinite loop, and adds support for walking model subtrees, as opposed to forcing root to be unextended. this is port of a878b36af0ef7c311d0f10cc9f1771078de378fb --- nimble/host/mesh/src/access.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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)