EDAC: sb_edac: simplify switch statement
Subsystems (2)
PATCH 1/1 EDAC: sb_edac: simplify switch statement
From: Tom Rix <[email protected]>
clang static analyzer reports this problem
sb_edac.c:959:2: warning: Undefined or garbage value
returned to caller
return type;
^~~~~~~~~~~This is a false positive.
However by initializing the type to DEV_UNKNOWN the 3 case can be removed from the switch, saving a comparison and jump.
--- drivers/edac/sb_edac.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/edac/sb_edac.c +1 -4
@@ -939,12 +939,9 @@ static enum dev_type sbridge_get_width(struct sbridge_pvt *pvt, u32 mtr)static enum dev_type __ibridge_get_width (u32 mtr) { -enum dev_type type; +enum dev_type type =DEV_UNKNOWN ;switch (mtr) { -case 3 : - type =DEV_UNKNOWN ; -break ;case 2 : type =DEV_X16 ;break ;
Signature · 1 line
2.18.1
Quoted 9 lines · On Mon, Sep 07, 2020 at 08:32:25AM -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
clang static analyzer reports this problem
sb_edac.c:959:2: warning: Undefined or garbage value
returned to callerreturn type; ^~~~~~~~~~~
Quoted 6 lines
This is a false positive.
However by initializing the type to
DEV_UNKNOWNthe 3 case can be removed from the switch, saving a comparison and jump.Signed-off-by Tom Rix <[email protected]>
Some maintainers have a preference for a default case statement but presumably this case statement has been cutting it as is so:
Quoted 29 lines
--- drivers/edac/sb_edac.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/edac/sb_edac.c +1
-4@@ -939,12 +939,9 @@ static enum dev_type sbridge_get_width(struct sbridge_pvt *pvt, u32 mtr)static enum dev_type __ibridge_get_width (u32 mtr) { -enum dev_type type; +enum dev_type type =DEV_UNKNOWN ;switch (mtr) { -case 3 : - type =DEV_UNKNOWN ; -break ;case 2 : type =DEV_X16 ;break ;Signature · 6 lines
2.18.1 -- You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200907153225.7294-1-trix%40redhat.com.
Quoted 4 lines
However by initializing the type to
DEV_UNKNOWNthe 3 case can be removed from the switch, saving a comparison and jump.Signed-off-by Tom Rix <[email protected]>
Applied. Thanks.
-Tony
[Boris: Pushed to edac-misc and edac-for-next branches in RAS tree]
Borislav Petkov
maintainerQuoted 1 line · Tony
[Boris: Pushed to edac-misc and edac-for-next branches in RAS tree]
Yap, looks good.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette