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

Fix following endianness warnings:
warning: cast to restricted __be16
warning: cast to restricted __be32

Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
---
 drivers/iio/temperature/maxim_thermocouple.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index 39dd202..3e99056 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -123,19 +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);
+	ret = spi_read(data->spi, (void *) &buf1, storage_bytes);
+	if (ret)
+		return ret;
+
+	ret = spi_read(data->spi, (void *) &buf2, storage_bytes);
 	if (ret)
 		return ret;
 
 	switch (storage_bytes) {
 	case 2:
-		*val = be16_to_cpu(buf);
+		*val = be16_to_cpu(buf1);
 		break;
 	case 4:
-		*val = be32_to_cpu(buf);
+		*val = be32_to_cpu(buf2);
 		break;
 	}
 
-- 
2.7.4



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

* Re: [Outreachy kernel] [PATCH] drivers: iio: temperature: Fix sparse endianness warnings
  2016-09-25 21:55 [PATCH] drivers: iio: temperature: Fix sparse endianness warnings sayli karnik
@ 2016-09-26  3:26 ` Alison Schofield
  0 siblings, 0 replies; 2+ messages in thread
From: Alison Schofield @ 2016-09-26  3:26 UTC (permalink / raw)
  To: sayli karnik
  Cc: outreachy-kernel, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler

On Mon, Sep 26, 2016 at 03:25:30AM +0530, sayli karnik wrote:
> Fix following endianness warnings:
> warning: cast to restricted __be16
> warning: cast to restricted __be32
> 
> Signed-off-by: sayli karnik <karniksayli1995@gmail.com>

Hi Sayli - Thanks for picking up one of these Endianess issues!

Please take another look at what the function was trying to do before
your patch.  Although the definition of 2 bufs may be part of the
solution, 2 reads won't be.  

The solution may be what you have started: define 2 different size bufs
based on the storage_bytes but you'll need to then move the reads into
the appropriate case statement. Maybe you'll come up with another
option.

In v2 - please also:
- path is: iio: temperature: maxim_thermocouple: 
- commit msg needs to be something like: use __be16 type for incoming read data
  (say what you end up changing....in a nutshell ;))
- see Lar's msg http://marc.info/?l=linux-iio&m=147481589111338&w=2 
  and try to distinguish in your changelog if it's cosmetic or bug.
- You should keep the reference to the tool you used to find the bug,
  and the warning you fixed.  It's nice to be able to grep for those.
- There's a checkpatch CHECK hiding in there. You didn't put it in, but
  since you are probably touching that line of code. Fix it. Your checkpatch
  check should have caught that. 

Questions....please ask,
alisons


> ---
>  drivers/iio/temperature/maxim_thermocouple.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
> index 39dd202..3e99056 100644
> --- a/drivers/iio/temperature/maxim_thermocouple.c
> +++ b/drivers/iio/temperature/maxim_thermocouple.c
> @@ -123,19 +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);
> +	ret = spi_read(data->spi, (void *) &buf1, storage_bytes);
> +	if (ret)
> +		return ret;
> +
> +	ret = spi_read(data->spi, (void *) &buf2, storage_bytes);
>  	if (ret)
>  		return ret;
>  
>  	switch (storage_bytes) {
>  	case 2:
> -		*val = be16_to_cpu(buf);
> +		*val = be16_to_cpu(buf1);
>  		break;
>  	case 4:
> -		*val = be32_to_cpu(buf);
> +		*val = be32_to_cpu(buf2);
>  		break;
>  	}
>  
> -- 
> 2.7.4
> 
> -- 
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160925215530.GA7543%40sayli-HP-15-Notebook-PC.
> For more options, visit https://groups.google.com/d/optout.


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

end of thread, other threads:[~2016-09-26  3:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-25 21:55 [PATCH] drivers: iio: temperature: Fix sparse endianness warnings sayli karnik
2016-09-26  3:26 ` [Outreachy kernel] " 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.