Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad4000: fix reading unsigned data
@ 2024-10-30 21:09 David Lechner
  2024-10-31 21:42 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: David Lechner @ 2024-10-30 21:09 UTC (permalink / raw)
  To: Marcelo Schmitt, Jonathan Cameron
  Cc: Michael Hennerich, Nuno Sa, linux-iio, linux-kernel,
	David Lechner

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")
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
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(+)

diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c
index 6ea491245084..fc9c9807f89d 100644
--- a/drivers/iio/adc/ad4000.c
+++ b/drivers/iio/adc/ad4000.c
@@ -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,
-- 
David Lechner <dlechner@baylibre.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-31 21:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30 21:09 [PATCH] iio: adc: ad4000: fix reading unsigned data David Lechner
2024-10-31 21:42 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox