init: drop init_fn union
Device init function is no longer taken from `struct init_entry`, so there's no need to keep such union. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
a0a907c90e
commit
ed3377ae78
2 changed files with 7 additions and 75 deletions
|
@ -49,43 +49,6 @@ extern "C" {
|
||||||
|
|
||||||
struct device;
|
struct device;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialization function for init entries.
|
|
||||||
*
|
|
||||||
* Init entries support both the system initialization and the device
|
|
||||||
* APIs. Each API has its own init function signature; hence, we have a
|
|
||||||
* union to cover both.
|
|
||||||
*/
|
|
||||||
union init_function {
|
|
||||||
/**
|
|
||||||
* System initialization function.
|
|
||||||
*
|
|
||||||
* @retval 0 On success
|
|
||||||
* @retval -errno If init fails.
|
|
||||||
*/
|
|
||||||
int (*sys)(void);
|
|
||||||
/**
|
|
||||||
* Device initialization function.
|
|
||||||
*
|
|
||||||
* @param dev Device instance.
|
|
||||||
*
|
|
||||||
* @retval 0 On success
|
|
||||||
* @retval -errno If device initialization fails.
|
|
||||||
*/
|
|
||||||
int (*dev)(const struct device *dev);
|
|
||||||
#ifdef CONFIG_DEVICE_MUTABLE
|
|
||||||
/**
|
|
||||||
* Device initialization function (rw).
|
|
||||||
*
|
|
||||||
* @param dev Device instance.
|
|
||||||
*
|
|
||||||
* @retval 0 On success
|
|
||||||
* @retval -errno If device initialization fails.
|
|
||||||
*/
|
|
||||||
int (*dev_rw)(struct device *dev);
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Structure to store initialization entry information.
|
* @brief Structure to store initialization entry information.
|
||||||
*
|
*
|
||||||
|
@ -101,8 +64,11 @@ union init_function {
|
||||||
* @endinternal
|
* @endinternal
|
||||||
*/
|
*/
|
||||||
struct init_entry {
|
struct init_entry {
|
||||||
/** Initialization function. */
|
/**
|
||||||
union init_function init_fn;
|
* If the init function belongs to a SYS_INIT, this field stored the
|
||||||
|
* initialization function, otherwise it is set to NULL.
|
||||||
|
*/
|
||||||
|
int (*init_fn)(void);
|
||||||
/**
|
/**
|
||||||
* If the init entry belongs to a device, this fields stores a
|
* If the init entry belongs to a device, this fields stores a
|
||||||
* reference to it, otherwise it is set to NULL.
|
* reference to it, otherwise it is set to NULL.
|
||||||
|
@ -151,39 +117,6 @@ struct init_entry {
|
||||||
__attribute__((__section__( \
|
__attribute__((__section__( \
|
||||||
".z_init_" #level STRINGIFY(prio)"_" STRINGIFY(sub_prio)"_")))
|
".z_init_" #level STRINGIFY(prio)"_" STRINGIFY(sub_prio)"_")))
|
||||||
|
|
||||||
|
|
||||||
/* Designated initializers where added to C in C99. There were added to
|
|
||||||
* C++ 20 years later in a much more restricted form. C99 allows many
|
|
||||||
* variations: out of order, mix of designated and not, overlap,
|
|
||||||
* override,... but C++ allows none of these. See differences detailed
|
|
||||||
* in the P0329R0.pdf C++ proposal.
|
|
||||||
* Note __STDC_VERSION__ is undefined when compiling C++.
|
|
||||||
*/
|
|
||||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
|
|
||||||
|
|
||||||
/* Anonymous unions require C11. Some pre-C11 gcc versions have early
|
|
||||||
* support for anonymous unions but they require these braces when
|
|
||||||
* combined with C99 designated initializers, see longer discussion in
|
|
||||||
* #69411.
|
|
||||||
* These braces are compatible with any C version but not with C++20.
|
|
||||||
*/
|
|
||||||
# define Z_INIT_SYS_INIT_DEV_NULL { .dev = NULL }
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* When using -std=c++20 or higher, g++ (v12.2.0) reject braces for
|
|
||||||
* initializing anonymous unions because it is technically a mix of
|
|
||||||
* designated and not designated initializers which is not allowed in
|
|
||||||
* C++. Interestingly, the _same_ g++ version does accept the braces above
|
|
||||||
* when using -std=c++17 or lower!
|
|
||||||
* The tests/lib/cpp/cxx/ added by commit 3d9c428d57bf invoke the C++
|
|
||||||
* compiler with a range of different `-std=...` parameters without needing
|
|
||||||
* any manual configuration.
|
|
||||||
*/
|
|
||||||
# define Z_INIT_SYS_INIT_DEV_NULL .dev = NULL
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @endcond */
|
/** @endcond */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,8 +171,7 @@ struct init_entry {
|
||||||
#define SYS_INIT_NAMED(name, init_fn_, level, prio) \
|
#define SYS_INIT_NAMED(name, init_fn_, level, prio) \
|
||||||
static const Z_DECL_ALIGN(struct init_entry) \
|
static const Z_DECL_ALIGN(struct init_entry) \
|
||||||
Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \
|
Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \
|
||||||
Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}, \
|
Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_)} \
|
||||||
Z_INIT_SYS_INIT_DEV_NULL}
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
|
@ -367,7 +367,7 @@ static void z_sys_init_run_level(enum init_level level)
|
||||||
if (dev != NULL) {
|
if (dev != NULL) {
|
||||||
result = do_device_init(dev);
|
result = do_device_init(dev);
|
||||||
} else {
|
} else {
|
||||||
result = entry->init_fn.sys();
|
result = entry->init_fn();
|
||||||
}
|
}
|
||||||
sys_trace_sys_init_exit(entry, level, result);
|
sys_trace_sys_init_exit(entry, level, result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue