fix(cpufeat): make stub enable functions "static inline"

For builds where we don't have a certain feature enabled, we provide
empty stub xxx_enable() functions in a header file. This way we
avoid #ifdef's in the code, and can call the enable function
unconditionally. When compiling with -O1 or higher, the compiler will
even optimise out the whole call, so the symbol will never make it into
any object file.
When compiling with optimisations turned off, the function stub will
survive, and could make it into multiple object files, which would lead
to a multiple definitons error.

Avoid this by defining those stub functions as "static inline". The
"static" will avoid the multiple definitions problems, the "inline" will
avoid a potential compiler warning about unused functions.
This patterns is used extensively in the Linux kernel.

Change-Id: Iad07bb946aab372587c83f2423b4983bf3817990
Reported-by: Chris Kay <chris.kay@arm.com>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
This commit is contained in:
Andre Przywara 2023-03-22 13:25:00 +00:00
parent 1f8be7fc66
commit d7f3ed3655
5 changed files with 6 additions and 6 deletions

View file

@ -10,7 +10,7 @@
#if ENABLE_BRBE_FOR_NS #if ENABLE_BRBE_FOR_NS
void brbe_enable(void); void brbe_enable(void);
#else #else
void brbe_enable(void) static inline void brbe_enable(void)
{ {
} }
#endif /* ENABLE_BRBE_FOR_NS */ #endif /* ENABLE_BRBE_FOR_NS */

View file

@ -12,7 +12,7 @@
#if ENABLE_MPAM_FOR_LOWER_ELS #if ENABLE_MPAM_FOR_LOWER_ELS
void mpam_enable(bool el2_unused); void mpam_enable(bool el2_unused);
#else #else
void mpam_enable(bool el2_unused) static inline void mpam_enable(bool el2_unused)
{ {
} }
#endif #endif

View file

@ -13,10 +13,10 @@
void spe_enable(bool el2_unused); void spe_enable(bool el2_unused);
void spe_disable(void); void spe_disable(void);
#else #else
void spe_enable(bool el2_unused) static inline void spe_enable(bool el2_unused)
{ {
} }
void spe_disable(void) static inline void spe_disable(void)
{ {
} }
#endif #endif

View file

@ -10,7 +10,7 @@
#if ENABLE_TRBE_FOR_NS #if ENABLE_TRBE_FOR_NS
void trbe_enable(void); void trbe_enable(void);
#else #else
void trbe_enable(void) static inline void trbe_enable(void)
{ {
} }
#endif /* ENABLE_TRBE_FOR_NS */ #endif /* ENABLE_TRBE_FOR_NS */

View file

@ -10,7 +10,7 @@
#if ENABLE_TRF_FOR_NS #if ENABLE_TRF_FOR_NS
void trf_enable(void); void trf_enable(void);
#else #else
void trf_enable(void) static inline void trf_enable(void)
{ {
} }
#endif /* ENABLE_TRF_FOR_NS */ #endif /* ENABLE_TRF_FOR_NS */