All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iio: temperature: maxim_thermocouple: Fix sparse endianness warnings
@ 2016-09-26 17:14 sayli karnik
  2016-09-27  6:05 ` [Outreachy kernel] " Alison Schofield
  0 siblings, 1 reply; 6+ messages in thread
From: sayli karnik @ 2016-09-26 17:14 UTC (permalink / raw)
  To: outreachy-kernel
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler

Fix following endianness warnings using sparse:
warning: cast to restricted __be16
warning: cast to restricted __be32
Use __be16 type for incoming read data when storage_bytes equals 2 and __be32
when storage_bytes equals 4. Since the variable allocated already has the
correct storage size the patch is classified as cosmetic.

Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
---
v2:
Updated the subject line and changelog
Moved the spi_read function call inside respective case statements so that data
is read only once.
Moved the return statement after the switch case

 drivers/iio/temperature/maxim_thermocouple.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index 39dd202..2683b0f 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -123,22 +123,24 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
 {
 	unsigned int storage_bytes = data->chip->read_size;
 	unsigned int shift = chan->scan_type.shift + (chan->address * 8);
-	unsigned int buf;
+	__be16 buf1;
+	__be32 buf2;
 	int ret;
 
-	ret = spi_read(data->spi, (void *) &buf, storage_bytes);
-	if (ret)
-		return ret;
-
 	switch (storage_bytes) {
 	case 2:
-		*val = be16_to_cpu(buf);
+		ret = spi_read(data->spi, (void *) &buf1, storage_bytes);
+		*val = be16_to_cpu(buf1);
 		break;
 	case 4:
-		*val = be32_to_cpu(buf);
+		ret = spi_read(data->spi, (void *) &buf2, storage_bytes);
+		*val = be32_to_cpu(buf2);
 		break;
 	}
 
+	if (ret)
+		return ret;
+
 	/* check to be sure this is a valid reading */
 	if (*val & data->chip->status_bit)
 		return -EINVAL;
-- 
2.7.4



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

end of thread, other threads:[~2016-09-27 16:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-26 17:14 [PATCH v2] iio: temperature: maxim_thermocouple: Fix sparse endianness warnings sayli karnik
2016-09-27  6:05 ` [Outreachy kernel] " Alison Schofield
2016-09-27  8:07   ` Lars-Peter Clausen
2016-09-27 15:05   ` sayli karnik
2016-09-27 16:20     ` Julia Lawall
2016-09-27 16:25     ` Alison Schofield

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.