drivers: sensor: 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:04:53 +02:00 committed by Carles Cufí
parent 9c1833b2e8
commit 78dd25e79e
1 changed files with 5 additions and 0 deletions

View File

@ -314,6 +314,11 @@ static int tach_npcx_init(const struct device *dev)
const struct device *const clk_dev = DEVICE_DT_GET(NPCX_CLK_CTRL_NODE);
int ret;
if (!device_is_ready(clk_dev)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
/* Turn on device clock first and get source clock freq. */
ret = clock_control_on(clk_dev, (clock_control_subsys_t *)
&config->clk_cfg);