Skip to contentSkip to conversation

media: tc358743: initialize variable

PATCH In review [email protected] 2 participants 4 messages Aug 30, 2020 – Sep 2, 2020

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

PATCH 1/1 media: tc358743: initialize variable

From: Tom Rix <[email protected]>

clang static analysis flags this error

tc358743.c:1468:9: warning: Branch condition evaluates
to a garbage value

        return handled ? IRQ_HANDLED : IRQ_NONE;
               ^~~~~~~

handled should be initialized to false.

Fixes d747b806abf4 ("[media] tc358743: add direct interrupt handling")
---
 drivers/media/i2c/tc358743.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/tc358743.c +1 -1
index a03dcab5ce61..c724bd1591de 100644
@@ -1461,7 +1461,7 @@ static int tc358743_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 static irqreturn_t tc358743_irq_handler(int irq, void *dev_id)
 {
 	struct tc358743_state *state = dev_id;
-	bool handled;
+	bool handled = false;
 
 	tc358743_isr(&state->sd, 0, &handled);
 
Signature · 1 line
2.18.1
#1 lore raw
Quoted 5 lines · On Sun, Aug 30, 2020 at 9:30 AM <[email protected]> wrote:

From: Tom Rix <[email protected]>

clang static analysis flags this error

Quoted 8 lines

tc358743.c:1468:9: warning: Branch condition evaluates
to a garbage value

        return handled ? IRQ_HANDLED : IRQ_NONE;
               ^~~~~~~

handled should be initialized to false.

Fixes d747b806abf4 ("[media] tc358743: add direct interrupt handling")

I'm guessing there was more to the report that says that handled isn't necessarily initialized along any of the paths within tc358743_isr()? But you should fix this for all callers of tc358743_isr(), such as tc358743_work_i2c_poll(), not just tc358743_irq_handler().

Quoted 20 lines
---
 drivers/media/i2c/tc358743.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/tc358743.c +1 -2
index a03dcab5ce61..c724bd1591de 100644
@@ -1461,7 +1461,7 @@ static int tc358743_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 static irqreturn_t tc358743_irq_handler(int irq, void *dev_id)
 {
        struct tc358743_state *state = dev_id;
-       bool handled;
+       bool handled = false;
 
        tc358743_isr(&state->sd, 0, &handled);
 
--

2.18.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#2 lore raw
Quoted 11 lines · Nick Desaulniers
Quoted 10 lines · On Sun, Aug 30, 2020 at 9:30 AM <[email protected]> wrote:

From: Tom Rix <[email protected]>

clang static analysis flags this error

tc358743.c:1468:9: warning: Branch condition evaluates
to a garbage value

        return handled ? IRQ_HANDLED : IRQ_NONE;
               ^~~~~~~

handled should be initialized to false.

Quoted 7 lines
Quoted 2 lines
Fixes d747b806abf4 ("[media] tc358743: add direct interrupt handling")

I'm guessing there was more to the report that says that handled isn't necessarily initialized along any of the paths within tc358743_isr()? But you should fix this for all callers of tc358743_isr(), such as tc358743_work_i2c_poll(), not just tc358743_irq_handler().

Interesting. The static analyzer did not catch this.

I will take another.

Thanks

Tom

Quoted 21 lines
Quoted 20 lines
---
 drivers/media/i2c/tc358743.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/tc358743.c +1 -2
index a03dcab5ce61..c724bd1591de 100644
@@ -1461,7 +1461,7 @@ static int tc358743_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 static irqreturn_t tc358743_irq_handler(int irq, void *dev_id)
 {
        struct tc358743_state *state = dev_id;
-       bool handled;
+       bool handled = false;
 
        tc358743_isr(&state->sd, 0, &handled);
 
--

2.18.1

author
#3 lore raw
In reply to Nick Desaulniers
Quoted 11 lines · Nick Desaulniers
Quoted 10 lines · On Sun, Aug 30, 2020 at 9:30 AM <[email protected]> wrote:

From: Tom Rix <[email protected]>

clang static analysis flags this error

tc358743.c:1468:9: warning: Branch condition evaluates
to a garbage value

        return handled ? IRQ_HANDLED : IRQ_NONE;
               ^~~~~~~

handled should be initialized to false.

Quoted 7 lines
Quoted 2 lines
Fixes d747b806abf4 ("[media] tc358743: add direct interrupt handling")

I'm guessing there was more to the report that says that handled isn't necessarily initialized along any of the paths within tc358743_isr()? But you should fix this for all callers of tc358743_isr(), such as tc358743_work_i2c_poll(), not just tc358743_irq_handler().

tc358743_work_i2c_poll does not use handled, so in theory it could pass a null, however at least one of the subhandler, tc358743_cec_isr, does not check if null is passed in.

so i think that covers the callers.

i think initializing handler in tc358743_work_i2c_poll is a not needed since it is unused.  but the null check in tc358743_cec_isr needs to be done. i'll post that as a separate patch once this one settles.

Tom

Quoted 21 lines
Quoted 20 lines
---
 drivers/media/i2c/tc358743.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/tc358743.c +1 -2
index a03dcab5ce61..c724bd1591de 100644
@@ -1461,7 +1461,7 @@ static int tc358743_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 static irqreturn_t tc358743_irq_handler(int irq, void *dev_id)
 {
        struct tc358743_state *state = dev_id;
-       bool handled;
+       bool handled = false;
 
        tc358743_isr(&state->sd, 0, &handled);
 
--

2.18.1