Commit 5999ec53f60b270adf0a59edb63043fe60bc3464

Authored by Peter Meerwald
Committed by Greg Kroah-Hartman
1 parent 9ab8ee47dd

iio: Fix two mpl3115 issues in measurement conversion

commit d29f592929489d0a7c414396fae28119f3d280e1 upstream.

(i) pressure is 20-bit unsigned, not signed; the buffer description
is incorrect; for raw reads, this is just cosmetic

(ii) temperature is 12-bit signed, not 16-bit; this affects
readout of temperatures below zero as the sign bit is incorrectly
processed

reported via private mail

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Reported-by: Robert Deliën <robert@delien.nl>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 3 additions and 3 deletions Side-by-side Diff

drivers/iio/pressure/mpl3115.c
... ... @@ -98,7 +98,7 @@
98 98 mutex_unlock(&data->lock);
99 99 if (ret < 0)
100 100 return ret;
101   - *val = sign_extend32(be32_to_cpu(tmp) >> 12, 23);
  101 + *val = be32_to_cpu(tmp) >> 12;
102 102 return IIO_VAL_INT;
103 103 case IIO_TEMP: /* in 0.0625 celsius / LSB */
104 104 mutex_lock(&data->lock);
... ... @@ -112,7 +112,7 @@
112 112 mutex_unlock(&data->lock);
113 113 if (ret < 0)
114 114 return ret;
115   - *val = sign_extend32(be32_to_cpu(tmp) >> 20, 15);
  115 + *val = sign_extend32(be32_to_cpu(tmp) >> 20, 11);
116 116 return IIO_VAL_INT;
117 117 default:
118 118 return -EINVAL;
... ... @@ -185,7 +185,7 @@
185 185 BIT(IIO_CHAN_INFO_SCALE),
186 186 .scan_index = 0,
187 187 .scan_type = {
188   - .sign = 's',
  188 + .sign = 'u',
189 189 .realbits = 20,
190 190 .storagebits = 32,
191 191 .shift = 12,