From 5246cea80047bdbe0794b4dc96e3e0873f5ef984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Barna=C5=9B?= Date: Fri, 29 Sep 2023 16:27:47 +0200 Subject: [PATCH] usbc: improve error handling in the ucpd_stm32 and vbus_adc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As noted in PR#63165 checking of result should use comparison to success value instead of checking if result is negative. It will allow to check if function returned invalid but positive value. Signed-off-by: Michał Barnaś --- drivers/usb_c/tcpc/ucpd_stm32.c | 2 +- drivers/usb_c/vbus/usbc_vbus_adc.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/usb_c/tcpc/ucpd_stm32.c b/drivers/usb_c/tcpc/ucpd_stm32.c index ae007667a10..2fca84346fc 100644 --- a/drivers/usb_c/tcpc/ucpd_stm32.c +++ b/drivers/usb_c/tcpc/ucpd_stm32.c @@ -1366,7 +1366,7 @@ static int ucpd_init(const struct device *dev) LOG_DBG("Pinctrl signals configuration"); ret = pinctrl_apply_state(config->ucpd_pcfg, PINCTRL_STATE_DEFAULT); - if (ret < 0) { + if (ret != 0) { LOG_ERR("USB pinctrl setup failed (%d)", ret); return ret; } diff --git a/drivers/usb_c/vbus/usbc_vbus_adc.c b/drivers/usb_c/vbus/usbc_vbus_adc.c index a1fbe6f3421..1b2d576a3ed 100644 --- a/drivers/usb_c/vbus/usbc_vbus_adc.c +++ b/drivers/usb_c/vbus/usbc_vbus_adc.c @@ -146,13 +146,12 @@ static int adc_vbus_init(const struct device *dev) /* Configure VBUS Measurement enable pin if defined */ if (gcp->port) { - ret = device_is_ready(gcp->port); - if (ret < 0) { + if (!device_is_ready(gcp->port)) { LOG_ERR("%s: device not ready", gcp->port->name); - return ret; + return -EIO; } ret = gpio_pin_configure_dt(gcp, GPIO_OUTPUT_INACTIVE); - if (ret < 0) { + if (ret != 0) { LOG_ERR("Failed to control feed %s.%u: %d", gcp->port->name, gcp->pin, ret); return ret; @@ -161,13 +160,12 @@ static int adc_vbus_init(const struct device *dev) /* Configure VBUS Discharge pin if defined */ if (gcd->port) { - ret = device_is_ready(gcd->port); - if (ret == false) { + if (!device_is_ready(gcd->port)) { LOG_ERR("%s: device not ready", gcd->port->name); - return ret; + return -EIO; } ret = gpio_pin_configure_dt(gcd, GPIO_OUTPUT_INACTIVE); - if (ret < 0) { + if (ret != 0) { LOG_ERR("Failed to control feed %s.%u: %d", gcd->port->name, gcd->pin, ret); return ret; @@ -179,13 +177,13 @@ static int adc_vbus_init(const struct device *dev) data->sequence.buffer_size = sizeof(data->sample); ret = adc_channel_setup_dt(&config->adc_channel); - if (ret < 0) { + if (ret != 0) { LOG_INF("Could not setup channel (%d)\n", ret); return ret; } ret = adc_sequence_init_dt(&config->adc_channel, &data->sequence); - if (ret < 0) { + if (ret != 0) { LOG_INF("Could not init sequence (%d)\n", ret); return ret; }