From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <528A156C.1070501@xenomai.org> Date: Mon, 18 Nov 2013 14:26:04 +0100 From: Gilles Chanteperdrix MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai] [Xenomai-git] Jan Kiszka : switchtest: Account for invalid last_switch.from field List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xenomai@xenomai.org On 11/18/2013 01:41 PM, git repository hosting wrote: > Module: xenomai-jki > Branch: for-forge > Commit: 3e6d8ff9a99262e78655329dc043aacc607eb158 > URL: http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3e6d8ff9a99262e78655329dc043aacc607eb158 > > Author: Jan Kiszka > 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 > > --- > > 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; > + } I do not see how we can reach rtswitch_to_rt without having switched context, since the first task to run is not an rt task. -- Gilles.