Skip to content

Commit 824135c

Browse files
committed
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>
1 parent 48db6f7 commit 824135c

File tree

2 files changed

+7
-75
lines changed

2 files changed

+7
-75
lines changed

include/zephyr/init.h

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -49,43 +49,6 @@ extern "C" {
4949

5050
struct device;
5151

52-
/**
53-
* @brief Initialization function for init entries.
54-
*
55-
* Init entries support both the system initialization and the device
56-
* APIs. Each API has its own init function signature; hence, we have a
57-
* union to cover both.
58-
*/
59-
union init_function {
60-
/**
61-
* System initialization function.
62-
*
63-
* @retval 0 On success
64-
* @retval -errno If init fails.
65-
*/
66-
int (*sys)(void);
67-
/**
68-
* Device initialization function.
69-
*
70-
* @param dev Device instance.
71-
*
72-
* @retval 0 On success
73-
* @retval -errno If device initialization fails.
74-
*/
75-
int (*dev)(const struct device *dev);
76-
#ifdef CONFIG_DEVICE_MUTABLE
77-
/**
78-
* Device initialization function (rw).
79-
*
80-
* @param dev Device instance.
81-
*
82-
* @retval 0 On success
83-
* @retval -errno If device initialization fails.
84-
*/
85-
int (*dev_rw)(struct device *dev);
86-
#endif
87-
};
88-
8952
/**
9053
* @brief Structure to store initialization entry information.
9154
*
@@ -101,8 +64,11 @@ union init_function {
10164
* @endinternal
10265
*/
10366
struct init_entry {
104-
/** Initialization function. */
105-
union init_function init_fn;
67+
/**
68+
* If the init function belongs to a SYS_INIT, this field stored the
69+
* initialization function, otherwise it is set to NULL.
70+
*/
71+
int (*init_fn)(void);
10672
/**
10773
* If the init entry belongs to a device, this fields stores a
10874
* reference to it, otherwise it is set to NULL.
@@ -151,39 +117,6 @@ struct init_entry {
151117
__attribute__((__section__( \
152118
".z_init_" #level STRINGIFY(prio)"_" STRINGIFY(sub_prio)"_")))
153119

154-
155-
/* Designated initializers where added to C in C99. There were added to
156-
* C++ 20 years later in a much more restricted form. C99 allows many
157-
* variations: out of order, mix of designated and not, overlap,
158-
* override,... but C++ allows none of these. See differences detailed
159-
* in the P0329R0.pdf C++ proposal.
160-
* Note __STDC_VERSION__ is undefined when compiling C++.
161-
*/
162-
#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
163-
164-
/* Anonymous unions require C11. Some pre-C11 gcc versions have early
165-
* support for anonymous unions but they require these braces when
166-
* combined with C99 designated initializers, see longer discussion in
167-
* #69411.
168-
* These braces are compatible with any C version but not with C++20.
169-
*/
170-
# define Z_INIT_SYS_INIT_DEV_NULL { .dev = NULL }
171-
172-
#else
173-
174-
/* When using -std=c++20 or higher, g++ (v12.2.0) reject braces for
175-
* initializing anonymous unions because it is technically a mix of
176-
* designated and not designated initializers which is not allowed in
177-
* C++. Interestingly, the _same_ g++ version does accept the braces above
178-
* when using -std=c++17 or lower!
179-
* The tests/lib/cpp/cxx/ added by commit 3d9c428d57bf invoke the C++
180-
* compiler with a range of different `-std=...` parameters without needing
181-
* any manual configuration.
182-
*/
183-
# define Z_INIT_SYS_INIT_DEV_NULL .dev = NULL
184-
185-
#endif
186-
187120
/** @endcond */
188121

189122
/**
@@ -238,8 +171,7 @@ struct init_entry {
238171
#define SYS_INIT_NAMED(name, init_fn_, level, prio) \
239172
static const Z_DECL_ALIGN(struct init_entry) \
240173
Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \
241-
Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}, \
242-
Z_INIT_SYS_INIT_DEV_NULL}
174+
Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_)} \
243175

244176
/** @} */
245177

kernel/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static void z_sys_init_run_level(enum init_level level)
367367
if (dev != NULL) {
368368
result = do_device_init(dev);
369369
} else {
370-
result = entry->init_fn.sys();
370+
result = entry->init_fn();
371371
}
372372
sys_trace_sys_init_exit(entry, level, result);
373373
}

0 commit comments

Comments
 (0)