From e0125d04af61097d2d880f4f35cab896d3aa2d2c Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 17 Aug 2022 15:37:22 +0200 Subject: [PATCH] devices: constify statically initialized device pointers It is frequent to find variable definitions like this: ```c static const struct device *dev = DEVICE_DT_GET(...) ``` That is, module level variables that are statically initialized with a device reference. Such value is, in most cases, never changed meaning the variable can also be declared as const (immutable). This patch constifies all such cases. Signed-off-by: Gerard Marull-Paretas --- arch/x86/core/intel64/irq.c | 2 +- arch/x86/core/pcie.c | 2 +- drivers/adc/adc_gd32.c | 2 +- drivers/adc/adc_stm32.c | 3 ++- drivers/dma/dma_stm32.c | 3 ++- drivers/flash/flash_shell.c | 2 +- drivers/gpio/gpio_xlnx_ps.c | 2 +- drivers/pinctrl/pinctrl_stm32.c | 2 +- drivers/pinctrl/pinctrl_xlnx_zynq.c | 2 +- drivers/timer/stm32_lptim_timer.c | 2 +- .../sl_opensource/platform/nrf_802154_temperature_zephyr.c | 2 +- modules/openthread/platform/entropy.c | 2 +- samples/arch/mpu/mpu_test/src/main.c | 2 +- samples/bluetooth/hci_spi/src/main.c | 2 +- samples/bluetooth/hci_uart/src/main.c | 2 +- samples/bluetooth/mesh/src/board.c | 4 ++-- samples/bluetooth/mesh_demo/src/microbit.c | 5 +++-- samples/boards/96b_argonkey/microphone/src/main.c | 2 +- samples/boards/mimxrt1060_evk/system_off/src/main.c | 2 +- samples/boards/nrf/clock_skew/src/main.c | 4 ++-- samples/boards/reel_board/mesh_badge/src/periphs.c | 2 +- samples/drivers/dac/src/main.c | 2 +- samples/drivers/led_lpd8806/src/main.c | 2 +- samples/drivers/led_ws2812/src/main.c | 2 +- samples/drivers/uart/echo_bot/src/main.c | 2 +- samples/sensor/accel_polling/src/main.c | 2 +- samples/shields/x_nucleo_53l0a1/src/display_7seg.c | 4 ++-- samples/shields/x_nucleo_53l0a1/src/main.c | 2 +- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 2 +- subsys/bluetooth/controller/ll_sw/openisa/lll/lll.c | 2 +- subsys/shell/modules/device_service.c | 2 +- subsys/testsuite/busy_sim/busy_sim.c | 2 +- tests/boards/espressif_esp32/cache_coex/src/cache_coex.c | 2 +- tests/boards/frdm_k64f/i2c/src/i2c.c | 2 +- tests/drivers/can/canfd/src/main.c | 2 +- tests/drivers/clock_control/nrf_onoff_and_bt/src/main.c | 2 +- tests/drivers/counter/counter_basic_api/src/test_counter.c | 4 ++-- .../counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c | 2 +- tests/drivers/counter/maxim_ds3231_api/src/test_counter.c | 2 +- tests/drivers/flash/src/main.c | 2 +- tests/drivers/flash_simulator/src/main.c | 2 +- tests/drivers/mipi_dsi/api/src/main.c | 2 +- tests/drivers/regulator/fixed/src/main.c | 2 +- tests/drivers/sdhc/src/main.c | 2 +- tests/subsys/fs/nvs/src/main.c | 2 +- tests/subsys/openthread/radio_test.c | 2 +- tests/subsys/sd/sdmmc/src/main.c | 2 +- tests/subsys/storage/stream/stream_flash/src/main.c | 2 +- 48 files changed, 56 insertions(+), 53 deletions(-) diff --git a/arch/x86/core/intel64/irq.c b/arch/x86/core/intel64/irq.c index fb29e590688..026281dfc6f 100644 --- a/arch/x86/core/intel64/irq.c +++ b/arch/x86/core/intel64/irq.c @@ -34,7 +34,7 @@ const void *x86_irq_args[NR_IRQ_VECTORS]; #include #include -static const struct device *vtd = DEVICE_DT_GET_ONE(intel_vt_d); +static const struct device *const vtd = DEVICE_DT_GET_ONE(intel_vt_d); #endif /* CONFIG_INTEL_VTD_ICTL */ diff --git a/arch/x86/core/pcie.c b/arch/x86/core/pcie.c index e59e730dc4b..1d2888b8d12 100644 --- a/arch/x86/core/pcie.c +++ b/arch/x86/core/pcie.c @@ -164,7 +164,7 @@ void pcie_conf_write(pcie_bdf_t bdf, unsigned int reg, uint32_t data) #include #include -static const struct device *vtd = DEVICE_DT_GET_ONE(intel_vt_d); +static const struct device *const vtd = DEVICE_DT_GET_ONE(intel_vt_d); #endif /* CONFIG_INTEL_VTD_ICTL */ diff --git a/drivers/adc/adc_gd32.c b/drivers/adc/adc_gd32.c index e4cba411f18..b0838e53035 100644 --- a/drivers/adc/adc_gd32.c +++ b/drivers/adc/adc_gd32.c @@ -372,7 +372,7 @@ static int adc_gd32_init(const struct device *dev) } #define HANDLE_SHARED_IRQ(n, active_irq) \ - static const struct device *dev_##n = DEVICE_DT_INST_GET(n); \ + static const struct device *const dev_##n = DEVICE_DT_INST_GET(n); \ const struct adc_gd32_config *cfg_##n = dev_##n->config; \ \ if ((cfg_##n->irq_num == active_irq) && \ diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index b081b9d0ae1..0ff37df7f59 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -1185,7 +1185,8 @@ bool adc_stm32_is_irq_active(ADC_TypeDef *adc) } #define HANDLE_IRQS(index) \ - static const struct device *dev_##index = DEVICE_DT_INST_GET(index); \ + static const struct device *const dev_##index = \ + DEVICE_DT_INST_GET(index); \ const struct adc_stm32_cfg *cfg_##index = dev_##index->config; \ ADC_TypeDef *adc_##index = (ADC_TypeDef *)(cfg_##index->base); \ \ diff --git a/drivers/dma/dma_stm32.c b/drivers/dma/dma_stm32.c index 7f2d7a62769..d4cc46a3f93 100644 --- a/drivers/dma/dma_stm32.c +++ b/drivers/dma/dma_stm32.c @@ -143,7 +143,8 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id) #ifdef CONFIG_DMA_STM32_SHARED_IRQS #define HANDLE_IRQS(index) \ - static const struct device *dev_##index = DEVICE_DT_INST_GET(index); \ + static const struct device *const dev_##index = \ + DEVICE_DT_INST_GET(index); \ const struct dma_stm32_config *cfg_##index = dev_##index->config; \ DMA_TypeDef *dma_##index = (DMA_TypeDef *)(cfg_##index->base); \ \ diff --git a/drivers/flash/flash_shell.c b/drivers/flash/flash_shell.c index f0358d7e367..1b8b78e1ba8 100644 --- a/drivers/flash/flash_shell.c +++ b/drivers/flash/flash_shell.c @@ -26,7 +26,7 @@ */ BUILD_ASSERT(BUF_ARRAY_CNT >= 1); -static const struct device *zephyr_flash_controller = +static const struct device *const zephyr_flash_controller = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_flash_controller)); static uint8_t __aligned(4) test_arr[TEST_ARR_SIZE]; diff --git a/drivers/gpio/gpio_xlnx_ps.c b/drivers/gpio/gpio_xlnx_ps.c index 001ce2d58be..e1f7e729bd0 100644 --- a/drivers/gpio/gpio_xlnx_ps.c +++ b/drivers/gpio/gpio_xlnx_ps.c @@ -97,7 +97,7 @@ static void gpio_xlnx_ps_isr(const struct device *dev) #define GPIO_XLNX_PS_CHILD_CONCAT(idx) DEVICE_DT_GET(idx), #define GPIO_XLNX_PS_GEN_BANK_ARRAY(idx)\ -static const struct device *gpio_xlnx_ps##idx##_banks[] = {\ +static const struct device *const gpio_xlnx_ps##idx##_banks[] = {\ DT_FOREACH_CHILD_STATUS_OKAY(DT_DRV_INST(idx), GPIO_XLNX_PS_CHILD_CONCAT)\ }; diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index a27595120e3..ee4f3ff0e35 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -19,7 +19,7 @@ * * Entries will be NULL if the GPIO port is not enabled. */ -static const struct device * const gpio_ports[] = { +static const struct device *const gpio_ports[] = { DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpioa)), DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpiob)), DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpioc)), diff --git a/drivers/pinctrl/pinctrl_xlnx_zynq.c b/drivers/pinctrl/pinctrl_xlnx_zynq.c index e19524ef85d..a1c4aa20a09 100644 --- a/drivers/pinctrl/pinctrl_xlnx_zynq.c +++ b/drivers/pinctrl/pinctrl_xlnx_zynq.c @@ -22,7 +22,7 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1, #define SD0_WP_CD_SEL_OFFSET 0x0130 #define SD1_WP_CD_SEL_OFFSET 0x0134 -static const struct device *slcr = DEVICE_DT_GET(DT_INST_PHANDLE(0, syscon)); +static const struct device *const slcr = DEVICE_DT_GET(DT_INST_PHANDLE(0, syscon)); static mm_reg_t base = DT_INST_REG_ADDR(0); K_SEM_DEFINE(pinctrl_lock, 1, 1); diff --git a/drivers/timer/stm32_lptim_timer.c b/drivers/timer/stm32_lptim_timer.c index c7362dff6c8..b9c255e3e0c 100644 --- a/drivers/timer/stm32_lptim_timer.c +++ b/drivers/timer/stm32_lptim_timer.c @@ -42,7 +42,7 @@ static const struct stm32_pclken lptim_clk[] = { static const struct stm32_pclken lptim_clk[] = STM32_DT_INST_CLOCKS(0); #endif -static const struct device *clk_ctrl = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE); +static const struct device *const clk_ctrl = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE); /* * Assumptions and limitations: diff --git a/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_temperature_zephyr.c b/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_temperature_zephyr.c index a63d2487fb8..cc2a1e69bcc 100644 --- a/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_temperature_zephyr.c +++ b/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_temperature_zephyr.c @@ -30,7 +30,7 @@ static int8_t value = DEFAULT_TEMPERATURE; #if defined(CONFIG_NRF_802154_TEMPERATURE_UPDATE) -static const struct device *device = DEVICE_DT_GET(DT_NODELABEL(temp)); +static const struct device *const device = DEVICE_DT_GET(DT_NODELABEL(temp)); static struct k_work_delayable dwork; static void work_handler(struct k_work *work) diff --git a/modules/openthread/platform/entropy.c b/modules/openthread/platform/entropy.c index 58d23ed438c..e8790908494 100644 --- a/modules/openthread/platform/entropy.c +++ b/modules/openthread/platform/entropy.c @@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(net_otPlat_entropy, CONFIG_OPENTHREAD_L2_LOG_LEVEL); #error OpenThread requires an entropy source for a TRNG #endif -static const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); +static const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) { diff --git a/samples/arch/mpu/mpu_test/src/main.c b/samples/arch/mpu/mpu_test/src/main.c index d95f62db929..8726a4bbbd1 100644 --- a/samples/arch/mpu/mpu_test/src/main.c +++ b/samples/arch/mpu/mpu_test/src/main.c @@ -31,7 +31,7 @@ #if defined(CONFIG_SOC_FLASH_MCUX) || defined(CONFIG_SOC_FLASH_LPC) || \ defined(CONFIG_SOC_FLASH_STM32) -static const struct device *flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); +static const struct device *const flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); #endif static int cmd_read(const struct shell *shell, size_t argc, char *argv[]) diff --git a/samples/bluetooth/hci_spi/src/main.c b/samples/bluetooth/hci_spi/src/main.c index eb8c6bf7f98..cd71e84a870 100644 --- a/samples/bluetooth/hci_spi/src/main.c +++ b/samples/bluetooth/hci_spi/src/main.c @@ -83,7 +83,7 @@ const static struct spi_buf_set tx_bufs = { * This is the SPI bus controller device used to exchange data with * the SPI-based BT controller. */ -static const struct device *spi_hci_dev = DEVICE_DT_GET(DT_BUS(HCI_SPI_NODE)); +static const struct device *const spi_hci_dev = DEVICE_DT_GET(DT_BUS(HCI_SPI_NODE)); static struct spi_config spi_cfg = { .operation = SPI_WORD_SET(8) | SPI_OP_MODE_SLAVE, }; diff --git a/samples/bluetooth/hci_uart/src/main.c b/samples/bluetooth/hci_uart/src/main.c index 6d7bde1985d..429044ebe2c 100644 --- a/samples/bluetooth/hci_uart/src/main.c +++ b/samples/bluetooth/hci_uart/src/main.c @@ -30,7 +30,7 @@ #define LOG_MODULE_NAME hci_uart LOG_MODULE_REGISTER(LOG_MODULE_NAME); -static const struct device *hci_uart_dev = +static const struct device *const hci_uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_c2h_uart)); static K_THREAD_STACK_DEFINE(tx_thread_stack, CONFIG_BT_HCI_TX_STACK_SIZE); static struct k_thread tx_thread_data; diff --git a/samples/bluetooth/mesh/src/board.c b/samples/bluetooth/mesh/src/board.c index bf5e30cdffd..3c16279774f 100644 --- a/samples/bluetooth/mesh/src/board.c +++ b/samples/bluetooth/mesh/src/board.c @@ -37,7 +37,7 @@ #define LED0_PIN DT_PHA(LED0, gpios, pin) #define LED0_FLAGS DT_PHA(LED0, gpios, flags) -static const struct device *led_dev = DEVICE_DT_GET(LED0_DEV); +static const struct device *const led_dev = DEVICE_DT_GET(LED0_DEV); #endif /* LED0 */ #if DT_NODE_EXISTS(BUTTON0) @@ -45,7 +45,7 @@ static const struct device *led_dev = DEVICE_DT_GET(LED0_DEV); #define BUTTON0_PIN DT_PHA(BUTTON0, gpios, pin) #define BUTTON0_FLAGS DT_PHA(BUTTON0, gpios, flags) -static const struct device *button_dev = DEVICE_DT_GET(BUTTON0_DEV); +static const struct device *const button_dev = DEVICE_DT_GET(BUTTON0_DEV); static struct k_work *button_work; static void button_cb(const struct device *port, struct gpio_callback *cb, diff --git a/samples/bluetooth/mesh_demo/src/microbit.c b/samples/bluetooth/mesh_demo/src/microbit.c index 1c70e869cd9..12cab0c1869 100644 --- a/samples/bluetooth/mesh_demo/src/microbit.c +++ b/samples/bluetooth/mesh_demo/src/microbit.c @@ -32,9 +32,10 @@ static const struct gpio_dt_spec button_a = GPIO_DT_SPEC_GET(DT_NODELABEL(buttona), gpios); static const struct gpio_dt_spec button_b = GPIO_DT_SPEC_GET(DT_NODELABEL(buttonb), gpios); -static const struct device *nvm = +static const struct device *const nvm = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); -static const struct device *pwm = DEVICE_DT_GET_ANY(nordic_nrf_sw_pwm); +static const struct device *const pwm = + DEVICE_DT_GET_ANY(nordic_nrf_sw_pwm); static struct k_work button_work; diff --git a/samples/boards/96b_argonkey/microphone/src/main.c b/samples/boards/96b_argonkey/microphone/src/main.c index 4bbdfd6ab25..e040984ef15 100644 --- a/samples/boards/96b_argonkey/microphone/src/main.c +++ b/samples/boards/96b_argonkey/microphone/src/main.c @@ -86,7 +86,7 @@ void main(void) } #ifdef CONFIG_LP3943 - static const struct device *ledc = DEVICE_DT_GET_ONE(ti_lp3943); + static const struct device *const ledc = DEVICE_DT_GET_ONE(ti_lp3943); if (!device_is_ready(ledc)) { printk("Device %s is not ready\n", ledc->name); diff --git a/samples/boards/mimxrt1060_evk/system_off/src/main.c b/samples/boards/mimxrt1060_evk/system_off/src/main.c index 798c2160f8b..ee8304071d9 100644 --- a/samples/boards/mimxrt1060_evk/system_off/src/main.c +++ b/samples/boards/mimxrt1060_evk/system_off/src/main.c @@ -29,7 +29,7 @@ #define SNVS_LP_RTC_ALARM_ID 1 static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, { 0 }); -static const struct device *snvs_rtc_dev = DEVICE_DT_GET(SNVS_RTC_NODE); +static const struct device *const snvs_rtc_dev = DEVICE_DT_GET(SNVS_RTC_NODE); void main(void) { diff --git a/samples/boards/nrf/clock_skew/src/main.c b/samples/boards/nrf/clock_skew/src/main.c index fc58f7a80b0..cd12e0dcb39 100644 --- a/samples/boards/nrf/clock_skew/src/main.c +++ b/samples/boards/nrf/clock_skew/src/main.c @@ -14,8 +14,8 @@ #define UPDATE_INTERVAL_S 10 -static const struct device *clock0 = DEVICE_DT_GET_ONE(nordic_nrf_clock); -static const struct device *timer0 = DEVICE_DT_GET(DT_NODELABEL(timer0)); +static const struct device *const clock0 = DEVICE_DT_GET_ONE(nordic_nrf_clock); +static const struct device *const timer0 = DEVICE_DT_GET(DT_NODELABEL(timer0)); static struct timeutil_sync_config sync_config; static uint64_t counter_ref; static struct timeutil_sync_state sync_state; diff --git a/samples/boards/reel_board/mesh_badge/src/periphs.c b/samples/boards/reel_board/mesh_badge/src/periphs.c index a374e3d3279..d8e42708063 100644 --- a/samples/boards/reel_board/mesh_badge/src/periphs.c +++ b/samples/boards/reel_board/mesh_badge/src/periphs.c @@ -12,7 +12,7 @@ #include -static const struct device *dev_info[] = { +static const struct device *const dev_info[] = { DEVICE_DT_GET_ONE(ti_hdc1010), DEVICE_DT_GET_ONE(nxp_mma8652fc), DEVICE_DT_GET_ONE(avago_apds9960), diff --git a/samples/drivers/dac/src/main.c b/samples/drivers/dac/src/main.c index 491c91114fa..393f2b854ca 100644 --- a/samples/drivers/dac/src/main.c +++ b/samples/drivers/dac/src/main.c @@ -23,7 +23,7 @@ #define DAC_RESOLUTION 0 #endif -static const struct device *dac_dev = DEVICE_DT_GET(DAC_NODE); +static const struct device *const dac_dev = DEVICE_DT_GET(DAC_NODE); static const struct dac_channel_cfg dac_ch_cfg = { .channel_id = DAC_CHANNEL_ID, diff --git a/samples/drivers/led_lpd8806/src/main.c b/samples/drivers/led_lpd8806/src/main.c index 285c79ec7ea..6f97d3caa4c 100644 --- a/samples/drivers/led_lpd8806/src/main.c +++ b/samples/drivers/led_lpd8806/src/main.c @@ -38,7 +38,7 @@ static const struct led_rgb black = { struct led_rgb strip_colors[STRIP_NUM_LEDS]; -static const struct device *strip = DEVICE_DT_GET_ANY(greeled_lpd8806); +static const struct device *const strip = DEVICE_DT_GET_ANY(greeled_lpd8806); const struct led_rgb *color_at(size_t time, size_t i) { diff --git a/samples/drivers/led_ws2812/src/main.c b/samples/drivers/led_ws2812/src/main.c index fea560a3d7f..0b1859e42e9 100644 --- a/samples/drivers/led_ws2812/src/main.c +++ b/samples/drivers/led_ws2812/src/main.c @@ -33,7 +33,7 @@ static const struct led_rgb colors[] = { struct led_rgb pixels[STRIP_NUM_PIXELS]; -static const struct device *strip = DEVICE_DT_GET(STRIP_NODE); +static const struct device *const strip = DEVICE_DT_GET(STRIP_NODE); void main(void) { diff --git a/samples/drivers/uart/echo_bot/src/main.c b/samples/drivers/uart/echo_bot/src/main.c index e4156d9e8b0..6b4384b3644 100644 --- a/samples/drivers/uart/echo_bot/src/main.c +++ b/samples/drivers/uart/echo_bot/src/main.c @@ -18,7 +18,7 @@ /* queue to store up to 10 messages (aligned to 4-byte boundary) */ K_MSGQ_DEFINE(uart_msgq, MSG_SIZE, 10, 4); -static const struct device *uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE); +static const struct device *const uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE); /* receive buffer used in UART ISR callback */ static char rx_buf[MSG_SIZE]; diff --git a/samples/sensor/accel_polling/src/main.c b/samples/sensor/accel_polling/src/main.c index 902d40738c7..c94e4d509f5 100644 --- a/samples/sensor/accel_polling/src/main.c +++ b/samples/sensor/accel_polling/src/main.c @@ -17,7 +17,7 @@ IF_ENABLED(DT_NODE_EXISTS(ACCEL_ALIAS(i)), (DEVICE_DT_GET(ACCEL_ALIAS(i)),)) /* support up to 10 accelerometer sensors */ -static const struct device *sensors[] = {LISTIFY(10, ACCELEROMETER_DEVICE, ())}; +static const struct device *const sensors[] = {LISTIFY(10, ACCELEROMETER_DEVICE, ())}; static const enum sensor_channel channels[] = { SENSOR_CHAN_ACCEL_X, diff --git a/samples/shields/x_nucleo_53l0a1/src/display_7seg.c b/samples/shields/x_nucleo_53l0a1/src/display_7seg.c index d812fccf980..e93b6b0073b 100644 --- a/samples/shields/x_nucleo_53l0a1/src/display_7seg.c +++ b/samples/shields/x_nucleo_53l0a1/src/display_7seg.c @@ -13,8 +13,8 @@ const uint8_t DISPLAY_OFF[4] = { CHAR_OFF, CHAR_OFF, CHAR_OFF, CHAR_OFF }; const uint8_t TEXT_Err[4] = { CHAR_E, CHAR_r, CHAR_r, CHAR_OFF }; static bool initialized; -static const struct device *expander1 = DEVICE_DT_GET(DT_NODELABEL(expander1)); -static const struct device *expander2 = DEVICE_DT_GET(DT_NODELABEL(expander2)); +static const struct device *const expander1 = DEVICE_DT_GET(DT_NODELABEL(expander1)); +static const struct device *const expander2 = DEVICE_DT_GET(DT_NODELABEL(expander2)); static const uint8_t digits[16] = { CHAR_0, CHAR_1, diff --git a/samples/shields/x_nucleo_53l0a1/src/main.c b/samples/shields/x_nucleo_53l0a1/src/main.c index e16d7c65b6a..ccb9f6054fe 100644 --- a/samples/shields/x_nucleo_53l0a1/src/main.c +++ b/samples/shields/x_nucleo_53l0a1/src/main.c @@ -29,7 +29,7 @@ typedef void (*fsm_state)(void); static int64_t last_mode_change; -static const struct device *sensors[] = { +static const struct device *const sensors[] = { DEVICE_DT_GET(DT_NODELABEL(vl53l0x_l)), DEVICE_DT_GET(DT_NODELABEL(vl53l0x_c)), DEVICE_DT_GET(DT_NODELABEL(vl53l0x_r)), diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index 7cb2679194a..10de30c50d3 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -59,7 +59,7 @@ static struct { } event; /* Entropy device */ -static const struct device *dev_entropy = DEVICE_DT_GET(DT_NODELABEL(rng)); +static const struct device *const dev_entropy = DEVICE_DT_GET(DT_NODELABEL(rng)); static int init_reset(void); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll.c b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll.c index c83a9048ae2..1d382f2354f 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll.c @@ -52,7 +52,7 @@ static struct { } event; /* Entropy device */ -static const struct device *dev_entropy = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); +static const struct device *const dev_entropy = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); static int init_reset(void); #if defined(CONFIG_BT_CTLR_LOW_LAT_ULL_DONE) diff --git a/subsys/shell/modules/device_service.c b/subsys/shell/modules/device_service.c index feaf79e7e3c..8f0525c88a6 100644 --- a/subsys/shell/modules/device_service.c +++ b/subsys/shell/modules/device_service.c @@ -23,7 +23,7 @@ extern const struct device __device_end[]; extern const struct device __device_SMP_start[]; #endif -static const struct device *levels[] = { +static const struct device *const levels[] = { __device_PRE_KERNEL_1_start, __device_PRE_KERNEL_2_start, __device_POST_KERNEL_start, diff --git a/subsys/testsuite/busy_sim/busy_sim.c b/subsys/testsuite/busy_sim/busy_sim.c index 314e41ef27e..6b8b6109c34 100644 --- a/subsys/testsuite/busy_sim/busy_sim.c +++ b/subsys/testsuite/busy_sim/busy_sim.c @@ -46,7 +46,7 @@ static const struct busy_sim_config sim_config = { }; static struct busy_sim_data sim_data; -static const struct device *busy_sim_dev = DEVICE_DT_GET_ONE(vnd_busy_sim); +static const struct device *const busy_sim_dev = DEVICE_DT_GET_ONE(vnd_busy_sim); static void rng_pool_work_handler(struct k_work *work) { diff --git a/tests/boards/espressif_esp32/cache_coex/src/cache_coex.c b/tests/boards/espressif_esp32/cache_coex/src/cache_coex.c index afdaa81c147..82580266973 100644 --- a/tests/boards/espressif_esp32/cache_coex/src/cache_coex.c +++ b/tests/boards/espressif_esp32/cache_coex/src/cache_coex.c @@ -25,7 +25,7 @@ #define STACKSIZE 1024 #define PRIORITY 7 -static const struct device *flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); +static const struct device *const flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); static struct flash_pages_info page_info; static int *mem; uint8_t flash_fill_buff[FLASH_READBACK_LEN]; diff --git a/tests/boards/frdm_k64f/i2c/src/i2c.c b/tests/boards/frdm_k64f/i2c/src/i2c.c index 291750b7be1..b128eb5330f 100644 --- a/tests/boards/frdm_k64f/i2c/src/i2c.c +++ b/tests/boards/frdm_k64f/i2c/src/i2c.c @@ -25,7 +25,7 @@ #define FXOS8700_CTRLREG2_RST_MASK 0x40 -static const struct device *i2c_bus = DEVICE_DT_GET(DT_NODELABEL(i2c0)); +static const struct device *const i2c_bus = DEVICE_DT_GET(DT_NODELABEL(i2c0)); /** * Setup and enable the fxos8700 with its max sample rate and diff --git a/tests/drivers/can/canfd/src/main.c b/tests/drivers/can/canfd/src/main.c index ded3e36127f..3a08445323b 100644 --- a/tests/drivers/can/canfd/src/main.c +++ b/tests/drivers/can/canfd/src/main.c @@ -31,7 +31,7 @@ /** * @brief Global variables. */ -static const struct device *can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus)); +static const struct device *const can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus)); static struct k_sem rx_callback_sem; static struct k_sem tx_callback_sem; diff --git a/tests/drivers/clock_control/nrf_onoff_and_bt/src/main.c b/tests/drivers/clock_control/nrf_onoff_and_bt/src/main.c index 1dd83c2b015..bcadac8f62f 100644 --- a/tests/drivers/clock_control/nrf_onoff_and_bt/src/main.c +++ b/tests/drivers/clock_control/nrf_onoff_and_bt/src/main.c @@ -20,7 +20,7 @@ static bool test_end; #include -static const struct device *entropy = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); +static const struct device *const entropy = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy)); static struct onoff_manager *hf_mgr; static uint32_t iteration; diff --git a/tests/drivers/counter/counter_basic_api/src/test_counter.c b/tests/drivers/counter/counter_basic_api/src/test_counter.c index 4152383e674..ecbee61c1b3 100644 --- a/tests/drivers/counter/counter_basic_api/src/test_counter.c +++ b/tests/drivers/counter/counter_basic_api/src/test_counter.c @@ -27,7 +27,7 @@ struct counter_alarm_cfg alarm_cfg2; #define DEVS_FOR_DT_COMPAT(compat) \ DT_FOREACH_STATUS_OKAY(compat, DEVICE_DT_GET_AND_COMMA) -static const struct device *devices[] = { +static const struct device *const devices[] = { #ifdef CONFIG_COUNTER_TIMER0 /* Nordic TIMER0 may be reserved for Bluetooth */ DEVICE_DT_GET(DT_NODELABEL(timer0)), @@ -93,7 +93,7 @@ static const struct device *devices[] = { #endif }; -static const struct device *period_devs[] = { +static const struct device *const period_devs[] = { #ifdef CONFIG_COUNTER_MCUX_RTC DEVS_FOR_DT_COMPAT(nxp_kinetis_rtc) #endif diff --git a/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c b/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c index df159a83e6b..a9f951ed713 100644 --- a/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c +++ b/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c @@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(test); static volatile uint32_t top_cnt; -static const struct device *devices[] = { +static const struct device *const devices[] = { #ifdef CONFIG_COUNTER_RTC0 /* Nordic RTC0 may be reserved for Bluetooth */ DEVICE_DT_GET(DT_NODELABEL(rtc0)), diff --git a/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c b/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c index 942c45812f0..ccacfabdc74 100644 --- a/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c +++ b/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c @@ -24,7 +24,7 @@ void *exp_user_data = (void *)199; struct counter_alarm_cfg alarm_cfg; struct counter_alarm_cfg alarm_cfg2; -static const struct device *devices[] = { +static const struct device *const devices[] = { DEVICE_DT_GET(DT_NODELABEL(ds3231)), }; typedef void (*counter_test_func_t)(const struct device *dev); diff --git a/tests/drivers/flash/src/main.c b/tests/drivers/flash/src/main.c index a237c7a190c..e8725421e46 100644 --- a/tests/drivers/flash/src/main.c +++ b/tests/drivers/flash/src/main.c @@ -47,7 +47,7 @@ #define EXPECTED_SIZE 256 #define CANARY 0xff -static const struct device *flash_dev = TEST_AREA_DEVICE; +static const struct device *const flash_dev = TEST_AREA_DEVICE; static struct flash_pages_info page_info; static uint8_t __aligned(4) expected[EXPECTED_SIZE]; diff --git a/tests/drivers/flash_simulator/src/main.c b/tests/drivers/flash_simulator/src/main.c index 820237b8788..347da759df1 100644 --- a/tests/drivers/flash_simulator/src/main.c +++ b/tests/drivers/flash_simulator/src/main.c @@ -32,7 +32,7 @@ (((((((0xff & pat) << 8) | (0xff & pat)) << 8) | \ (0xff & pat)) << 8) | (0xff & pat)) -static const struct device *flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); +static const struct device *const flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); static uint8_t test_read_buf[TEST_SIM_FLASH_SIZE]; static uint32_t p32_inc; diff --git a/tests/drivers/mipi_dsi/api/src/main.c b/tests/drivers/mipi_dsi/api/src/main.c index 8c5a355509b..d8cfbe08b99 100644 --- a/tests/drivers/mipi_dsi/api/src/main.c +++ b/tests/drivers/mipi_dsi/api/src/main.c @@ -14,7 +14,7 @@ * @} */ -static const struct device *mipi_dev = DEVICE_DT_GET(DT_ALIAS(mipi_dsi)); +static const struct device *const mipi_dev = DEVICE_DT_GET(DT_ALIAS(mipi_dsi)); /** * Test the MIPI generic APIs to test read and write API functionality diff --git a/tests/drivers/regulator/fixed/src/main.c b/tests/drivers/regulator/fixed/src/main.c index 4a9432fa69c..2fea0666ff2 100644 --- a/tests/drivers/regulator/fixed/src/main.c +++ b/tests/drivers/regulator/fixed/src/main.c @@ -23,7 +23,7 @@ BUILD_ASSERT(DT_NODE_HAS_COMPAT_STATUS(CHECK_NODE, test_regulator_fixed, okay)); static const struct gpio_dt_spec reg_gpio = GPIO_DT_SPEC_GET(REGULATOR_NODE, enable_gpios); static const struct gpio_dt_spec check_gpio = GPIO_DT_SPEC_GET(CHECK_NODE, check_gpios); -static const struct device *reg_dev = DEVICE_DT_GET(REGULATOR_NODE); +static const struct device *const reg_dev = DEVICE_DT_GET(REGULATOR_NODE); static enum { PC_UNCHECKED, diff --git a/tests/drivers/sdhc/src/main.c b/tests/drivers/sdhc/src/main.c index 8371cc48198..e654db8f53b 100644 --- a/tests/drivers/sdhc/src/main.c +++ b/tests/drivers/sdhc/src/main.c @@ -9,7 +9,7 @@ #include #include -static const struct device *sdhc_dev = DEVICE_DT_GET(DT_ALIAS(sdhc0)); +static const struct device *const sdhc_dev = DEVICE_DT_GET(DT_ALIAS(sdhc0)); static struct sdhc_host_props props; static struct sdhc_io io; diff --git a/tests/subsys/fs/nvs/src/main.c b/tests/subsys/fs/nvs/src/main.c index dcf61f752a1..bacc99df0ce 100644 --- a/tests/subsys/fs/nvs/src/main.c +++ b/tests/subsys/fs/nvs/src/main.c @@ -33,7 +33,7 @@ #define TEST_DATA_ID 1 #define TEST_SECTOR_COUNT 5U -static const struct device *flash_dev = DEVICE_DT_GET(TEST_NVS_FLASH_DEV_NODE); +static const struct device *const flash_dev = DEVICE_DT_GET(TEST_NVS_FLASH_DEV_NODE); struct nvs_fixture { struct nvs_fs fs; diff --git a/tests/subsys/openthread/radio_test.c b/tests/subsys/openthread/radio_test.c index 2c984cd808a..3edbe55e394 100644 --- a/tests/subsys/openthread/radio_test.c +++ b/tests/subsys/openthread/radio_test.c @@ -83,7 +83,7 @@ static int init_mock(const struct device *dev) #define DT_DRV_COMPAT vnd_ieee802154 DEVICE_DT_INST_DEFINE(0, init_mock, NULL, NULL, NULL, POST_KERNEL, 0, &rapi); -static const struct device *radio = DEVICE_DT_INST_GET(0); +static const struct device *const radio = DEVICE_DT_INST_GET(0); static int16_t rssi_scan_mock_max_ed; static int rssi_scan_mock(const struct device *dev, uint16_t duration, diff --git a/tests/subsys/sd/sdmmc/src/main.c b/tests/subsys/sd/sdmmc/src/main.c index 0b502568104..d6464870a70 100644 --- a/tests/subsys/sd/sdmmc/src/main.c +++ b/tests/subsys/sd/sdmmc/src/main.c @@ -14,7 +14,7 @@ #define SECTOR_COUNT 32 #define SECTOR_SIZE 512 /* subsystem should set all cards to 512 byte blocks */ #define BUF_SIZE SECTOR_SIZE * SECTOR_COUNT -static const struct device *sdhc_dev = DEVICE_DT_GET(DT_ALIAS(sdhc0)); +static const struct device *const sdhc_dev = DEVICE_DT_GET(DT_ALIAS(sdhc0)); static struct sd_card card; static uint8_t buf[BUF_SIZE] __aligned(CONFIG_SDHC_BUFFER_ALIGNMENT); static uint8_t check_buf[BUF_SIZE] __aligned(CONFIG_SDHC_BUFFER_ALIGNMENT); diff --git a/tests/subsys/storage/stream/stream_flash/src/main.c b/tests/subsys/storage/stream/stream_flash/src/main.c index 968b3eaded9..379b8f19ac2 100644 --- a/tests/subsys/storage/stream/stream_flash/src/main.c +++ b/tests/subsys/storage/stream/stream_flash/src/main.c @@ -24,7 +24,7 @@ #define FLASH_BASE (128*1024) #define FLASH_AVAILABLE (FLASH_SIZE-FLASH_BASE) -static const struct device *fdev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); +static const struct device *const fdev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); static const struct flash_driver_api *api; static const struct flash_pages_layout *layout; static size_t layout_size;