cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he
Subsystems (3)
PATCH 1/1 cfg80211: Change an 'else if' into an 'else' in cfg80211_calculate_bitrate_he
When building with -Wsometimes-uninitialized, Clang warns:
net/wireless/util.c:1223:11: warning: variable 'result' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
Clang can't evaluate at this point that WARN(1, ...) always returns true because __ret_warn_on is defined as !!(condition), which isn't immediately evaluated as 1. Change this branch to else so that it's clear to Clang that we intend to bail out here.
--- net/wireless/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/wireless/util.c +4 -2
@@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)else if (rate->bw ==RATE_INFO_BW_HE_RU && rate->he_ru_alloc ==NL80211_RATE_INFO_HE_RU_ALLOC_26 ) result = rates_26[rate->he_gi]; -else if (WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , - rate->bw, rate->he_ru_alloc)) +else { +WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , + rate->bw, rate->he_ru_alloc);return 0 ; + }/* now scale to the appropriate MCS */ tmp = result;
Signature · 1 line
2.21.0
Quoted 7 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
net/wireless/util.c:1223:11: warning: variable 'result' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
Quoted 8 lines
Clang can't evaluate at this point that
WARN(1, ...)always returns true because__ret_warn_onis defined as !!(condition), which isn't immediately evaluated as 1. Change this branch to else so that it's clear to Clang that we intend to bail out here.Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>
Thanks for the quick fix!
Quoted 25 lines
--- net/wireless/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)net/wireless/util.c +4
-3@@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)else if (rate->bw ==RATE_INFO_BW_HE_RU && rate->he_ru_alloc ==NL80211_RATE_INFO_HE_RU_ALLOC_26 ) result = rates_26[rate->he_gi]; -else if (WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , - rate->bw, rate->he_ru_alloc)) +else { +WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , + rate->bw, rate->he_ru_alloc);return 0 ; + }/* now scale to the appropriate MCS */ tmp = result; --2.21.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 39 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
net/wireless/util.c:1223:11: warning: variable 'result' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]Clang can't evaluate at this point that
WARN(1, ...)always returns true because__ret_warn_onis defined as !!(condition), which isn't immediately evaluated as 1. Change this branch to else so that it's clear to Clang that we intend to bail out here.Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- net/wireless/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)net/wireless/util.c +4
-2@@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)else if (rate->bw ==RATE_INFO_BW_HE_RU && rate->he_ru_alloc ==NL80211_RATE_INFO_HE_RU_ALLOC_26 ) result = rates_26[rate->he_gi]; -else if (WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , - rate->bw, rate->he_ru_alloc)) +else { +WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , + rate->bw, rate->he_ru_alloc);return 0 ; + }/* now scale to the appropriate MCS */ tmp = result;Signature · 1 line
2.21.0
Gentle ping (if there was a response to this, I didn't receive it). I know I sent it in the middle of a merge window so I get if it slipped through the cracks.
Thanks,
Nathan
Quoted 24 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
net/wireless/util.c:1223:11: warning: variable 'result' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]Clang can't evaluate at this point that
WARN(1, ...)always returns true because__ret_warn_onis defined as !!(condition), which isn't immediately evaluated as 1. Change this branch to else so that it's clear to Clang that we intend to bail out here.Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- net/wireless/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)net/wireless/util.c +0
-0
net/wireless/util.c static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate) · line 1227
Quoted 10 lines
net/wireless/util.c +4
-2@@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)else if (rate->bw ==RATE_INFO_BW_HE_RU && rate->he_ru_alloc ==NL80211_RATE_INFO_HE_RU_ALLOC_26 ) result = rates_26[rate->he_gi]; -else if (WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , - rate->bw, rate->he_ru_alloc)) +else { +WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , + rate->bw, rate->he_ru_alloc);return 0 ; + }
I independently came up with the same fix before I saw yours, the only difference was that I avoided the extra curly braces using
+ else
+ return !WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
+ rate->bw, rate->he_ru_alloc);
to avoid the mix of bare if() and if() {}
Arnd
Quoted 47 lines · Arnd Bergmann
Quoted 24 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
net/wireless/util.c:1223:11: warning: variable 'result' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]Clang can't evaluate at this point that
WARN(1, ...)always returns true because__ret_warn_onis defined as !!(condition), which isn't immediately evaluated as 1. Change this branch to else so that it's clear to Clang that we intend to bail out here.Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- net/wireless/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)net/wireless/util.c +0
-0net/wireless/util.c static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate) · line 1227
Quoted 10 lines
net/wireless/util.c +4
-2@@ -1220,9 +1220,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)else if (rate->bw ==RATE_INFO_BW_HE_RU && rate->he_ru_alloc ==NL80211_RATE_INFO_HE_RU_ALLOC_26 ) result = rates_26[rate->he_gi]; -else if (WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , - rate->bw, rate->he_ru_alloc)) +else { +WARN (1 ,"invalid HE MCS: bw:%d, ru:%d\n" , + rate->bw, rate->he_ru_alloc);return 0 ; + }Reviewed-by Arnd Bergmann <[email protected]>I independently came up with the same fix before I saw yours, the only difference was that I avoided the extra curly braces using
(quoted diff) +3
-0+ else + return !WARN(1, "invalid HE MCS: bw:%d, ru:%d\n", + rate->bw, rate->he_ru_alloc);
Quoted 1 line
to avoid the mix of bare
if()andif(){}
Right, shouldn't all arms of the if/else if/else conditional have {} if any arm has {}.