drivers: flash: 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 13:35:10 +02:00 committed by Carles Cufí
commit c1a35b7b39
3 changed files with 15 additions and 0 deletions

View file

@ -358,6 +358,11 @@ static int stm32_flash_init(const struct device *dev)
}
#endif
if (!device_is_ready(clk)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
/* enable clock */
if (clock_control_on(clk, (clock_control_subsys_t *)&p->pclken) != 0) {
LOG_ERR("Failed to enable clock");

View file

@ -1583,6 +1583,11 @@ static int flash_stm32_ospi_init(const struct device *dev)
return ret;
}
if (!device_is_ready(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE))) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
/* Clock configuration */
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken[0]) != 0) {

View file

@ -666,6 +666,11 @@ static int stm32h7_flash_init(const struct device *dev)
struct flash_stm32_priv *p = FLASH_STM32_PRIV(dev);
const struct device *clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
if (!device_is_ready(clk)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
/* enable clock */
if (clock_control_on(clk, (clock_control_subsys_t *)&p->pclken) != 0) {
LOG_ERR("Failed to enable clock");