You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/01/28 09:23:22 UTC

[mynewt-core] branch master updated: kernel/os: Fix os_dev list order

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new c527a94  kernel/os: Fix os_dev list order
c527a94 is described below

commit c527a9401b2e0c15f697be0d0f25a45ea3696b0e
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri Jan 25 17:02:51 2019 +0100

    kernel/os: Fix os_dev list order
    
    Contrary to what could be exepected from os_dev_add()
    device list was sorted in incorrect order devices that should
    be initialized first were added at the end of the list.
    
    Even the reversed order could be further mismatched in following
    scenario. List was in descending order:
    3 3 3 1 1
    Adding 2 would produce
    3 3 3 1 2 1
---
 kernel/os/src/os_dev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/kernel/os/src/os_dev.c b/kernel/os/src/os_dev.c
index 12e871b..cf7779b 100644
--- a/kernel/os/src/os_dev.c
+++ b/kernel/os/src/os_dev.c
@@ -50,6 +50,7 @@ static int
 os_dev_add(struct os_dev *dev)
 {
     struct os_dev *cur_dev;
+    struct os_dev *prev_dev;
 
     /* If no devices present, insert into head */
     if (STAILQ_FIRST(&g_os_dev_list) == NULL) {
@@ -61,21 +62,20 @@ os_dev_add(struct os_dev *dev)
      * priority.  Keep sorted in this order for initialization
      * stage.
      */
-    cur_dev = NULL;
+    prev_dev = NULL;
     STAILQ_FOREACH(cur_dev, &g_os_dev_list, od_next) {
-        if (cur_dev->od_stage > dev->od_stage) {
-            continue;
-        }
-
-        if (dev->od_priority >= cur_dev->od_priority) {
+        if (dev->od_stage < cur_dev->od_stage ||
+            ((dev->od_stage == cur_dev->od_stage) &&
+             (dev->od_priority < cur_dev->od_priority))) {
             break;
         }
+        prev_dev = cur_dev;
     }
 
-    if (cur_dev) {
-        STAILQ_INSERT_AFTER(&g_os_dev_list, cur_dev, dev, od_next);
+    if (prev_dev) {
+        STAILQ_INSERT_AFTER(&g_os_dev_list, prev_dev, dev, od_next);
     } else {
-        STAILQ_INSERT_TAIL(&g_os_dev_list, dev, od_next);
+        STAILQ_INSERT_HEAD(&g_os_dev_list, dev, od_next);
     }
 
     return (0);