John Zhao has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: Fix control flow DEADCODE issue ......................................................................
Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change removes the DEADCODE code.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 0 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/1
diff --git a/src/ec/kontron/kempld/kempld_i2c.c b/src/ec/kontron/kempld/kempld_i2c.c index 296cf76..165c940 100644 --- a/src/ec/kontron/kempld/kempld_i2c.c +++ b/src/ec/kontron/kempld/kempld_i2c.c @@ -250,9 +250,6 @@ else prescale = KEMPLD_CLK / (KEMPLD_I2C_FREQ_STD * 4) - 3000;
- if (prescale < 0) - prescale = 0; - /* Round to the best matching value */ prescale_corr = prescale / 1000; if (prescale % 1000 >= 500)
Hello Tim Wawrzynczak, Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45623
to look at the new patch set (#2).
Change subject: Fix control flow DEADCODE issue ......................................................................
Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change removes the DEADCODE.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 0 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/2
Hello build bot (Jenkins), Tim Wawrzynczak, Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45623
to look at the new patch set (#3).
Change subject: Fix control flow DEADCODE issue ......................................................................
Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change removes this DEADCODE.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 0 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/3
Hello build bot (Jenkins), Tim Wawrzynczak, Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45623
to look at the new patch set (#4).
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
ec/kontron: Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change removes this DEADCODE.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 0 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/4
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 4:
Seems like it might be simpler to have something like #if KEMPLD_CLK < 0 || KEMPLD_I2C_FREQ_STD < 0 #error Check your KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions #endif
That would avoid the dead code and still prevent negative prescaler values here. what do you think?
John Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 4:
Patch Set 4:
Seems like it might be simpler to have something like #if KEMPLD_CLK < 0 || KEMPLD_I2C_FREQ_STD < 0 #error Check your KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions #endif
That would avoid the dead code and still prevent negative prescaler values here. what do you think?
Apart from the signs of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD, prescale is determined by the following calculation "KEMPLD_CLK / (KEMPLD_I2C_FREQ_STD * 5) - 1000" or "KEMPLD_CLK / (KEMPLD_I2C_FREQ_STD * 4) - 3000". Based on current KEMPLD_CLK & KEMPLD_I2C_FREQ_STD definitions, prescale won't be negative which is why Coverity complains about the DEADCODE. It seems checking the signs of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD does not help to address this DEADCODE issue.
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 4: Code-Review+1
(1 comment)
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... File src/ec/kontron/kempld/kempld_i2c.c:
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... PS4, Line 253: if (prescale < 0) This is a safeguard in case prescale ends up being negative. I'd replace it with an assertion.
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 4:
(1 comment)
Please never remove checks because of tools.
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... File src/ec/kontron/kempld/kempld_i2c.c:
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... PS4, Line 253: if (prescale < 0)
This is a safeguard in case prescale ends up being negative. I'd replace it with an assertion.
I guess I kept it in case the constants would change (it is probably runtime configurable in the Linux driver). A _Static_assertion() would make most sense here I guess.
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 4:
(1 comment)
Patch Set 4:
(1 comment)
Please never remove checks because of tools.
Instead, try to find a more suitable kind of check.
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... File src/ec/kontron/kempld/kempld_i2c.c:
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... PS4, Line 253: if (prescale < 0)
I guess I kept it in case the constants would change (it is probably runtime […]
Sounds good. Regular `assert()` now provides compile-time checks if possible, too.
Hello build bot (Jenkins), Nico Huber, Maxim Polyakov, Tim Wawrzynczak, Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45623
to look at the new patch set (#5).
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
ec/kontron: Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change removes this DEADCODE.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 1 insertion(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/5
John Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 5:
(1 comment)
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... File src/ec/kontron/kempld/kempld_i2c.c:
https://review.coreboot.org/c/coreboot/+/45623/4/src/ec/kontron/kempld/kempl... PS4, Line 253: if (prescale < 0)
Sounds good. Regular `assert()` now provides compile-time checks if possible, too.
Ack
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 5:
(2 comments)
https://review.coreboot.org/c/coreboot/+/45623/5//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/45623/5//COMMIT_MSG@11 PS5, Line 11: This change removes this DEADCODE. This change makes Coverity happy by using an assertion instead.
https://review.coreboot.org/c/coreboot/+/45623/5/src/ec/kontron/kempld/kempl... File src/ec/kontron/kempld/kempld_i2c.c:
https://review.coreboot.org/c/coreboot/+/45623/5/src/ec/kontron/kempld/kempl... PS5, Line 253: assert(prescale < 0); Um, no. We want `prescale` to be larger than or equal to 0.
Hello build bot (Jenkins), Nico Huber, Maxim Polyakov, Tim Wawrzynczak, Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45623
to look at the new patch set (#6).
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
ec/kontron: Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change adds assertion check for the prescale value.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 1 insertion(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/6
John Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 6:
(2 comments)
https://review.coreboot.org/c/coreboot/+/45623/5//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/45623/5//COMMIT_MSG@11 PS5, Line 11: This change removes this DEADCODE.
This change makes Coverity happy by using an assertion instead.
Done
https://review.coreboot.org/c/coreboot/+/45623/5/src/ec/kontron/kempld/kempl... File src/ec/kontron/kempld/kempld_i2c.c:
https://review.coreboot.org/c/coreboot/+/45623/5/src/ec/kontron/kempld/kempl... PS5, Line 253: assert(prescale < 0);
Um, no. We want `prescale` to be larger than or equal to 0.
Done
Hello build bot (Jenkins), Nico Huber, Maxim Polyakov, Tim Wawrzynczak, Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45623
to look at the new patch set (#7).
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
ec/kontron: Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change asserts check for the prescale value.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 1 insertion(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/7
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 7:
(1 comment)
https://review.coreboot.org/c/coreboot/+/45623/7//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/45623/7//COMMIT_MSG@11 PS7, Line 11: asserts check IMHO, this doesn't parse well. Also, the sentence I suggested hints at Coverity not being smart enough about code safety:
This change makes Coverity happy by using an assertion instead.
Let's not forget that, while tools can be helpful, they can also cause lots of pain. Have you ever hit your fingers while trying to hammer a nail? 😉
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 7: Code-Review+2
Other than the comment on the commit message (which is important), LGTM.
Hello build bot (Jenkins), Nico Huber, Maxim Polyakov, Tim Wawrzynczak, Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45623
to look at the new patch set (#8).
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
ec/kontron: Fix control flow DEADCODE issue
Coverity detects DEADCODE issue in the control flow. Based on both of KEMPLD_CLK and KEMPLD_I2C_FREQ_STD definitions, execution cannot reach this statement "prescale = 0". This change makes Coverity happy by using an assertion instead.
Found-by: Coverity CID 1431154 TEST=None
Signed-off-by: John Zhao john.zhao@intel.com Change-Id: Ic002e708636961358969b2c1eaec0fee5bbcb73a --- M src/ec/kontron/kempld/kempld_i2c.c 1 file changed, 1 insertion(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/23/45623/8
John Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/c/coreboot/+/45623/7//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/45623/7//COMMIT_MSG@11 PS7, Line 11: asserts check
IMHO, this doesn't parse well. […]
Done
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 8: Code-Review+2
Thank you!
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 8: Code-Review-1
I strongly advice against using assert() like this. If we know, event want, that the check is done at build time, we should use _Static_assertion(). Beside being clear to the reader it also allows us to specify a proper error message.
Do we even know if using assert() (which only does the build- time check with our custom implementation) will calm Coverity? iow. is it smart enough to detect that this is no usual assert()?
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 8:
Patch Set 8: Code-Review-1
I strongly advice against using assert() like this. If we know, event want, that the check is done at build time, we should use _Static_assertion(). Beside being clear to the reader it also allows us to specify a proper error message.
Do we even know if using assert() (which only does the build- time check with our custom implementation) will calm Coverity? iow. is it smart enough to detect that this is no usual assert()?
There's CB:44476 which would probably not work if using a _Static_assert().
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45623 )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Patch Set 8: Code-Review+1
Stefan Reinauer has abandoned this change. ( https://review.coreboot.org/c/coreboot/+/45623?usp=email )
Change subject: ec/kontron: Fix control flow DEADCODE issue ......................................................................
Abandoned