Skip to contentSkip to conversation

iio: chemical: bme680: Fix uninitialized variable in __bme680_read_raw()

PATCH Applied Dan Carpenter 3 participants 3 messages Jan 8, 2025 – Jan 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: chemical: bme680: Fix uninitialized variable in __bme680_read_raw()

The bme680_read_temp() function takes a pointer to s16 but we're passing an int pointer to it. This will not work on big endian systems and it also means that the other 16 bits are uninitialized.

Pass an s16 type variable.

Fixes f51171ce2236 ("iio: chemical: bme680: Add SCALE and RAW channels")
---
 drivers/iio/chemical/bme680_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680_core.c +2 -2
index 26eb0fa77a43..9d73fd2cf52c 100644
@@ -879,11 +879,11 @@ static int __bme680_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_RAW:
 		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;
+			*val = temp_chan_val;
 			return IIO_VAL_INT;
 		case IIO_PRESSURE:
 			ret = bme680_read_press(data, &chan_val);
Signature · 1 line
2.45.2
Acked-by on v1 1/1
#1 lore raw
Quoted 33 lines · Dan Carpenter

The bme680_read_temp() function takes a pointer to s16 but we're passing an int pointer to it. This will not work on big endian systems and it also means that the other 16 bits are uninitialized.

Pass an s16 type variable.

Fixes f51171ce2236 ("iio: chemical: bme680: Add SCALE and RAW channels")
---
 drivers/iio/chemical/bme680_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680_core.c +2 -2
index 26eb0fa77a43..9d73fd2cf52c 100644
@@ -879,11 +879,11 @@ static int __bme680_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_RAW:
 		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;
+			*val = temp_chan_val;
 			return IIO_VAL_INT;
 		case IIO_PRESSURE:
 			ret = bme680_read_press(data, &chan_val);
Signature · 1 line
2.45.2

Hi Dan,

I had already applied this for IIO_CHAN_INFO_PROCESSED but not for the IIO_CHAN_INFO_RAW channel... Very good that you spotted it!

Cheers,
Vasilis

maintainer Applied
#2 lore raw
Quoted 37 lines · On Wed, 8 Jan 2025 22:29:40 +0100 Vasileios Amoiridis <[email protected]>…
Quoted 33 lines · Dan Carpenter

The bme680_read_temp() function takes a pointer to s16 but we're passing an int pointer to it. This will not work on big endian systems and it also means that the other 16 bits are uninitialized.

Pass an s16 type variable.

Fixes f51171ce2236 ("iio: chemical: bme680: Add SCALE and RAW channels")
---
 drivers/iio/chemical/bme680_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/chemical/bme680_core.c +2 -2
index 26eb0fa77a43..9d73fd2cf52c 100644
@@ -879,11 +879,11 @@ static int __bme680_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_RAW:
 		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;
+			*val = temp_chan_val;
 			return IIO_VAL_INT;
 		case IIO_PRESSURE:
 			ret = bme680_read_press(data, &chan_val);
Signature · 1 line
2.45.2
Quoted 4 lines

Hi Dan,

I had already applied this for IIO_CHAN_INFO_PROCESSED but not for the IIO_CHAN_INFO_RAW channel... Very good that you spotted it!

Applied to the fixes-togreg branch of iio.git and marked for stable.

Most likely will go in during the merge window or slightly after.

Quoted 4 lines

Cheers,
Vasilis