From 51932c2cec1a694ef36bb592f77f822d00156aa3 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 17 Aug 2022 14:11:58 +0200 Subject: [PATCH] random: initialize devices at compile time Initialize devices at compile time so that device pointer can be constified. Signed-off-by: Gerard Marull-Paretas --- subsys/random/rand32_entropy_device.c | 3 ++- subsys/random/rand32_xoshiro128.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/subsys/random/rand32_entropy_device.c b/subsys/random/rand32_entropy_device.c index 397a8216934..92ce441911e 100644 --- a/subsys/random/rand32_entropy_device.c +++ b/subsys/random/rand32_entropy_device.c @@ -9,7 +9,8 @@ #include #include -static const struct device *entropy_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); +static const struct device *const entropy_dev = + DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); #if defined(CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR) uint32_t z_impl_sys_rand32_get(void) diff --git a/subsys/random/rand32_xoshiro128.c b/subsys/random/rand32_xoshiro128.c index 23c82b1b3e5..4556280e48d 100644 --- a/subsys/random/rand32_xoshiro128.c +++ b/subsys/random/rand32_xoshiro128.c @@ -32,7 +32,8 @@ #include #include -static const struct device *entropy_driver; +static const struct device *const entropy_driver = + DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); static uint32_t state[4]; static bool initialized; @@ -43,7 +44,6 @@ static inline uint32_t rotl(const uint32_t x, int k) static int xoshiro128_initialize(const struct device *dev) { - entropy_driver = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); if (!device_is_ready(entropy_driver)) { return -ENODEV; }