drivers: usb-c: fix - check if adc_channel is ready before use

This will protect a user of this driver against driver initialisation
order misconfiguration.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
This commit is contained in:
Nick Ward 2023-07-16 22:12:34 +10:00 committed by Fabio Baltieri
commit 2bf091f8af

View file

@ -139,6 +139,11 @@ static int adc_vbus_init(const struct device *dev)
const struct gpio_dt_spec *gcd = &config->discharge_gpios;
int ret;
if (!adc_is_ready_dt(&config->adc_channel)) {
LOG_ERR("ADC controller device is not ready");
return -ENODEV;
}
/* Configure VBUS Measurement enable pin if defined */
if (gcp->port) {
ret = device_is_ready(gcp->port);