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

naveenkaje 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 95437ef  kernel/os: os_dev_add check to see if device is already 
present
     new dcf74ed  Merge pull request #2357 from nkaje/os_dev_add_check
95437ef is described below

commit 95437ef046b9f4f44d7dbf4150a5b6c97b50c9bb
Author: Naveen Kaje <[email protected]>
AuthorDate: Tue Aug 18 11:17:57 2020 -0500

    kernel/os: os_dev_add check to see if device is already present
    
    If the device is already present in the global list,
    calling os_dev_add() can potentially result in an incorrect
    list. Fix this by checking for the device when the list
    is traversed.
    
    Signed-off-by: Naveen Kaje <[email protected]>
---
 kernel/os/src/os_dev.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/kernel/os/src/os_dev.c b/kernel/os/src/os_dev.c
index b1aee6a..2e1ea38 100644
--- a/kernel/os/src/os_dev.c
+++ b/kernel/os/src/os_dev.c
@@ -64,9 +64,12 @@ os_dev_add(struct os_dev *dev)
      */
     prev_dev = NULL;
     STAILQ_FOREACH(cur_dev, &g_os_dev_list, od_next) {
-        if (dev->od_stage < cur_dev->od_stage ||
-            ((dev->od_stage == cur_dev->od_stage) &&
-             (dev->od_priority < cur_dev->od_priority))) {
+        if (dev == cur_dev) {
+            /* Do nothing */
+            return 0;
+        } else 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;

Reply via email to