Skip to contentSkip to conversation

drivers: fixes wrong ADC result due to incorrect bit mask of ad7949 driver

PATCH New Wilfried Wessner 1 participant 1 message Feb 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: fixes wrong ADC result due to incorrect bit mask of ad7949 driver

Fixes a wrong bit mask used for the ADC's result, which was caused by an improper usage of the GENMASK macro. The bits higher than ADC's resolution are undefined and if not masked out correctly, a wrong result can be given. The GENMASK macro indexing is zero based, so the mask has to go from [resolution -1 , 0].

---
 drivers/iio/adc/ad7949.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7949.c +1 -1
index 5d597e5050f6..a5b4858cb6dc 100644
@@ -91,7 +91,7 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val,
 	int ret;
 	int i;
 	int bits_per_word = ad7949_adc->resolution;
-	int mask = GENMASK(ad7949_adc->resolution, 0);
+	int mask = GENMASK((ad7949_adc->resolution-1), 0);
 	struct spi_message msg;
 	struct spi_transfer tx[] = {
 		{
Signature · 1 line
2.25.1