staging: wfx: drop calls to BUG_ON()

Most of calls to BUG_ON() could replaced by WARN().

By the way, this patch also try to favor WARN() (that include a comment
about the problem) instead of WARN_ON().

Reported-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Link: https://lore.kernel.org/r/20191008094232.10014-7-Jerome.Pouiller@silabs.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jérôme Pouiller 2019-10-08 09:43:01 +00:00 committed by Greg Kroah-Hartman
parent 51f589c82f
commit b5be2aa3b3
8 changed files with 28 additions and 28 deletions

View File

@ -56,7 +56,7 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf)
int release_count; int release_count;
int piggyback = 0; int piggyback = 0;
WARN_ON(read_len < 4); WARN(read_len < 4, "corrupted read");
WARN(read_len > round_down(0xFFF, 2) * sizeof(u16), WARN(read_len > round_down(0xFFF, 2) * sizeof(u16),
"%s: request exceed WFx capability", __func__); "%s: request exceed WFx capability", __func__);
@ -173,7 +173,7 @@ static void tx_helper(struct wfx_dev *wdev, struct hif_msg *hif)
bool is_encrypted = false; bool is_encrypted = false;
size_t len = le16_to_cpu(hif->len); size_t len = le16_to_cpu(hif->len);
BUG_ON(len < sizeof(*hif)); WARN(len < sizeof(*hif), "try to send corrupted data");
hif->seqnum = wdev->hif.tx_seqnum; hif->seqnum = wdev->hif.tx_seqnum;
wdev->hif.tx_seqnum = (wdev->hif.tx_seqnum + 1) % (HIF_COUNTER_MAX + 1); wdev->hif.tx_seqnum = (wdev->hif.tx_seqnum + 1) % (HIF_COUNTER_MAX + 1);

View File

