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 <affrin.pinhero@hcl.com>
This commit is contained in:
Affrin Pinhero 2021-05-24 20:26:06 +05:30 committed by Kumar Gala
parent 12c80eba71
commit 2c61c06a0e

View file

@ -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);
}