[PATCH v1] fix compiling warning

朱忠杰 zhongjiezhu1 at gmail.com
Mon Jan 16 09:38:23 UTC 2023


with RTEMS_SMP or RTEMS_PROFILING defined, it will call
_Thread_Dispatch_disable_critical( &lock_context )
only in UP system with RTEMS_PROFILING not defined, it will call
_Thread_Dispatch_disable_critical( NULL ), in this case, the real
function use the lock_context is
_Profiling_Thread_dispatch_disable_critical(), it is an empty
function.
I have tried the three cases.
it could also be avoid by initialize the lock_context = {};

Sebastian Huber <sebastian.huber at embedded-brains.de> 于2023年1月16日周一 17:02写道:
>
> On 16.01.23 09:36, Zhu Zhongjie wrote:
> > From: Zhongjie Zhu <zhongjiezhu1 at gmail.com>
> >
> > there are different cases for _ISR_lock_ISR_disable() and _ISR_lock_ISR_enable()
> > in the case RTEMS_SMP is defined or RTEMS_PROFILING is defined, so remove the related code.
> >
> > ../../../cpukit/include/rtems/score/threaddispatch.h: In function '_Thread_Dispatch_disable':
> > ../../../cpukit/include/rtems/score/threaddispatch.h:231:14: warning: 'lock_context' may be used uninitialized [-Wmaybe-uninitialized]
> >    231 |   cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
> >        |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ../../../cpukit/include/rtems/score/threaddispatch.h:210:32: note: by argument 1 of type 'const ISR_lock_Context *' to '_Thread_Dispatch_disable_critical' declared here
> >    210 | static inline Per_CPU_Control *_Thread_Dispatch_disable_critical(
> >        |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ../../../cpukit/include/rtems/score/threaddispatch.h:225:21: note: 'lock_context' declared here
> >    225 |   ISR_lock_Context  lock_context;
> >        |                     ^~~~~~~~~~~~
> > ---
> >   cpukit/include/rtems/score/threaddispatch.h | 7 ++++---
> >   1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/cpukit/include/rtems/score/threaddispatch.h b/cpukit/include/rtems/score/threaddispatch.h
> > index 589935823f..b06ebe8fec 100644
> > --- a/cpukit/include/rtems/score/threaddispatch.h
> > +++ b/cpukit/include/rtems/score/threaddispatch.h
> > @@ -222,16 +222,17 @@ static inline Per_CPU_Control *_Thread_Dispatch_disable_critical(
> >   static inline Per_CPU_Control *_Thread_Dispatch_disable( void )
> >   {
> >     Per_CPU_Control  *cpu_self;
> > -  ISR_lock_Context  lock_context;
> >
> >   #if defined( RTEMS_SMP ) || defined( RTEMS_PROFILING )
> > +  ISR_lock_Context  lock_context;
> > +
> >     _ISR_lock_ISR_disable( &lock_context );
> > -#endif
> >
> >     cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
> >
> > -#if defined( RTEMS_SMP ) || defined( RTEMS_PROFILING )
> >     _ISR_lock_ISR_enable( &lock_context );
> > +#else
> > +  cpu_self = _Thread_Dispatch_disable_critical( NULL );
> >   #endif
> >
> >     return cpu_self;
>
> I doubt that this patch compiles if RTEMS_SMP or RTEMS_PROFILING is not
> defined.
>
> The problem with the warning is that _Thread_Dispatch_disable_critical()
> takes a const pointer to lock_context and nobody writes to this
> structure before it is handed over.
>
> --
> embedded brains GmbH
> Herr Sebastian HUBER
> Dornierstr. 4
> 82178 Puchheim
> Germany
> email: sebastian.huber at embedded-brains.de
> phone: +49-89-18 94 741 - 16
> fax:   +49-89-18 94 741 - 08
>
> Registergericht: Amtsgericht München
> Registernummer: HRB 157899
> Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
> Unsere Datenschutzerklärung finden Sie hier:
> https://embedded-brains.de/datenschutzerklaerung/


More information about the devel mailing list