Skip to content

Commit

Permalink
iio: at91-sama5d2: Fix incorrect sign extension
Browse files Browse the repository at this point in the history
Use scan_type when processing raw data which also fixes that the sign
extension was from the wrong bit.

Use channel definition as root of trust and replace constant
when reading elements directly using the raw sysfs attributes.

Fixes: 6794e23 ("iio: adc: at91-sama5d2_adc: add support for oversampling resolution")
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Eugen Hristev <eugen.hristev@microchip.com>
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20211104082413.3681212-9-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
Gwendal Grignou authored and Jonathan Cameron committed Nov 21, 2021
1 parent 92beafb commit 652e7df
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/iio/adc/at91-sama5d2_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
*val = st->conversion_value;
ret = at91_adc_adjust_val_osr(st, val);
if (chan->scan_type.sign == 's')
*val = sign_extend32(*val, 11);
*val = sign_extend32(*val,
chan->scan_type.realbits - 1);
st->conversion_done = false;
}

Expand Down

0 comments on commit 652e7df

Please sign in to comment.