From 776464aad46cd317b9707870acc5f6be5531e15a Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 19 Sep 2018 11:52:47 +0200 Subject: score: Allocate per-CPU data only if necessary The _Workspace_Allocate_aligned() would returns a non-NULL pointer for a zero size allocation request if there is enough memory available. This conflicts with the size estimate of zero in _Workspace_Space_for_per_CPU_data() if the per-CPU data set is empty. Update #3507. --- cpukit/score/src/wkspace.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c index 823e357009..ea2ab84849 100644 --- a/cpukit/score/src/wkspace.c +++ b/cpukit/score/src/wkspace.c @@ -129,22 +129,26 @@ static uintptr_t _Workspace_Space_for_per_CPU_data( uintptr_t page_size ) static void _Workspace_Allocate_per_CPU_data( void ) { #ifdef RTEMS_SMP - Per_CPU_Control *cpu; - uintptr_t size; - uint32_t cpu_index; - uint32_t cpu_max; - - cpu = _Per_CPU_Get_by_index( 0 ); - cpu->data = RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ); + uintptr_t size; size = RTEMS_LINKER_SET_SIZE( _Per_CPU_Data ); - cpu_max = rtems_configuration_get_maximum_processors(); - for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) { - cpu = _Per_CPU_Get_by_index( cpu_index ); - cpu->data = _Workspace_Allocate_aligned( size, CPU_CACHE_LINE_BYTES ); - _Assert( cpu->data != NULL ); - memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size); + if ( size > 0 ) { + Per_CPU_Control *cpu; + uint32_t cpu_index; + uint32_t cpu_max; + + cpu = _Per_CPU_Get_by_index( 0 ); + cpu->data = RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ); + + cpu_max = rtems_configuration_get_maximum_processors(); + + for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) { + cpu = _Per_CPU_Get_by_index( cpu_index ); + cpu->data = _Workspace_Allocate_aligned( size, CPU_CACHE_LINE_BYTES ); + _Assert( cpu->data != NULL ); + memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size); + } } #endif } -- cgit v1.2.3