drivers: watchdog: check if clock device is ready before accessing

Add check for device_is_ready() before accessing clock control devices.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2022-08-08 16:06:08 +02:00 committed by Carles Cufí
commit b5a79fa4ad
4 changed files with 20 additions and 0 deletions

View file

@ -153,6 +153,11 @@ static int wdt_esp32_init(const struct device *dev)
const struct wdt_esp32_config *const config = dev->config;
struct wdt_esp32_data *data = dev->data;
if (!device_is_ready(config->clock_dev)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
clock_control_on(config->clock_dev, config->clock_subsys);
wdt_hal_init(&data->hal, config->wdt_inst, MWDT_TICK_PRESCALER, true);

View file

@ -78,6 +78,11 @@ static int mcux_wdog_install_timeout(const struct device *dev,
return -ENOMEM;
}
if (!device_is_ready(config->clock_dev)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
&clock_freq)) {
return -EINVAL;

View file

@ -93,6 +93,11 @@ static int mcux_wdog32_install_timeout(const struct device *dev,
#if DT_NODE_HAS_PROP(DT_INST_PHANDLE(0, clocks), clock_frequency)
clock_freq = config->clock_frequency;
#else /* !DT_NODE_HAS_PROP(DT_INST_PHANDLE(0, clocks), clock_frequency) */
if (!device_is_ready(config->clock_dev)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
if (clock_control_get_rate(config->clock_dev, config->clock_subsys,
&clock_freq)) {
return -EINVAL;

View file

@ -282,6 +282,11 @@ static int wwdg_stm32_init(const struct device *dev)
wwdg_stm32_irq_config(dev);
if (!device_is_ready(clk)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
return clock_control_on(clk, (clock_control_subsys_t *) &cfg->pclken);
}