Skip to contentSkip to conversation

net: ethernet: sun: Zero initialize class in default case in niu_add_ethtool_tcam_entry

PATCH Applied Nathan Chancellor 3 participants 3 messages Mar 7, 2019 – Mar 8, 2019

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

PATCH 1/1 net: ethernet: sun: Zero initialize class in default case in niu_add_ethtool_tcam_entry

When building with -Wsometimes-uninitialized, Clang warns:

drivers/net/ethernet/sun/niu.c:7466:5: warning: variable 'class' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

The default case can never happen because i can only be 0 to 3 (NIU_L3_PROG_CLS is defined as 4). To make this clear to Clang, just zero initialize class in the default case (use the macro CLASS_CODE_UNRECOG to make it clear this shouldn't happen).

---
 drivers/net/ethernet/sun/niu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sun/niu.c +1 -0
index d84501441edd..6f99437a6962 100644
@@ -7464,6 +7464,7 @@ static int niu_add_ethtool_tcam_entry(struct niu *np,
 					class = CLASS_CODE_USER_PROG4;
 					break;
 				default:
+					class = CLASS_CODE_UNRECOG;
 					break;
 				}
 				ret = tcam_user_ip_class_set(np, class, 0,
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/net/ethernet/sun/niu.c:7466:5: warning: variable 'class' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

The default case can never happen because i can only be 0 to 3 (NIU_L3_PROG_CLS is defined as 4). To make this clear to Clang, just zero initialize class in the default case (use the macro CLASS_CODE_UNRECOG to make it clear this shouldn't happen).

Good choice. Thanks for the patch.

Quoted 22 lines
---
 drivers/net/ethernet/sun/niu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/sun/niu.c +1 -1
index d84501441edd..6f99437a6962 100644
@@ -7464,6 +7464,7 @@ static int niu_add_ethtool_tcam_entry(struct niu *np,
                                        class = CLASS_CODE_USER_PROG4;
                                        break;
                                default:
+                                       class = CLASS_CODE_UNRECOG;
                                        break;
                                }
                                ret = tcam_user_ip_class_set(np, class, 0,
--

2.21.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer Applied
#2 lore raw
In reply to Nathan Chancellor

From: Nathan Chancellor <[email protected]>
Date: Thu, 7 Mar 2019 16:29:33 -0700

Quoted 6 lines

When building with -Wsometimes-uninitialized, Clang warns:

drivers/net/ethernet/sun/niu.c:7466:5: warning: variable 'class' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

Quoted 7 lines

The default case can never happen because i can only be 0 to 3 (NIU_L3_PROG_CLS is defined as 4). To make this clear to Clang, just zero initialize class in the default case (use the macro CLASS_CODE_UNRECOG to make it clear this shouldn't happen).

Applied, thanks.