aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfried Wessner <wilfried.wessner@gmail.com>2021-02-08 15:27:05 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-03-24 11:26:42 +0100
commit4458ae8d4001d9345a83e55389acb7a4ab7bf615 (patch)
tree68179154ce066ccaa106dc2295505fd1291ef4f2
parenta605c095bb463ff9948f4fb7151068c63894fe81 (diff)
downloadlinux-yocto-4458ae8d4001d9345a83e55389acb7a4ab7bf615.tar.gz
linux-yocto-4458ae8d4001d9345a83e55389acb7a4ab7bf615.tar.bz2
linux-yocto-4458ae8d4001d9345a83e55389acb7a4ab7bf615.zip
iio: adc: ad7949: fix wrong ADC result due to incorrect bit mask
commit f890987fac8153227258121740a9609668c427f3 upstream. 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]. Fixes: 7f40e0614317f ("iio:adc:ad7949: Add AD7949 ADC driver family") Signed-off-by: Wilfried Wessner <wilfried.wessner@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Charles-Antoine Couret <charles-antoine.couret@essensium.com> Cc: <Stable@vger.kernel.org> Link: https://lore.kernel.org/r/20210208142705.GA51260@ubuntu Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/iio/adc/ad7949.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/iio/adc/ad7949.c b/drivers/iio/adc/ad7949.c
index 6b51bfcad0d0..325cd7d18b91 100644
--- a/drivers/iio/adc/ad7949.c
+++ b/drivers/iio/adc/ad7949.c
@@ -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[] = {
{