From e5200d5afe4415f3c3f41b0b5c18c733c23d277f Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 22 May 2007 15:02:02 +0000 Subject: [PATCH] 2007-05-22 Joel Sherrill * score/src/corerwlockrelease.c: Do not dereference NULL. --- cpukit/ChangeLog | 4 +++ cpukit/score/src/corerwlockrelease.c | 43 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index a1b3e8d538..70c47843d8 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,7 @@ +2007-05-22 Joel Sherrill + + * score/src/corerwlockrelease.c: Do not dereference NULL. + 2007-05-21 Joel Sherrill * rtems/Makefile.am, rtems/include/rtems/rtems/barrier.h, diff --git a/cpukit/score/src/corerwlockrelease.c b/cpukit/score/src/corerwlockrelease.c index 30daaeaba9..b9d0e2f9e1 100644 --- a/cpukit/score/src/corerwlockrelease.c +++ b/cpukit/score/src/corerwlockrelease.c @@ -79,32 +79,33 @@ CORE_RWLock_Status _CORE_RWLock_Release( next = _Thread_queue_Dequeue( &the_rwlock->Wait_queue ); - rwmode = next->Wait.option; - if ( rwmode == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE ) { - the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING; - return CORE_RWLOCK_SUCCESSFUL; - } + if ( next ) { + rwmode = next->Wait.option; + if ( rwmode == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE ) { + the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING; + return CORE_RWLOCK_SUCCESSFUL; + } - /* - * Must be CORE_RWLOCK_THREAD_WAITING_FOR_READING now see if more - * readers can be let go. - */ - - while ( 1 ) { - next = _Thread_queue_First( &the_rwlock->Wait_queue ); - if ( !next ) - return CORE_RWLOCK_SUCCESSFUL; - if ( next->Wait.option != CORE_RWLOCK_THREAD_WAITING_FOR_READ ) - return CORE_RWLOCK_SUCCESSFUL; - - /* it is definitely wanting to read */ - the_rwlock->number_of_readers += 1; - _Thread_queue_Extract( &the_rwlock->Wait_queue, next ); - } + /* + * Must be CORE_RWLOCK_THREAD_WAITING_FOR_READING now see if more + * readers can be let go. + */ + while ( 1 ) { + next = _Thread_queue_First( &the_rwlock->Wait_queue ); + if ( !next ) + return CORE_RWLOCK_SUCCESSFUL; + if ( next->Wait.option != CORE_RWLOCK_THREAD_WAITING_FOR_READ ) + return CORE_RWLOCK_SUCCESSFUL; + /* it is definitely wanting to read */ + the_rwlock->number_of_readers += 1; + _Thread_queue_Extract( &the_rwlock->Wait_queue, next ); + } /* XXX need to put read/write lock request indicator in Wait info */ + } + return CORE_RWLOCK_SUCCESSFUL; }