drivers: iio: temperature: Fix sparse endianness warnings
PATCH 1/1 drivers: iio: temperature: Fix sparse endianness warnings
Fix following endianness warnings:
warning: cast to restricted __be16
warning: cast to restricted __be32
--- drivers/iio/temperature/maxim_thermocouple.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/iio/temperature/maxim_thermocouple.c +9 -4
@@ -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 ; }
Signature · 1 line
2.7.4
Quoted 5 lines · sayli karnik
Fix following endianness warnings:
warning: cast to restricted__be16
warning: cast to restricted__be32Signed-off-by sayli karnik <[email protected]>
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
Quoted 46 lines
--- drivers/iio/temperature/maxim_thermocouple.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/iio/temperature/maxim_thermocouple.c +9
-4@@ -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 ; }Signature · 8 lines
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 [email protected]. To post to this group, send email to [email protected]. 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.