From 3af2dc7802164d6c22dbef1f144c9bd945a35c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20K=C3=BChndel?= Date: Tue, 11 May 2021 16:26:55 +0200 Subject: _TOD_Validate(): Fix incorrect return code This patch fixes bug #4403. Directives * rtems_timer_fire_when() * rtems_timer_server_fire_when() * rtems_task_wake_when() are documented to return RTEMS_INVALID_ADDRESS when their time-of-day argument is NULL. But actually they return RTEMS_INVALID_CLOCK. To fix the issue this patch changes _TOD_Validate() to return a status code instead of just true/false. Close #4403 --- cpukit/rtems/src/clockset.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'cpukit/rtems/src/clockset.c') diff --git a/cpukit/rtems/src/clockset.c b/cpukit/rtems/src/clockset.c index 7a085ada69..df163531a7 100644 --- a/cpukit/rtems/src/clockset.c +++ b/cpukit/rtems/src/clockset.c @@ -29,26 +29,25 @@ rtems_status_code rtems_clock_set( const rtems_time_of_day *tod ) { - Status_Control status; + rtems_status_code status; + Status_Control score_status; + struct timespec tod_as_timespec; + ISR_lock_Context lock_context; - if ( !tod ) - return RTEMS_INVALID_ADDRESS; + status = _TOD_Validate( tod ); - if ( _TOD_Validate( tod ) ) { - struct timespec tod_as_timespec; - ISR_lock_Context lock_context; - - tod_as_timespec.tv_sec = _TOD_To_seconds( tod ); - tod_as_timespec.tv_nsec = tod->ticks - * rtems_configuration_get_nanoseconds_per_tick(); + if ( status != RTEMS_SUCCESSFUL ) { + return status; + } - _TOD_Lock(); - _TOD_Acquire( &lock_context ); - status = _TOD_Set( &tod_as_timespec, &lock_context ); - _TOD_Unlock(); + tod_as_timespec.tv_sec = _TOD_To_seconds( tod ); + tod_as_timespec.tv_nsec = tod->ticks + * rtems_configuration_get_nanoseconds_per_tick(); - return _Status_Get( status ); - } + _TOD_Lock(); + _TOD_Acquire( &lock_context ); + score_status = _TOD_Set( &tod_as_timespec, &lock_context ); + _TOD_Unlock(); - return RTEMS_INVALID_CLOCK; + return _Status_Get( score_status ); } -- cgit v1.2.3