drivers: counter: 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:
parent
035c7d2190
commit
e885ead428
5 changed files with 24 additions and 1 deletions
|
@ -282,6 +282,11 @@ static int rtc_stm32_init(const struct device *dev)
|
|||
|
||||
data->callback = NULL;
|
||||
|
||||
if (!device_is_ready(clk)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (clock_control_on(clk, (clock_control_subsys_t *) &cfg->pclken) != 0) {
|
||||
LOG_ERR("clock op failed\n");
|
||||
return -EIO;
|
||||
|
|
|
@ -354,6 +354,10 @@ static int counter_stm32_get_tim_clk(const struct stm32_pclken *pclken, uint32_t
|
|||
|
||||
clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
||||
|
||||
if (!device_is_ready(clk)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
r = clock_control_get_rate(clk, (clock_control_subsys_t *)pclken,
|
||||
&bus_clk);
|
||||
if (r < 0) {
|
||||
|
|
|
@ -250,9 +250,13 @@ static int mcux_lpc_ctimer_init(const struct device *dev)
|
|||
{
|
||||
const struct mcux_lpc_ctimer_config *config = dev->config;
|
||||
struct mcux_lpc_ctimer_data *data = dev->data;
|
||||
|
||||
ctimer_config_t ctimer_config;
|
||||
|
||||
if (!device_is_ready(config->clock_dev)) {
|
||||
LOG_ERR("clock control device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
for (uint8_t chan = 0; chan < NUM_CHANNELS; chan++) {
|
||||
data->channels[chan].alarm_callback = NULL;
|
||||
data->channels[chan].alarm_user_data = NULL;
|
||||
|
|
|
@ -168,6 +168,11 @@ static int mcux_gpt_init(const struct device *dev)
|
|||
gpt_config_t gptConfig;
|
||||
uint32_t clock_freq;
|
||||
|
||||
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;
|
||||
|
|
|
@ -267,6 +267,11 @@ static int mcux_qtmr_init(const struct device *dev)
|
|||
data->freq = config->info.freq;
|
||||
} else {
|
||||
/* bus clock with divider */
|
||||
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,
|
||||
&data->freq)) {
|
||||
return -EINVAL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue