From 2c61c06a0e475cd69da854012436903f57c7c950 Mon Sep 17 00:00:00 2001 From: Affrin Pinhero Date: Mon, 24 May 2021 20:26:06 +0530 Subject: [PATCH] drivers/ADC: STM32: This solves coverity reported in ADC driver. This commit it to resolve following bugs: * Operands don't affect result. * Logical dead code in stm32_adc driver. Above mentioned bugs were solved by adding parenthesis and changed the method of comparing. Since comparison of ADC channel_id with the channel may cause loss of value. So instead of direct comparison, introduced a mechanism to convert channel constant to a decimal using __LL_ADC_CHANNEL_TO_DECIMAL_NB() and strips away the INTERNAL_CH bit and then compare with channel_id. fix: * zephyrproject-rtos/zephyr#35130 * zephyrproject-rtos/zephyr#35136 Signed-off-by: Affrin Pinhero --- drivers/adc/adc_stm32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index 5431037873..878466c261 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -567,8 +567,8 @@ static int adc_stm32_channel_setup(const struct device *dev, return -EINVAL; } - if (channel_cfg->channel_id == ADC_CHANNEL_TEMPSENSOR || - channel_cfg->channel_id == ADC_CHANNEL_VREFINT) { + if ((__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_cfg->channel_id) || + (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_cfg->channel_id)) { adc_stm32_set_common_path(dev); }