Skip to contentSkip to conversation

iio: chemical: bme680: resolve issue reported by

PATCH New Vasileios Amoiridis 2 participants 3 messages Oct 30, 2024 – Oct 31, 2024 IIO

lore
Share & tools
lore
#0 lore raw

cover iio: chemical: bme680: resolve issue reported by

According to Dan [1], the previous approach was prone to endianness and variable initialization issues because of the typecasting of a s32 to s16 variable. Fix this, by using a local variable and not reusing the local ones.

[1]: https://lore.kernel.org/linux-iio/[email protected]/

Vasileios Amoiridis (1):
iio: chemical: bme680: use s16 variable for temp value to avoid
casting

 drivers/iio/chemical/bme680_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 iio: chemical: bme680: use s16 variable for temp value to avoid casting

Use local s16 variable for the temperature channel to avoid casting it later before passing it to the bme680_read_temp() function. This way, possible endianness and initialization issues are avoided.

---
 drivers/iio/chemical/bme680_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680_core.c +3 -2
index 871921d81e70..6d11f9188367 100644
@@ -741,6 +741,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
 {
 	struct bme680_data *data = iio_priv(indio_dev);
 	int chan_val, ret;
+	s16 temp_chan_val;
 
 	guard(mutex)(&data->lock);
 
@@ -757,11 +758,11 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_PROCESSED:
 		switch (chan->type) {
 		case IIO_TEMP:
-			ret = bme680_read_temp(data, (s16 *)&chan_val);
+			ret = bme680_read_temp(data, &temp_chan_val);
 			if (ret)
 				return ret;
 
-			*val = chan_val * 10;
+			*val = temp_chan_val * 10;
 			return IIO_VAL_INT;
 		case IIO_PRESSURE:
 			ret = bme680_read_press(data, &chan_val);
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw

Re: [PATCH v1] iio: chemical: bme680: use s16 variable for temp value to avoid casting

Quoted 5 lines · On Thu, 31 Oct 2024 00:54:24 +0100 Vasileios Amoiridis…

Use local s16 variable for the temperature channel to avoid casting it later before passing it to the bme680_read_temp() function. This way, possible endianness and initialization issues are avoided.

Applied.

Quoted 30 lines
---
 drivers/iio/chemical/bme680_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680_core.c +3 -2
index 871921d81e70..6d11f9188367 100644
@@ -741,6 +741,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
 {
 	struct bme680_data *data = iio_priv(indio_dev);
 	int chan_val, ret;
+	s16 temp_chan_val;
 
 	guard(mutex)(&data->lock);
 
@@ -757,11 +758,11 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_PROCESSED:
 		switch (chan->type) {
 		case IIO_TEMP:
-			ret = bme680_read_temp(data, (s16 *)&chan_val);
+			ret = bme680_read_temp(data, &temp_chan_val);
 			if (ret)
 				return ret;
 
-			*val = chan_val * 10;
+			*val = temp_chan_val * 10;
 			return IIO_VAL_INT;
 		case IIO_PRESSURE:
 			ret = bme680_read_press(data, &chan_val);