From f3124f834f64bbfad514abac8634147b1dac837d Mon Sep 17 00:00:00 2001 From: water_zhang <5346363+water_zhang@user.noreply.gitee.com> Date: Sat, 31 Jul 2021 00:39:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3FinSH=E4=B8=AD=E8=87=AA?= =?UTF-8?q?=E5=B8=A6=E7=9A=84list=5Fthread=E7=AD=89=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E4=BC=9A=E6=97=A0=E9=99=90=E6=89=93=E5=8D=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/finsh/cmd.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index 8b51896cde..429d5103f5 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, list is header */ if (!current) /* find first */ { - node = list; + node = first_node; first_flag = 1; } else @@ -142,18 +145,22 @@ 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 node */ + if (node == first_node) + { + node = (rt_list_t *)RT_NULL; + break; } } -- Gitee From 655166b717a8e6ca7005ab4caf2e734162a607d3 Mon Sep 17 00:00:00 2001 From: water_zhang <5346363+water_zhang@user.noreply.gitee.com> Date: Sat, 31 Jul 2021 00:39:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3FinSH=E4=B8=AD=E8=87=AA?= =?UTF-8?q?=E5=B8=A6=E7=9A=84list=5Fthread=E7=AD=89=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E4=BC=9A=E6=97=A0=E9=99=90=E6=89=93=E5=8D=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/finsh/cmd.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index 8b51896cde..2ddd800013 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); -- Gitee