Skip to content

Commit 868fd97

Browse files
jerome-pouillergregkh
authored andcommitted
staging: wfx: improve robustness of wfx_get_hw_rate()
Smatch complains: data_tx.c:37 wfx_get_hw_rate() warn: constraint '(struct ieee80211_supported_band)->bitrates' overflow 'band->bitrates' 0 <= abs_rl '0-127' user_rl '' required = '(struct ieee80211_supported_band)->n_bitrates' 23 struct ieee80211_supported_band *band; 24 25 if (rate->idx < 0) 26 return -1; 27 if (rate->flags & IEEE80211_TX_RC_MCS) { 28 if (rate->idx > 7) { 29 WARN(1, "wrong rate->idx value: %d", rate->idx); 30 return -1; 31 } 32 return rate->idx + 14; 33 } 34 // WFx only support 2GHz, else band information should be retrieved 35 // from ieee80211_tx_info 36 band = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ]; 37 return band->bitrates[rate->idx].hw_value; Add a simple check to make Smatch happy. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Jérôme Pouiller <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c9d4769 commit 868fd97

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/staging/wfx/data_tx.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ static int wfx_get_hw_rate(struct wfx_dev *wdev,
3131
}
3232
return rate->idx + 14;
3333
}
34+
if (rate->idx >= band->n_bitrates) {
35+
WARN(1, "wrong rate->idx value: %d", rate->idx);
36+
return -1;
37+
}
3438
// WFx only support 2GHz, else band information should be retrieved
3539
// from ieee80211_tx_info
3640
band = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ];

0 commit comments

Comments
 (0)