diff mbox series

iio: Fix uninitialized variable

Message ID 20241011093752.30685-1-0xff07@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series iio: Fix uninitialized variable | expand

Commit Message

Yo-Jung Lin Oct. 11, 2024, 9:37 a.m. UTC
clang found that the "offset" in bmp580_trigger_handler doesn't get
initialized before access. Add proper initialization to this variable.

Signed-off-by: Yo-Jung (Leo) Lin <0xff07@gmail.com>
---
 drivers/iio/pressure/bmp280-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andy Shevchenko Oct. 11, 2024, 10:54 a.m. UTC | #1
On Fri, Oct 11, 2024 at 05:37:45PM +0800, Yo-Jung (Leo) Lin wrote:
> clang found that the "offset" in bmp580_trigger_handler doesn't get
> initialized before access. Add proper initialization to this variable.

...

>  	struct bmp280_data *data = iio_priv(indio_dev);
> -	int ret, offset;
> +	int ret, offset = 0;

Can it be done closer to the actual user of it?
Javier Carrasco Oct. 11, 2024, 11:02 a.m. UTC | #2
On 11/10/2024 12:54, Andy Shevchenko wrote:
> On Fri, Oct 11, 2024 at 05:37:45PM +0800, Yo-Jung (Leo) Lin wrote:
>> clang found that the "offset" in bmp580_trigger_handler doesn't get
>> initialized before access. Add proper initialization to this variable.
> 
> ...
> 
>>  	struct bmp280_data *data = iio_priv(indio_dev);
>> -	int ret, offset;
>> +	int ret, offset = 0;
> 
> Can it be done closer to the actual user of it?
> 
> 

Actually, offset could be initialized to sizeof(32), and only used for
the temperature calculations.

+	int ret, offset = sizeof(s32);

The first memcpy would use 0 as index, as it did before.


Best regards,
Javier Carrasco
diff mbox series

Patch

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index f4df222ed0c3..7d4151826b86 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -2210,7 +2210,7 @@  static irqreturn_t bmp580_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct bmp280_data *data = iio_priv(indio_dev);
-	int ret, offset;
+	int ret, offset = 0;
 
 	guard(mutex)(&data->lock);