diff mbox series

[1/2] staging: wfx: fix use of uninitialized pointer

Message ID 20201019160604.1609180-1-Jerome.Pouiller@silabs.com (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series [1/2] staging: wfx: fix use of uninitialized pointer | expand

Commit Message

Jérôme Pouiller Oct. 19, 2020, 4:06 p.m. UTC
From: Jérôme Pouiller <jerome.pouiller@silabs.com>

With -Wuninitialized, the compiler complains:

drivers/staging/wfx/data_tx.c:34:19: warning: variable 'band' is uninitialized when used here [-Wuninitialized]
    if (rate->idx >= band->n_bitrates) {
                         ^~~~

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Nathan Chancellor <natechancellor@gmail.com>
Fixes: 868fd970e187 ("staging: wfx: improve robustness of wfx_get_hw_rate()")
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
---
 drivers/staging/wfx/data_tx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Nathan Chancellor Oct. 20, 2020, 1:07 a.m. UTC | #1
On Mon, Oct 19, 2020 at 06:06:03PM +0200, Jerome Pouiller wrote:
> From: Jérôme Pouiller <jerome.pouiller@silabs.com>
> 
> With -Wuninitialized, the compiler complains:
> 
> drivers/staging/wfx/data_tx.c:34:19: warning: variable 'band' is uninitialized when used here [-Wuninitialized]
>     if (rate->idx >= band->n_bitrates) {
>                          ^~~~
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Nathan Chancellor <natechancellor@gmail.com>
> Fixes: 868fd970e187 ("staging: wfx: improve robustness of wfx_get_hw_rate()")
> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  drivers/staging/wfx/data_tx.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/wfx/data_tx.c b/drivers/staging/wfx/data_tx.c
> index 41f6a604a697..36b36ef39d05 100644
> --- a/drivers/staging/wfx/data_tx.c
> +++ b/drivers/staging/wfx/data_tx.c
> @@ -31,13 +31,13 @@ static int wfx_get_hw_rate(struct wfx_dev *wdev,
>  		}
>  		return rate->idx + 14;
>  	}
> -	if (rate->idx >= band->n_bitrates) {
> -		WARN(1, "wrong rate->idx value: %d", rate->idx);
> -		return -1;
> -	}
>  	// WFx only support 2GHz, else band information should be retrieved
>  	// from ieee80211_tx_info
>  	band = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ];
> +	if (rate->idx >= band->n_bitrates) {
> +		WARN(1, "wrong rate->idx value: %d", rate->idx);
> +		return -1;
> +	}
>  	return band->bitrates[rate->idx].hw_value;
>  }
>  
> -- 
> 2.28.0
>
diff mbox series

Patch

diff --git a/drivers/staging/wfx/data_tx.c b/drivers/staging/wfx/data_tx.c
index 41f6a604a697..36b36ef39d05 100644
--- a/drivers/staging/wfx/data_tx.c
+++ b/drivers/staging/wfx/data_tx.c
@@ -31,13 +31,13 @@  static int wfx_get_hw_rate(struct wfx_dev *wdev,
 		}
 		return rate->idx + 14;
 	}
-	if (rate->idx >= band->n_bitrates) {
-		WARN(1, "wrong rate->idx value: %d", rate->idx);
-		return -1;
-	}
 	// WFx only support 2GHz, else band information should be retrieved
 	// from ieee80211_tx_info
 	band = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ];
+	if (rate->idx >= band->n_bitrates) {
+		WARN(1, "wrong rate->idx value: %d", rate->idx);
+		return -1;
+	}
 	return band->bitrates[rate->idx].hw_value;
 }