diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index 8b51896cdea74c669285db2d960fb99ab24c00f0..2ddd8000132dc739923b59a1cc7b172a535fc162 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -30,6 +30,8 @@ * 2018-12-27 Jesven Fix the problem that disable interrupt too long in list_thread * Provide protection for the "first layer of objects" when list_* * 2020-04-07 chenhui add clear + * 2021-07-31 water_zhang Fix the problem that cmd list_xxxx execution gets stuck in an + * infinite loop, see gitee issues I4394C */ #include @@ -101,7 +103,7 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg) { int first_flag = 0; rt_ubase_t level; - rt_list_t *node, *list; + rt_list_t *node, *list, *first_node; rt_list_t **array; int nr; @@ -113,10 +115,11 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg) } list = arg->list; + first_node = list->next; /* first valid node is list->next */ if (!current) /* find first */ { - node = list; + node = first_node; first_flag = 1; } else @@ -142,19 +145,23 @@ static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg) array = arg->array; while (1) { - node = node->next; - - if (node == list) - { - node = (rt_list_t *)RT_NULL; - break; - } + /* store node */ nr++; *array++ = node; if (nr == arg->nr) { break; } + + /* go to next node */ + node = node->next; + + /* go back to first node means we had traverse all list nodes */ + if (node == first_node) + { + node = (rt_list_t *)RT_NULL; + break; + } } rt_hw_interrupt_enable(level);