Skip to content

Commit 2c61c06

Browse files
affrinpinhero-2356galak
authored andcommitted
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: * #35130 * #35136 Signed-off-by: Affrin Pinhero <[email protected]>
1 parent 12c80eb commit 2c61c06

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/adc/adc_stm32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ static int adc_stm32_channel_setup(const struct device *dev,
567567
return -EINVAL;
568568
}
569569

570-
if (channel_cfg->channel_id == ADC_CHANNEL_TEMPSENSOR ||
571-
channel_cfg->channel_id == ADC_CHANNEL_VREFINT) {
570+
if ((__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_cfg->channel_id) ||
571+
(__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_cfg->channel_id)) {
572572
adc_stm32_set_common_path(dev);
573573
}
574574

0 commit comments

Comments
 (0)