linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: at91-sama5d2_adc: fix up casting in at91_adc_read_info_raw()
@ 2018-07-09 11:06 Dan Carpenter
  2018-07-09 11:22 ` Eugen Hristev
  2018-07-17  8:12 ` Ludovic Desroches
  0 siblings, 2 replies; 7+ messages in thread
From: Dan Carpenter @ 2018-07-09 11:06 UTC (permalink / raw)
  To: Ludovic Desroches, Eugen Hristev
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Nicolas Ferre, Alexandre Belloni,
	linux-iio, kernel-janitors

This code is problematic because we're supposed to be writing an int but
we instead write to only the high 16 bits.  This doesn't work on big
endian systems, and there is a potential that the bottom 16 bits are
used without being initialized.

Fixes: 23ec2774f1cc ("iio: adc: at91-sama5d2_adc: add support for position and pressure channels")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index e02f7d1c86bc..d5ea84cf6460 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -1296,6 +1296,7 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
 {
 	struct at91_adc_state *st = iio_priv(indio_dev);
 	u32 cor = 0;
+	u16 tmp_val;
 	int ret;
 
 	/*
@@ -1309,7 +1310,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
 		mutex_lock(&st->lock);
 
 		ret = at91_adc_read_position(st, chan->channel,
-					     (u16 *)val);
+					     &tmp_val);
+		*val = tmp_val;
 		mutex_unlock(&st->lock);
 		iio_device_release_direct_mode(indio_dev);
 
@@ -1322,7 +1324,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev,
 		mutex_lock(&st->lock);
 
 		ret = at91_adc_read_pressure(st, chan->channel,
-					     (u16 *)val);
+					     &tmp_val);
+		*val = tmp_val;
 		mutex_unlock(&st->lock);
 		iio_device_release_direct_mode(indio_dev);
 

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

end of thread, other threads:[~2018-07-21 19:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-09 11:06 [PATCH] iio: adc: at91-sama5d2_adc: fix up casting in at91_adc_read_info_raw() Dan Carpenter
2018-07-09 11:22 ` Eugen Hristev
2018-07-09 11:41   ` Dan Carpenter
2018-07-15  8:15     ` Jonathan Cameron
2018-07-16 13:46       ` Eugen Hristev
2018-07-17  8:12 ` Ludovic Desroches
2018-07-21 18:07   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).