Skip to contentSkip to conversation

iio: accel: bma400: Fix smatch warning based on use of unintialized value.

PATCH In review Jonathan Cameron 3 participants 7 messages Sep 17, 2022 – Sep 19, 2022

Subsystems (2)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

PATCH 1/1 iio: accel: bma400: Fix smatch warning based on use of unintialized value.

From: Jonathan Cameron <[email protected]>

Only specific bits in this value are ever used and those are initialized, but that is complex to reason about in a checker. Hence, initialize the value to zero and avoid the complexity.

Smatch warning:
drivers/iio/accel/bma400_core.c:1287 bma400_tap_event_en()
error: uninitialized symbol 'field_value'.

---
 drivers/iio/accel/bma400_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/bma400_core.c +2 -1
index eceb1f8d338d..ad8fce3e08cd 100644
@@ -1184,7 +1184,8 @@ static int bma400_activity_event_en(struct bma400_data *data,
 				    enum iio_event_direction dir,
 				    int state)
 {
-	int ret, reg, msk, value, field_value;
+	int ret, reg, msk, value;
+	int field_value = 0;
 
 	switch (dir) {
 	case IIO_EV_DIR_RISING:
Signature · 1 line
2.37.2
#1 lore raw

Hi Jonathan,

Thank you for sending this patch.
If you need a tag for this fix.

Fixes 961db2da159d ("iio: accel: bma400: Add support for single and

double tap events")

Thank you
Jagath

Quoted 36 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Only specific bits in this value are ever used and those are initialized, but that is complex to reason about in a checker. Hence, initialize the value to zero and avoid the complexity.

Smatch warning:
drivers/iio/accel/bma400_core.c:1287 bma400_tap_event_en()
error: uninitialized symbol 'field_value'.

---
 drivers/iio/accel/bma400_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/bma400_core.c +2 -2
index eceb1f8d338d..ad8fce3e08cd 100644
@@ -1184,7 +1184,8 @@ static int bma400_activity_event_en(struct bma400_data *data,
                                    enum iio_event_direction dir,
                                    int state)
 {
-       int ret, reg, msk, value, field_value;
+       int ret, reg, msk, value;
+       int field_value = 0;
 
        switch (dir) {
        case IIO_EV_DIR_RISING:
--

2.37.2

author maintainer
#2 lore raw
Quoted 7 lines · On Sun, 18 Sep 2022 20:05:48 +0530 Jagath Jog J <[email protected]> wrote:

Hi Jonathan,

Thank you for sending this patch.
If you need a tag for this fix.

Fixes 961db2da159d ("iio: accel: bma400: Add support for single and

double tap events")

Good point. I'm careful about fixes tags to stuff still not upstream because they tend to be a little unstable. This should be fine. I'll see if it's valid when I rebase the tree (hopefully in a few days time).

Also helpful if you give an Acked-by!

Thanks,

Jonathan

Quoted 41 lines

Thank you
Jagath

Quoted 36 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Only specific bits in this value are ever used and those are initialized, but that is complex to reason about in a checker. Hence, initialize the value to zero and avoid the complexity.

Smatch warning:
drivers/iio/accel/bma400_core.c:1287 bma400_tap_event_en()
error: uninitialized symbol 'field_value'.

---
 drivers/iio/accel/bma400_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/bma400_core.c +2 -2
index eceb1f8d338d..ad8fce3e08cd 100644
@@ -1184,7 +1184,8 @@ static int bma400_activity_event_en(struct bma400_data *data,
                                    enum iio_event_direction dir,
                                    int state)
 {
-       int ret, reg, msk, value, field_value;
+       int ret, reg, msk, value;
+       int field_value = 0;
 
        switch (dir) {
        case IIO_EV_DIR_RISING:
--

2.37.2

#3 lore raw
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Sun, 18 Sep 2022 20:05:48 +0530 Jagath Jog J <[email protected]> wrote:

Hi Jonathan,

Thank you for sending this patch.
If you need a tag for this fix.

Quoted 6 lines
Quoted 2 lines
Fixes 961db2da159d ("iio: accel: bma400: Add support for single and

double tap events")

Good point. I'm careful about fixes tags to stuff still not upstream because they tend to be a little unstable. This should be fine. I'll see if it's valid when I rebase the tree (hopefully in a few days time).

If you forget to update the tags after a rebase then Stephen Rothwell will let you know. It's best to not make Stephen's job more difficult, but it's some comfort to know that mistakes will get caught.

regards,
dan carpenter

author maintainer
#4 lore raw
Quoted 16 lines · On Mon, 19 Sep 2022 09:10:52 +0300 Dan Carpenter <[email protected]>…
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Sun, 18 Sep 2022 20:05:48 +0530 Jagath Jog J <[email protected]> wrote:

Hi Jonathan,

Thank you for sending this patch.
If you need a tag for this fix.

Quoted 6 lines
Quoted 2 lines
Fixes 961db2da159d ("iio: accel: bma400: Add support for single and

double tap events")

Good point. I'm careful about fixes tags to stuff still not upstream because they tend to be a little unstable. This should be fine. I'll see if it's valid when I rebase the tree (hopefully in a few days time).

Quoted 7 lines

If you forget to update the tags after a rebase then Stephen Rothwell will let you know. It's best to not make Stephen's job more difficult, but it's some comfort to know that mistakes will get caught.

regards,
dan carpenter

Hi Dan,

Having messed this up and caused Stephen pointless work several times I now have scripting (thanks to Greg KH's scripts and some local modes to make sure the tag is in the upstream of the fix) to check this but some how I still mess it up from time to time :(

Jonathan

Acked-by on v1 1/1
#5 lore raw
In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Only specific bits in this value are ever used and those are initialized, but that is complex to reason about in a checker. Hence, initialize the value to zero and avoid the complexity.

Smatch warning:
drivers/iio/accel/bma400_core.c:1287 bma400_tap_event_en()
error: uninitialized symbol 'field_value'.

Quoted 26 lines
---
 drivers/iio/accel/bma400_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/bma400_core.c +2 -2
index eceb1f8d338d..ad8fce3e08cd 100644
@@ -1184,7 +1184,8 @@ static int bma400_activity_event_en(struct bma400_data *data,
                                    enum iio_event_direction dir,
                                    int state)
 {
-       int ret, reg, msk, value, field_value;
+       int ret, reg, msk, value;
+       int field_value = 0;
 
        switch (dir) {
        case IIO_EV_DIR_RISING:
--

2.37.2

author maintainer
#6 lore raw
Quoted 8 lines · On Sun, 18 Sep 2022 23:50:44 +0530 Jagath Jog J <[email protected]> wrote:
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Only specific bits in this value are ever used and those are initialized, but that is complex to reason about in a checker. Hence, initialize the value to zero and avoid the complexity.

Quoted 5 lines
Quoted 3 lines

Smatch warning:
drivers/iio/accel/bma400_core.c:1287 bma400_tap_event_en()
error: uninitialized symbol 'field_value'.

Applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons.

Thanks,

Jonathan

Quoted 27 lines
Quoted 27 lines
---
 drivers/iio/accel/bma400_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/bma400_core.c +2 -2
index eceb1f8d338d..ad8fce3e08cd 100644
@@ -1184,7 +1184,8 @@ static int bma400_activity_event_en(struct bma400_data *data,
                                    enum iio_event_direction dir,
                                    int state)
 {
-       int ret, reg, msk, value, field_value;
+       int ret, reg, msk, value;
+       int field_value = 0;
 
        switch (dir) {
        case IIO_EV_DIR_RISING:
--

2.37.2