@ -37,7 +37,7 @@ static int wfx_sdio_copy_from_io(void *priv, unsigned int reg_id,
unsigned int sdio_addr = reg_id << 2; unsigned int sdio_addr = reg_id << 2;
int ret; int ret;
BUG_ON(reg_id > 7); WARN(reg_id > 7, "chip only has 7 registers");
WARN(((uintptr_t) dst) & 3, "unaligned buffer size"); WARN(((uintptr_t) dst) & 3, "unaligned buffer size");
WARN(count & 3, "unaligned buffer address"); WARN(count & 3, "unaligned buffer address");
@ -58,7 +58,7 @@ static int wfx_sdio_copy_to_io(void *priv, unsigned int reg_id,
unsigned int sdio_addr = reg_id << 2; unsigned int sdio_addr = reg_id << 2;
int ret; int ret;
BUG_ON(reg_id > 7); WARN(reg_id > 7, "chip only has 7 registers");
WARN(((uintptr_t) src) & 3, "unaligned buffer size"); WARN(((uintptr_t) src) & 3, "unaligned buffer size");
WARN(count & 3, "unaligned buffer address"); WARN(count & 3, "unaligned buffer address");

View File

@ -44,7 +44,7 @@ static void tx_policy_build(struct wfx_vif *wvif, struct tx_policy *policy,
size_t count; size_t count;
struct wfx_dev *wdev = wvif->wdev; struct wfx_dev *wdev = wvif->wdev;
BUG_ON(rates[0].idx < 0); WARN(rates[0].idx < 0, "invalid rate policy");
memset(policy, 0, sizeof(*policy)); memset(policy, 0, sizeof(*policy));
for (i = 1; i < IEEE80211_TX_MAX_RATES; i++) for (i = 1; i < IEEE80211_TX_MAX_RATES; i++)
if (rates[i].idx < 0) if (rates[i].idx < 0)
@ -162,7 +162,7 @@ static int tx_policy_get(struct wfx_vif *wvif, struct ieee80211_tx_rate *rates,
tx_policy_build(wvif, &wanted, rates); tx_policy_build(wvif, &wanted, rates);
spin_lock_bh(&cache->lock); spin_lock_bh(&cache->lock);
if (WARN_ON_ONCE(list_empty(&cache->free))) { if (WARN_ON(list_empty(&cache->free))) {
spin_unlock_bh(&cache->lock); spin_unlock_bh(&cache->lock);
return WFX_INVALID_RATE_ID; return WFX_INVALID_RATE_ID;
} }

View File

@ -138,7 +138,7 @@ static inline int hif_set_mfp(struct wfx_vif *wvif, bool capable, bool required)
{ {
struct hif_mib_protected_mgmt_policy val = { }; struct hif_mib_protected_mgmt_policy val = { };
WARN_ON(required && !capable); WARN(required && !capable, "incoherent arguments");
if (capable) { if (capable) {
val.pmf_enable = 1; val.pmf_enable = 1;
val.host_enc_auth_frames = 1; val.host_enc_auth_frames = 1;

View File

@ -26,7 +26,7 @@ static int wfx_alloc_key(struct wfx_dev *wdev)
static void wfx_free_key(struct wfx_dev *wdev, int idx) static void wfx_free_key(struct wfx_dev *wdev, int idx)
{ {
BUG_ON(!(wdev->key_map & BIT(idx))); WARN(!(wdev->key_map & BIT(idx)), "inconsistent key allocation");
memset(&wdev->keys[idx], 0, sizeof(wdev->keys[idx])); memset(&wdev->keys[idx], 0, sizeof(wdev->keys[idx]));
wdev->key_map &= ~BIT(idx); wdev->key_map &= ~BIT(idx);
} }
@ -34,7 +34,7 @@ static void wfx_free_key(struct wfx_dev *wdev, int idx)
static uint8_t fill_wep_pair(struct hif_wep_pairwise_key *msg, static uint8_t fill_wep_pair(struct hif_wep_pairwise_key *msg,
struct ieee80211_key_conf *key, u8 *peer_addr) struct ieee80211_key_conf *key, u8 *peer_addr)
{ {
WARN_ON(key->keylen > sizeof(msg->key_data)); WARN(key->keylen > sizeof(msg->key_data), "inconsistent data");
msg->key_length = key->keylen; msg->key_length = key->keylen;
memcpy(msg->key_data, key->key, key->keylen); memcpy(msg->key_data, key->key, key->keylen);
ether_addr_copy(msg->peer_address, peer_addr); ether_addr_copy(msg->peer_address, peer_addr);
@ -44,7 +44,7 @@ static uint8_t fill_wep_pair(struct hif_wep_pairwise_key *msg,
static uint8_t fill_wep_group(struct hif_wep_group_key *msg, static uint8_t fill_wep_group(struct hif_wep_group_key *msg,
struct ieee80211_key_conf *key) struct ieee80211_key_conf *key)
{ {
WARN_ON(key->keylen > sizeof(msg->key_data)); WARN(key->keylen > sizeof(msg->key_data), "inconsistent data");
msg->key_id = key->keyidx; msg->key_id = key->keyidx;
msg->key_length = key->keylen; msg->key_length = key->keylen;
memcpy(msg->key_data, key->key, key->keylen); memcpy(msg->key_data, key->key, key->keylen);
@ -56,9 +56,9 @@ static uint8_t fill_tkip_pair(struct hif_tkip_pairwise_key *msg,
{ {
uint8_t *keybuf = key->key; uint8_t *keybuf = key->key;
WARN_ON(key->keylen != sizeof(msg->tkip_key_data) WARN(key->keylen != sizeof(msg->tkip_key_data)
+ sizeof(msg->tx_mic_key) + sizeof(msg->tx_mic_key)
+ sizeof(msg->rx_mic_key)); + sizeof(msg->rx_mic_key), "inconsistent data");
memcpy(msg->tkip_key_data, keybuf, sizeof(msg->tkip_key_data)); memcpy(msg->tkip_key_data, keybuf, sizeof(msg->tkip_key_data));
keybuf += sizeof(msg->tkip_key_data); keybuf += sizeof(msg->tkip_key_data);
memcpy(msg->tx_mic_key, keybuf, sizeof(msg->tx_mic_key)); memcpy(msg->tx_mic_key, keybuf, sizeof(msg->tx_mic_key));
@ -75,8 +75,8 @@ static uint8_t fill_tkip_group(struct hif_tkip_group_key *msg,
{ {
uint8_t *keybuf = key->key; uint8_t *keybuf = key->key;
WARN_ON(key->keylen != sizeof(msg->tkip_key_data) WARN(key->keylen != sizeof(msg->tkip_key_data)
+ 2 * sizeof(msg->rx_mic_key)); + 2 * sizeof(msg->rx_mic_key), "inconsistent data");
msg->key_id = key->keyidx; msg->key_id = key->keyidx;
memcpy(msg->rx_sequence_counter, &seq->tkip.iv16, sizeof(seq->tkip.iv16)); memcpy(msg->rx_sequence_counter, &seq->tkip.iv16, sizeof(seq->tkip.iv16));
memcpy(msg->rx_sequence_counter + sizeof(uint16_t), &seq->tkip.iv32, sizeof(seq->tkip.iv32)); memcpy(msg->rx_sequence_counter + sizeof(uint16_t), &seq->tkip.iv32, sizeof(seq->tkip.iv32));
@ -94,7 +94,7 @@ static uint8_t fill_tkip_group(struct hif_tkip_group_key *msg,
static uint8_t fill_ccmp_pair(struct hif_aes_pairwise_key *msg, static uint8_t fill_ccmp_pair(struct hif_aes_pairwise_key *msg,
struct ieee80211_key_conf *key, u8 *peer_addr) struct ieee80211_key_conf *key, u8 *peer_addr)
{ {
WARN_ON(key->keylen != sizeof(msg->aes_key_data)); WARN(key->keylen != sizeof(msg->aes_key_data), "inconsistent data");
ether_addr_copy(msg->peer_address, peer_addr); ether_addr_copy(msg->peer_address, peer_addr);
memcpy(msg->aes_key_data, key->key, key->keylen); memcpy(msg->aes_key_data, key->key, key->keylen);
return HIF_KEY_TYPE_AES_PAIRWISE; return HIF_KEY_TYPE_AES_PAIRWISE;
@ -104,7 +104,7 @@ static uint8_t fill_ccmp_group(struct hif_aes_group_key *msg,
struct ieee80211_key_conf *key, struct ieee80211_key_conf *key,
struct ieee80211_key_seq *seq) struct ieee80211_key_seq *seq)
{ {
WARN_ON(key->keylen != sizeof(msg->aes_key_data)); WARN(key->keylen != sizeof(msg->aes_key_data), "inconsistent data");
memcpy(msg->aes_key_data, key->key, key->keylen); memcpy(msg->aes_key_data, key->key, key->keylen);
memcpy(msg->rx_sequence_counter, seq->ccmp.pn, sizeof(seq->ccmp.pn)); memcpy(msg->rx_sequence_counter, seq->ccmp.pn, sizeof(seq->ccmp.pn));
memreverse(msg->rx_sequence_counter, sizeof(seq->ccmp.pn)); memreverse(msg->rx_sequence_counter, sizeof(seq->ccmp.pn));
@ -117,8 +117,8 @@ static uint8_t fill_sms4_pair(struct hif_wapi_pairwise_key *msg,
{ {
uint8_t *keybuf = key->key; uint8_t *keybuf = key->key;
WARN_ON(key->keylen != sizeof(msg->wapi_key_data) WARN(key->keylen != sizeof(msg->wapi_key_data)
+ sizeof(msg->mic_key_data)); + sizeof(msg->mic_key_data), "inconsistent data");
ether_addr_copy(msg->peer_address, peer_addr); ether_addr_copy(msg->peer_address, peer_addr);
memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data)); memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data));
keybuf += sizeof(msg->wapi_key_data); keybuf += sizeof(msg->wapi_key_data);
@ -132,8 +132,8 @@ static uint8_t fill_sms4_group(struct hif_wapi_group_key *msg,
{ {
uint8_t *keybuf = key->key; uint8_t *keybuf = key->key;
WARN_ON(key->keylen != sizeof(msg->wapi_key_data) WARN(key->keylen != sizeof(msg->wapi_key_data)
+ sizeof(msg->mic_key_data)); + sizeof(msg->mic_key_data), "inconsistent data");
memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data)); memcpy(msg->wapi_key_data, keybuf, sizeof(msg->wapi_key_data));
keybuf += sizeof(msg->wapi_key_data); keybuf += sizeof(msg->wapi_key_data);
memcpy(msg->mic_key_data, keybuf, sizeof(msg->mic_key_data)); memcpy(msg->mic_key_data, keybuf, sizeof(msg->mic_key_data));
@ -145,7 +145,7 @@ static uint8_t fill_aes_cmac_group(struct hif_igtk_group_key *msg,
struct ieee80211_key_conf *key, struct ieee80211_key_conf *key,
struct ieee80211_key_seq *seq) struct ieee80211_key_seq *seq)
{ {
WARN_ON(key->keylen != sizeof(msg->igtk_key_data)); WARN(key->keylen != sizeof(msg->igtk_key_data), "inconsistent data");
memcpy(msg->igtk_key_data, key->key, key->keylen); memcpy(msg->igtk_key_data, key->key, key->keylen);
memcpy(msg->ipn, seq->aes_cmac.pn, sizeof(seq->aes_cmac.pn)); memcpy(msg->ipn, seq->aes_cmac.pn, sizeof(seq->aes_cmac.pn));
memreverse(msg->ipn, sizeof(seq->aes_cmac.pn)); memreverse(msg->ipn, sizeof(seq->aes_cmac.pn));
@ -163,7 +163,7 @@ static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta,
int idx = wfx_alloc_key(wvif->wdev); int idx = wfx_alloc_key(wvif->wdev);
bool pairwise = key->flags & IEEE80211_KEY_FLAG_PAIRWISE; bool pairwise = key->flags & IEEE80211_KEY_FLAG_PAIRWISE;
WARN_ON(key->flags & IEEE80211_KEY_FLAG_PAIRWISE && !sta); WARN(key->flags & IEEE80211_KEY_FLAG_PAIRWISE && !sta, "inconsistent data");
ieee80211_get_key_rx_seq(key, 0, &seq); ieee80211_get_key_rx_seq(key, 0, &seq);
if (idx < 0) if (idx < 0)
return -EINVAL; return -EINVAL;

View File

@ -78,7 +78,7 @@ void wfx_tx_queues_unlock(struct wfx_dev *wdev)
for (i = 0; i < IEEE80211_NUM_ACS; ++i) { for (i = 0; i < IEEE80211_NUM_ACS; ++i) {
queue = &wdev->tx_queue[i]; queue = &wdev->tx_queue[i];
spin_lock_bh(&queue->queue.lock); spin_lock_bh(&queue->queue.lock);
BUG_ON(!queue->tx_locked_cnt); WARN(!queue->tx_locked_cnt, "queue already unlocked");
if (--queue->tx_locked_cnt == 0) if (--queue->tx_locked_cnt == 0)
ieee80211_wake_queue(wdev->hw, queue->queue_id); ieee80211_wake_queue(wdev->hw, queue->queue_id);
spin_unlock_bh(&queue->queue.lock); spin_unlock_bh(&queue->queue.lock);
@ -295,8 +295,8 @@ struct sk_buff *wfx_pending_get(struct wfx_dev *wdev, u32 packet_id)
return skb; return skb;
} }
} }
WARN_ON(1);
spin_unlock_bh(&stats->pending.lock); spin_unlock_bh(&stats->pending.lock);
WARN(1, "cannot find packet in pending queue");
return NULL; return NULL;
} }
@ -408,7 +408,7 @@ static bool hif_handle_tx_data(struct wfx_vif *wvif, struct sk_buff *skb,
switch (action) { switch (action) {
case do_drop: case do_drop:
BUG_ON(wfx_pending_remove(wvif->wdev, skb)); wfx_pending_remove(wvif->wdev, skb);
handled = true; handled = true;
break; break;
case do_wep: case do_wep:

View File

@ -107,7 +107,7 @@ int wfx_hw_scan(struct ieee80211_hw *hw,
wfx_tx_lock_flush(wdev); wfx_tx_lock_flush(wdev);
BUG_ON(wvif->scan.req); WARN(wvif->scan.req, "unexpected concurrent scan");
wvif->scan.req = req; wvif->scan.req = req;
wvif->scan.n_ssids = 0; wvif->scan.n_ssids = 0;
wvif->scan.status = 0; wvif->scan.status = 0;

View File

@ -1454,6 +1454,7 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
}, },
}; };
BUILD_BUG_ON(ARRAY_SIZE(default_edca_params) != ARRAY_SIZE(wvif->edca.params));
if (wfx_api_older_than(wdev, 2, 0)) { if (wfx_api_older_than(wdev, 2, 0)) {
default_edca_params[IEEE80211_AC_BE].queue_id = HIF_QUEUE_ID_BACKGROUND; default_edca_params[IEEE80211_AC_BE].queue_id = HIF_QUEUE_ID_BACKGROUND;
default_edca_params[IEEE80211_AC_BK].queue_id = HIF_QUEUE_ID_BESTEFFORT; default_edca_params[IEEE80211_AC_BK].queue_id = HIF_QUEUE_ID_BESTEFFORT;
@ -1526,7 +1527,6 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
mutex_unlock(&wdev->conf_mutex); mutex_unlock(&wdev->conf_mutex);
hif_set_macaddr(wvif, vif->addr); hif_set_macaddr(wvif, vif->addr);
BUG_ON(ARRAY_SIZE(default_edca_params) != ARRAY_SIZE(wvif->edca.params));
for (i = 0; i < IEEE80211_NUM_ACS; i++) { for (i = 0; i < IEEE80211_NUM_ACS; i++) {
memcpy(&wvif->edca.params[i], &default_edca_params[i], sizeof(default_edca_params[i])); memcpy(&wvif->edca.params[i], &default_edca_params[i], sizeof(default_edca_params[i]));
wvif->edca.uapsd_enable[i] = false; wvif->edca.uapsd_enable[i] = false;