Skip to content

Commit 57c408f

Browse files
committed
init: drop device union from struct init_entry
Such union is rather redundant, considering a simple const cast can be done when initializing the init entry. Note that the init_entry does not need to be touched now that struct device stores the init call. It is merely an init entry sorted by linker scripts, so we can intertwine devices and SYS_INIT. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
1 parent 824135c commit 57c408f

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

include/zephyr/device.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,18 +1156,14 @@ device_get_dt_nodelabels(const struct device *dev)
11561156
static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \
11571157
level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \
11581158
Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1159-
COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), \
1160-
(.dev = { .dev_rw = &DEVICE_NAME_GET(dev_id)}), \
1161-
(.dev = { .dev = &DEVICE_NAME_GET(dev_id)})) \
1159+
.dev = (const struct device *)&DEVICE_NAME_GET(dev_id) \
11621160
}
11631161

11641162
#define Z_DEFER_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id) \
11651163
static const Z_DECL_ALIGN(struct init_entry) __used __noasan \
11661164
__attribute__((__section__(".z_deferred_init"))) \
11671165
Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1168-
COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), \
1169-
(.dev = { .dev_rw = &DEVICE_NAME_GET(dev_id)}), \
1170-
(.dev = { .dev = &DEVICE_NAME_GET(dev_id)})) \
1166+
.dev = (const struct device *)&DEVICE_NAME_GET(dev_id) \
11711167
}
11721168

11731169
/**

include/zephyr/init.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ struct init_entry {
7373
* If the init entry belongs to a device, this fields stores a
7474
* reference to it, otherwise it is set to NULL.
7575
*/
76-
union {
77-
const struct device *dev;
78-
#ifdef CONFIG_DEVICE_MUTABLE
79-
struct device *dev_rw;
80-
#endif
81-
} dev;
76+
const struct device *dev;
8277
};
8378

8479
/** @cond INTERNAL_HIDDEN */

kernel/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static void z_sys_init_run_level(enum init_level level)
360360
const struct init_entry *entry;
361361

362362
for (entry = levels[level]; entry < levels[level+1]; entry++) {
363-
const struct device *dev = entry->dev.dev;
363+
const struct device *dev = entry->dev;
364364
int result;
365365

366366
sys_trace_sys_init_enter(entry, level);
@@ -381,7 +381,7 @@ int z_impl_device_init(const struct device *dev)
381381
}
382382

383383
STRUCT_SECTION_FOREACH_ALTERNATE(_deferred_init, init_entry, entry) {
384-
if (entry->dev.dev == dev) {
384+
if (entry->dev == dev) {
385385
return do_device_init(dev);
386386
}
387387
}

0 commit comments

Comments
 (0)