Skip to content

Commit 3f6add6

Browse files
gmarullhenrikbrixandersen
authored andcommitted
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 <[email protected]>
1 parent ed3377a commit 3f6add6

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
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
}

tests/lib/devicetree/devices/src/main.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,25 @@ DEVICE_DT_DEFINE(TEST_NOLABEL, dev_init, NULL,
6464
ZTEST(devicetree_devices, test_init_get)
6565
{
6666
/* Check device pointers */
67-
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO)->dev.dev,
67+
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO)->dev,
6868
DEVICE_DT_GET(TEST_GPIO), NULL);
69-
zassert_equal(DEVICE_INIT_DT_GET(TEST_I2C)->dev.dev,
69+
zassert_equal(DEVICE_INIT_DT_GET(TEST_I2C)->dev,
7070
DEVICE_DT_GET(TEST_I2C), NULL);
71-
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVA)->dev.dev,
71+
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVA)->dev,
7272
DEVICE_DT_GET(TEST_DEVA), NULL);
73-
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVB)->dev.dev,
73+
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVB)->dev,
7474
DEVICE_DT_GET(TEST_DEVB), NULL);
75-
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIOX)->dev.dev,
75+
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIOX)->dev,
7676
DEVICE_DT_GET(TEST_GPIOX), NULL);
77-
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVC)->dev.dev,
77+
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVC)->dev,
7878
DEVICE_DT_GET(TEST_DEVC), NULL);
79-
zassert_equal(DEVICE_INIT_DT_GET(TEST_PARTITION)->dev.dev,
79+
zassert_equal(DEVICE_INIT_DT_GET(TEST_PARTITION)->dev,
8080
DEVICE_DT_GET(TEST_PARTITION), NULL);
81-
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO_INJECTED)->dev.dev,
81+
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO_INJECTED)->dev,
8282
DEVICE_DT_GET(TEST_GPIO_INJECTED), NULL);
83-
zassert_equal(DEVICE_INIT_GET(manual_dev)->dev.dev,
83+
zassert_equal(DEVICE_INIT_GET(manual_dev)->dev,
8484
DEVICE_GET(manual_dev), NULL);
85-
zassert_equal(DEVICE_INIT_DT_GET(TEST_NOLABEL)->dev.dev,
85+
zassert_equal(DEVICE_INIT_DT_GET(TEST_NOLABEL)->dev,
8686
DEVICE_DT_GET(TEST_NOLABEL), NULL);
8787

8888
/* Check init functions */

0 commit comments

Comments
 (0)