OSDN Git Service

staging: wfx: drop calls to BUG_ON()
authorJérôme Pouiller <jerome.pouiller@silabs.com>
Tue, 8 Oct 2019 09:43:01 +0000 (09:43 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Oct 2019 12:44:56 +0000 (14:44 +0200)
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>
drivers/staging/wfx/bh.c
drivers/staging/wfx/bus_sdio.c
drivers/staging/wfx/data_tx.c
drivers/staging/wfx/hif_tx_mib.h
drivers/staging/wfx/key.c
drivers/staging/wfx/queue.c
drivers/staging/wfx/scan.c
drivers/staging/wfx/sta.c

index 3715bb1..3355183 100644 (file)
@@ -56,7 +56,7 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf)
        int release_count;
        int piggyback = 0;
 
-       WARN_ON(read_len < 4);
+       WARN(read_len < 4, "corrupted read");
        WARN(read_len > round_down(0xFFF, 2) * sizeof(u16),
             "%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;
        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;
        wdev->hif.tx_seqnum = (wdev->hif.tx_seqnum + 1) % (HIF_COUNTER_MAX + 1);
index 05f02c2..f973605 100644 (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;
        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(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;
        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(count & 3, "unaligned buffer address");
 
index 1891bca..b2ca398 100644 (file)
@@ -44,7 +44,7 @@ static void tx_policy_build(struct wfx_vif *wvif, struct tx_policy *policy,
        size_t count;
        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));
        for (i = 1; i < IEEE80211_TX_MAX_RATES; i++)
                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);
 
        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);
                return WFX_INVALID_RATE_ID;
        }
index 4f13234..3339ad9 100644 (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 = { };
 
-       WARN_ON(required && !capable);
+       WARN(required && !capable, "incoherent arguments");
        if (capable) {
                val.pmf_enable = 1;
                val.host_enc_auth_frames = 1;
index 4e7d2b5..6d03abe 100644 (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)
 {
-       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]));
        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,
                             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;
        memcpy(msg->key_data, key->key, key->keylen);
        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,
                              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_length = 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;
 
-       WARN_ON(key->keylen != sizeof(msg->tkip_key_data)
-                              + sizeof(msg->tx_mic_key)
-                              + sizeof(msg->rx_mic_key));
+       WARN(key->keylen != sizeof(msg->tkip_key_data)
+                           + sizeof(msg->tx_mic_key)
+                           + sizeof(msg->rx_mic_key), "inconsistent data");
        memcpy(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));
@@ -75,8 +75,8 @@ static uint8_t fill_tkip_group(struct hif_tkip_group_key *msg,
 {
        uint8_t *keybuf = key->key;
 
-       WARN_ON(key->keylen != sizeof(msg->tkip_key_data)
-                              + 2 * sizeof(msg->rx_mic_key));
+       WARN(key->keylen != sizeof(msg->tkip_key_data)
+                           + 2 * sizeof(msg->rx_mic_key), "inconsistent data");
        msg->key_id = key->keyidx;
        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));
@@ -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,
                              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);
        memcpy(msg->aes_key_data, key->key, key->keylen);
        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_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->rx_sequence_counter, seq->ccmp.pn, 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;
 
-       WARN_ON(key->keylen != sizeof(msg->wapi_key_data)
-                              + sizeof(msg->mic_key_data));
+       WARN(key->keylen != sizeof(msg->wapi_key_data)
+                           + sizeof(msg->mic_key_data), "inconsistent data");
        ether_addr_copy(msg->peer_address, peer_addr);
        memcpy(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;
 
-       WARN_ON(key->keylen != sizeof(msg->wapi_key_data)
-                              + sizeof(msg->mic_key_data));
+       WARN(key->keylen != sizeof(msg->wapi_key_data)
+                           + sizeof(msg->mic_key_data), "inconsistent data");
        memcpy(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));
@@ -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_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->ipn, seq->aes_cmac.pn, 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);
        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);
        if (idx < 0)
                return -EINVAL;
index 6f1be4f..ee9b2c3 100644 (file)
@@ -78,7 +78,7 @@ void wfx_tx_queues_unlock(struct wfx_dev *wdev)
        for (i = 0; i < IEEE80211_NUM_ACS; ++i) {
                queue = &wdev->tx_queue[i];
                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)
                        ieee80211_wake_queue(wdev->hw, queue->queue_id);
                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;
                }
        }
-       WARN_ON(1);
        spin_unlock_bh(&stats->pending.lock);
+       WARN(1, "cannot find packet in pending queue");
        return NULL;
 }
 
@@ -408,7 +408,7 @@ static bool hif_handle_tx_data(struct wfx_vif *wvif, struct sk_buff *skb,
 
        switch (action) {
        case do_drop:
-               BUG_ON(wfx_pending_remove(wvif->wdev, skb));
+               wfx_pending_remove(wvif->wdev, skb);
                handled = true;
                break;
        case do_wep:
index ea5001c..cba735c 100644 (file)
@@ -107,7 +107,7 @@ int wfx_hw_scan(struct ieee80211_hw *hw,
 
        wfx_tx_lock_flush(wdev);
 
-       BUG_ON(wvif->scan.req);
+       WARN(wvif->scan.req, "unexpected concurrent scan");
        wvif->scan.req = req;
        wvif->scan.n_ssids = 0;
        wvif->scan.status = 0;
index 12198b8..733b93a 100644 (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)) {
                default_edca_params[IEEE80211_AC_BE].queue_id = HIF_QUEUE_ID_BACKGROUND;
                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);
 
        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++) {
                memcpy(&wvif->edca.params[i], &default_edca_params[i], sizeof(default_edca_params[i]));
                wvif->edca.uapsd_enable[i] = false;