Skip to contentSkip to conversation

iio: adc: ad4000: fix reading unsigned data

PATCH Applied David Lechner 2 participants 2 messages Oct 30, 2024 – Oct 31, 2024

Subsystems (3)
lore
Share & tools
lore

David Lechner

author reviewer
#0 lore raw

PATCH 1/1 iio: adc: ad4000: fix reading unsigned data

Fix reading unsigned data from the AD4000 ADC via the _raw sysfs attribute by ensuring that *val is set before returning from ad4000_single_conversion(). This was not being set in any code path and was causing the attribute to return a random value.

Fixes 938fd562b974 ("iio: adc: Add support for AD4000")

---
FYI, there is also another unrelated bug I noticed but didn't fix.

We are calling iio_push_to_buffers_with_timestamp() but there isn't actually a IIO_CHAN_SOFT_TIMESTAMP() channel. I assume the intention was to have the timestamp channel?

---
 drivers/iio/adc/ad4000.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/adc/ad4000.c +2 -0
index 6ea491245084..fc9c9807f89d 100644
@@ -344,6 +344,8 @@ static int ad4000_single_conversion(struct iio_dev *indio_dev,
 
 	if (chan->scan_type.sign == 's')
 		*val = sign_extend32(sample, chan->scan_type.realbits - 1);
+	else
+		*val = sample;
 
 	return IIO_VAL_INT;
 }

---
base-commit: fa4076314480bcb2bb32051027735b1cde07eea2
change-id: 20241030-iio-adc-ad4000-fix-reading-unsigned-data-88a1de88cf57

Best regards,

Signature · 1 line
David Lechner <[email protected]>
maintainer Applied
#1 lore raw
Quoted 7 lines · On Wed, 30 Oct 2024 16:09:41 -0500 David Lechner <[email protected]> wrote:

Fix reading unsigned data from the AD4000 ADC via the _raw sysfs attribute by ensuring that *val is set before returning from ad4000_single_conversion(). This was not being set in any code path and was causing the attribute to return a random value.

Fixes 938fd562b974 ("iio: adc: Add support for AD4000")

Applied.

Quoted 6 lines

---
FYI, there is also another unrelated bug I noticed but didn't fix.

We are calling iio_push_to_buffers_with_timestamp() but there isn't actually a IIO_CHAN_SOFT_TIMESTAMP() channel. I assume the intention was to have the timestamp channel?

Technically harmless as it can never be turned on, but indeed seems doubtful - maybe something to treat as a feature rather than a fix though given it was never there.

Quoted 23 lines
---
 drivers/iio/adc/ad4000.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/adc/ad4000.c +2 -1
index 6ea491245084..fc9c9807f89d 100644
@@ -344,6 +344,8 @@ static int ad4000_single_conversion(struct iio_dev *indio_dev,
 
 	if (chan->scan_type.sign == 's')
 		*val = sign_extend32(sample, chan->scan_type.realbits - 1);
+	else
+		*val = sample;
 
 	return IIO_VAL_INT;
 }
 
---

base-commit: fa4076314480bcb2bb32051027735b1cde07eea2
change-id: 20241030-iio-adc-ad4000-fix-reading-unsigned-data-88a1de88cf57

Best regards,