Skip to contentSkip to conversation

wifi: rtw88: fix uninitialized use of primary channel index

PATCH In review Ping-Ke Shih 3 participants 3 messages Aug 15, 2022 – Aug 29, 2022 Realtek wireless driver (rtw88)

lore
Share & tools
lore

Ping-Ke Shih

author maintainer
#0 lore raw

PATCH 1/1 wifi: rtw88: fix uninitialized use of primary channel index

clang reports uninitialized use:

Quoted 1 line
Quoted 1 line

drivers/net/wireless/realtek/rtw88/main.c:731:2: warning: variable

'primary_channel_idx' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

           default:
           ^~~~~~~
   drivers/net/wireless/realtek/rtw88/main.c:754:39: note: uninitialized
   use occurs here
           hal->current_primary_channel_index = primary_channel_idx;
                                                ^~~~~~~~~~~~~~~~~~~
   drivers/net/wireless/realtek/rtw88/main.c:687:24: note: initialize the
   variable 'primary_channel_idx' to silence this warning
           u8 primary_channel_idx;
                                 ^
                                  = '\0'

This situation could not happen, because possible channel bandwidth 20/40/80MHz are enumerated.

Fixes 341dd1f7de4c ("wifi: rtw88: add the update channel flow to support setting by parameters")
---
 drivers/net/wireless/realtek/rtw88/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/main.c +1 -2
index 790dcfed1125d..5a74dda977563 100644
@@ -697,6 +697,7 @@ void rtw_update_channel(struct rtw_dev *rtwdev, u8 center_channel,
 
 	switch (bandwidth) {
 	case RTW_CHANNEL_WIDTH_20:
+	default:
 		primary_channel_idx = RTW_SC_DONT_CARE;
 		break;
 	case RTW_CHANNEL_WIDTH_40:
@@ -728,8 +729,6 @@ void rtw_update_channel(struct rtw_dev *rtwdev, u8 center_channel,
 			cch_by_bw[RTW_CHANNEL_WIDTH_40] = center_channel - 4;
 		}
 		break;
-	default:
-		break;
 	}
 
 	switch (center_channel) {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Ping-Ke Shih

clang reports uninitialized use:

Quoted 1 line
Quoted 1 line

drivers/net/wireless/realtek/rtw88/main.c:731:2: warning: variable

'primary_channel_idx' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

           default:
           ^~~~~~~
   drivers/net/wireless/realtek/rtw88/main.c:754:39: note: uninitialized
   use occurs here
           hal->current_primary_channel_index = primary_channel_idx;
                                                ^~~~~~~~~~~~~~~~~~~
   drivers/net/wireless/realtek/rtw88/main.c:687:24: note: initialize the
   variable 'primary_channel_idx' to silence this warning
           u8 primary_channel_idx;
                                 ^
                                  = '\0'
Quoted 6 lines

This situation could not happen, because possible channel bandwidth 20/40/80MHz are enumerated.

Fixes 341dd1f7de4c ("wifi: rtw88: add the update channel flow to support setting by parameters")

Can we get this into -next soon? This warning is breaking our builds due to CONFIG_WERROR.

Quoted 29 lines
---
 drivers/net/wireless/realtek/rtw88/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/main.c +1 -2
index 790dcfed1125d..5a74dda977563 100644
@@ -697,6 +697,7 @@ void rtw_update_channel(struct rtw_dev *rtwdev, u8 center_channel,
 
 	switch (bandwidth) {
 	case RTW_CHANNEL_WIDTH_20:
+	default:
 		primary_channel_idx = RTW_SC_DONT_CARE;
 		break;
 	case RTW_CHANNEL_WIDTH_40:
@@ -728,8 +729,6 @@ void rtw_update_channel(struct rtw_dev *rtwdev, u8 center_channel,
 			cch_by_bw[RTW_CHANNEL_WIDTH_40] = center_channel - 4;
 		}
 		break;
-	default:
-		break;
 	}
 
 	switch (center_channel) {
Signature · 1 line
2.25.1
#2 lore raw
Quoted 22 lines · Nathan Chancellor
Quoted 20 lines · Ping-Ke Shih

clang reports uninitialized use:

Quoted 1 line
Quoted 1 line

drivers/net/wireless/realtek/rtw88/main.c:731:2: warning: variable

'primary_channel_idx' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

           default:
           ^~~~~~~
   drivers/net/wireless/realtek/rtw88/main.c:754:39: note: uninitialized
   use occurs here
           hal->current_primary_channel_index = primary_channel_idx;
                                                ^~~~~~~~~~~~~~~~~~~
   drivers/net/wireless/realtek/rtw88/main.c:687:24: note: initialize the
   variable 'primary_channel_idx' to silence this warning
           u8 primary_channel_idx;
                                 ^
                                  = '\0'

This situation could not happen, because possible channel bandwidth 20/40/80MHz are enumerated.

Quoted 8 lines
Quoted 3 lines
Fixes 341dd1f7de4c ("wifi: rtw88: add the update channel flow to support setting by parameters")

Can we get this into -next soon? This warning is breaking our builds due to CONFIG_WERROR.

Johannes applied it:

https://git.kernel.org/netdev/net-next/c/4ffb4d25ef12

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches