Module: xenomai-jki
Branch: for-forge
Commit: 3e6d8ff9a99262e78655329dc043aacc607eb158
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3e6d8ff9a99262e78655329dc043aacc607eb158

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Mon Nov 18 13:19:34 2013 +0100

switchtest: Account for invalid last_switch.from field

If we close a test device early, no switch may have yet taken place when
the first call to rtswitch_to_rt/nrt happens. This can cause to_idx to
become -1, and the system will crash. Handle this corner case
gracefully.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 kernel/drivers/testing/switchtest.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/drivers/testing/switchtest.c 
b/kernel/drivers/testing/switchtest.c
index 6f77ee9..7d17c5f 100644
--- a/kernel/drivers/testing/switchtest.c
+++ b/kernel/drivers/testing/switchtest.c
@@ -147,8 +147,11 @@ static int rtswitch_to_rt(rtswitch_context_t *ctx,
 
        /* to == from is a special case which means
           "return to the previous task". */
-       if (to_idx == from_idx)
+       if (to_idx == from_idx) {
                to_idx = ctx->error.last_switch.from;
+               if (to_idx == -1)
+                       return -EINVAL;
+       }
 
        from = &ctx->tasks[from_idx];
        to = &ctx->tasks[to_idx];
@@ -230,8 +233,11 @@ static int rtswitch_to_nrt(rtswitch_context_t *ctx,
 
        /* to == from is a special case which means
           "return to the previous task". */
-       if (to_idx == from_idx)
+       if (to_idx == from_idx) {
                to_idx = ctx->error.last_switch.from;
+               if (to_idx == -1)
+                       return -EINVAL;
+       }
 
        from = &ctx->tasks[from_idx];
        to = &ctx->tasks[to_idx];


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to