diff mbox series

wifi: rtw88: fix uninitialized use of primary channel index

Message ID 20220815062004.22920-1-pkshih@realtek.com (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series wifi: rtw88: fix uninitialized use of primary channel index | expand

Commit Message

Ping-Ke Shih Aug. 15, 2022, 6:20 a.m. UTC
clang reports uninitialized use:

>> 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")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
---
 drivers/net/wireless/realtek/rtw88/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Nathan Chancellor Aug. 24, 2022, 7:38 p.m. UTC | #1
On Mon, Aug 15, 2022 at 02:20:04PM +0800, Ping-Ke Shih wrote:
> clang reports uninitialized use:
> 
> >> 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")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

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

> ---
>  drivers/net/wireless/realtek/rtw88/main.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
> index 790dcfed1125d..5a74dda977563 100644
> --- a/drivers/net/wireless/realtek/rtw88/main.c
> +++ b/drivers/net/wireless/realtek/rtw88/main.c
> @@ -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) {
> -- 
> 2.25.1
> 
>
Kalle Valo Aug. 29, 2022, 3:35 p.m. UTC | #2
Nathan Chancellor <nathan@kernel.org> writes:

> On Mon, Aug 15, 2022 at 02:20:04PM +0800, Ping-Ke Shih wrote:
>
>> clang reports uninitialized use:
>> 
>> >> 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")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
>
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
>
> 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
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
index 790dcfed1125d..5a74dda977563 100644
--- a/drivers/net/wireless/realtek/rtw88/main.c
+++ b/drivers/net/wireless/realtek/rtw88/main.c
@@ -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) {