aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2011-04-18 12:12:37 -0400
committerWey-Yi Guy <wey-yi.w.guy@intel.com>2011-04-18 12:14:30 -0400
commit3e41ace5deef7af16dd277d9d17f9d36dca0a10e (patch)
tree213bf23ffeaede74cddd033ccd45a1d45e9d3f3b /drivers/net
parente79b1ca75bb48111e8d93fc576f50e24671f5f9d (diff)
iwlagn: remove most BUG_ON instances
There are a number of things in the driver that may result in a BUG(), which is suboptimal since it's hard to get debugging information out of the driver in that case and the user experience is also not good :-) Almost all BUG_ON instances can be converted to WARN_ON with a few lines of appropriate error handling, so do that instead. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-hcmd.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c25
7 files changed, 42 insertions, 27 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index b4f7510f51ec..0daededb0ff2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -394,7 +394,9 @@ int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
394 return -EINVAL; 394 return -EINVAL;
395 } 395 }
396 396
397 BUG_ON(addr & ~DMA_BIT_MASK(36)); 397 if (WARN_ON(addr & ~DMA_BIT_MASK(36)))
398 return -EINVAL;
399
398 if (unlikely(addr & ~IWL_TX_DMA_MASK)) 400 if (unlikely(addr & ~IWL_TX_DMA_MASK))
399 IWL_ERR(priv, "Unaligned address = %llx\n", 401 IWL_ERR(priv, "Unaligned address = %llx\n",
400 (unsigned long long)addr); 402 (unsigned long long)addr);
@@ -718,7 +720,10 @@ static void iwl_rx_handle(struct iwl_priv *priv)
718 /* If an RXB doesn't have a Rx queue slot associated with it, 720 /* If an RXB doesn't have a Rx queue slot associated with it,
719 * then a bug has been introduced in the queue refilling 721 * then a bug has been introduced in the queue refilling
720 * routines -- catch it here */ 722 * routines -- catch it here */
721 BUG_ON(rxb == NULL); 723 if (WARN_ON(rxb == NULL)) {
724 i = (i + 1) & RX_QUEUE_MASK;
725 continue;
726 }
722 727
723 rxq->queue[i] = NULL; 728 rxq->queue[i] = NULL;
724 729
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
index 859b94a12297..402733638f50 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
@@ -215,12 +215,6 @@ static int iwlcore_get_nvm_type(struct iwl_priv *priv, u32 hw_rev)
215 return nvm_type; 215 return nvm_type;
216} 216}
217 217
218const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
219{
220 BUG_ON(offset >= priv->cfg->base_params->eeprom_size);
221 return &priv->eeprom[offset];
222}
223
224static int iwl_init_otp_access(struct iwl_priv *priv) 218static int iwl_init_otp_access(struct iwl_priv *priv)
225{ 219{
226 int ret; 220 int ret;
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
index 0e9d9703636a..9ce052573c6a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
@@ -309,7 +309,6 @@ int iwl_eeprom_check_sku(struct iwl_priv *priv);
309const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset); 309const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset);
310int iwlcore_eeprom_verify_signature(struct iwl_priv *priv); 310int iwlcore_eeprom_verify_signature(struct iwl_priv *priv);
311u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset); 311u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset);
312const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset);
313int iwl_init_channel_map(struct iwl_priv *priv); 312int iwl_init_channel_map(struct iwl_priv *priv);
314void iwl_free_channel_map(struct iwl_priv *priv); 313void iwl_free_channel_map(struct iwl_priv *priv);
315const struct iwl_channel_info *iwl_get_channel_info( 314const struct iwl_channel_info *iwl_get_channel_info(
diff --git a/drivers/net/wireless/iwlwifi/iwl-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
index 9177b553fe57..8f0beb992ccf 100644
--- a/drivers/net/wireless/iwlwifi/iwl-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
@@ -143,10 +143,12 @@ static int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
143{ 143{
144 int ret; 144 int ret;
145 145
146 BUG_ON(!(cmd->flags & CMD_ASYNC)); 146 if (WARN_ON(!(cmd->flags & CMD_ASYNC)))
147 return -EINVAL;
147 148
148 /* An asynchronous command can not expect an SKB to be set. */ 149 /* An asynchronous command can not expect an SKB to be set. */
149 BUG_ON(cmd->flags & CMD_WANT_SKB); 150 if (WARN_ON(cmd->flags & CMD_WANT_SKB))
151 return -EINVAL;
150 152
151 /* Assign a generic callback if one is not provided */ 153 /* Assign a generic callback if one is not provided */
152 if (!cmd->callback) 154 if (!cmd->callback)
@@ -169,10 +171,12 @@ int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
169 int cmd_idx; 171 int cmd_idx;
170 int ret; 172 int ret;
171 173
172 lockdep_assert_held(&priv->mutex); 174 if (WARN_ON(cmd->flags & CMD_ASYNC))
175 return -EINVAL;
173 176
174 /* A synchronous command can not have a callback set. */ 177 /* A synchronous command can not have a callback set. */
175 BUG_ON((cmd->flags & CMD_ASYNC) || cmd->callback); 178 if (WARN_ON(cmd->callback))
179 return -EINVAL;
176 180
177 IWL_DEBUG_INFO(priv, "Attempting to send sync command %s\n", 181 IWL_DEBUG_INFO(priv, "Attempting to send sync command %s\n",
178 get_cmd_string(cmd->id)); 182 get_cmd_string(cmd->id));
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/iwl-power.c
index ae176d8da9e8..b7cd95820ff8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.c
+++ b/drivers/net/wireless/iwlwifi/iwl-power.c
@@ -188,9 +188,10 @@ static void iwl_static_sleep_cmd(struct iwl_priv *priv,
188 table = range_0; 188 table = range_0;
189 } 189 }
190 190
191 BUG_ON(lvl < 0 || lvl >= IWL_POWER_NUM); 191 if (WARN_ON(lvl < 0 || lvl >= IWL_POWER_NUM))
192 192 memset(cmd, 0, sizeof(*cmd));
193 *cmd = table[lvl].cmd; 193 else
194 *cmd = table[lvl].cmd;
194 195
195 if (period == 0) { 196 if (period == 0) {
196 skip = 0; 197 skip = 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index c21515640077..3c8cebde16cc 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -494,7 +494,8 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
494 494
495 priv->num_stations--; 495 priv->num_stations--;
496 496
497 BUG_ON(priv->num_stations < 0); 497 if (WARN_ON(priv->num_stations < 0))
498 priv->num_stations = 0;
498 499
499 spin_unlock_irqrestore(&priv->sta_lock, flags); 500 spin_unlock_irqrestore(&priv->sta_lock, flags);
500 501
@@ -679,7 +680,8 @@ void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
679 680
680 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; 681 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
681 priv->num_stations--; 682 priv->num_stations--;
682 BUG_ON(priv->num_stations < 0); 683 if (WARN_ON(priv->num_stations < 0))
684 priv->num_stations = 0;
683 kfree(priv->stations[i].lq); 685 kfree(priv->stations[i].lq);
684 priv->stations[i].lq = NULL; 686 priv->stations[i].lq = NULL;
685 } 687 }
@@ -775,7 +777,8 @@ int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
775 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 777 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
776 778
777 iwl_dump_lq_cmd(priv, lq); 779 iwl_dump_lq_cmd(priv, lq);
778 BUG_ON(init && (cmd.flags & CMD_ASYNC)); 780 if (WARN_ON(init && (cmd.flags & CMD_ASYNC)))
781 return -EINVAL;
779 782
780 if (is_lq_table_valid(priv, ctx, lq)) 783 if (is_lq_table_valid(priv, ctx, lq))
781 ret = iwl_send_cmd(priv, &cmd); 784 ret = iwl_send_cmd(priv, &cmd);
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index 3732380c4ffe..e7faba57b6e3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -263,11 +263,13 @@ static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
263 263
264 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap 264 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
265 * and iwl_queue_dec_wrap are broken. */ 265 * and iwl_queue_dec_wrap are broken. */
266 BUG_ON(!is_power_of_2(count)); 266 if (WARN_ON(!is_power_of_2(count)))
267 return -EINVAL;
267 268
268 /* slots_num must be power-of-two size, otherwise 269 /* slots_num must be power-of-two size, otherwise
269 * get_cmd_index is broken. */ 270 * get_cmd_index is broken. */
270 BUG_ON(!is_power_of_2(slots_num)); 271 if (WARN_ON(!is_power_of_2(slots_num)))
272 return -EINVAL;
271 273
272 q->low_mark = q->n_window / 4; 274 q->low_mark = q->n_window / 4;
273 if (q->low_mark < 4) 275 if (q->low_mark < 4)
@@ -384,7 +386,9 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
384 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); 386 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
385 387
386 /* Initialize queue's high/low-water marks, and head/tail indexes */ 388 /* Initialize queue's high/low-water marks, and head/tail indexes */
387 iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); 389 ret = iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
390 if (ret)
391 return ret;
388 392
389 /* Tell device where to find queue */ 393 /* Tell device where to find queue */
390 priv->cfg->ops->lib->txq_init(priv, txq); 394 priv->cfg->ops->lib->txq_init(priv, txq);
@@ -446,14 +450,19 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
446 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len); 450 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
447 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); 451 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
448 452
449 /* If any of the command structures end up being larger than 453 /*
454 * If any of the command structures end up being larger than
450 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then 455 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
451 * we will need to increase the size of the TFD entries 456 * we will need to increase the size of the TFD entries
452 * Also, check to see if command buffer should not exceed the size 457 * Also, check to see if command buffer should not exceed the size
453 * of device_cmd and max_cmd_size. */ 458 * of device_cmd and max_cmd_size.
454 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && 459 */
455 !(cmd->flags & CMD_SIZE_HUGE)); 460 if (WARN_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
456 BUG_ON(fix_size > IWL_MAX_CMD_SIZE); 461 !(cmd->flags & CMD_SIZE_HUGE)))
462 return -EINVAL;
463
464 if (WARN_ON(fix_size > IWL_MAX_CMD_SIZE))
465 return -EINVAL;
457 466
458 if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) { 467 if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) {
459 IWL_WARN(priv, "Not sending command - %s KILL\n", 468 IWL_WARN(priv, "Not sending command - %s KILL\n",