提交 f890987f 编写于 作者: W Wilfried Wessner 提交者: Jonathan Cameron

iio: adc: ad7949: fix wrong ADC result due to incorrect bit mask

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: 7f40e061 ("iio:adc:ad7949: Add AD7949 ADC driver family")
Signed-off-by: NWilfried Wessner <wilfried.wessner@gmail.com>
Reviewed-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: NCharles-Antoine Couret <charles-antoine.couret@essensium.com>
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210208142705.GA51260@ubuntuSigned-off-by: NJonathan Cameron <Jonathan.Cameron@huawei.com>
上级 d68c592e
...@@ -91,7 +91,7 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, ...@@ -91,7 +91,7 @@ static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val,
int ret; int ret;
int i; int i;
int bits_per_word = ad7949_adc->resolution; 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_message msg;
struct spi_transfer tx[] = { struct spi_transfer tx[] = {
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册