Commit 7f90dce1 authored by Emmanuel Grumbach's avatar Emmanuel Grumbach Committed by John W. Linville

iwlagn: use kcalloc when possible for array allocation

As everybody knows kcalloc checks the multiplication is safe and
that we don't run into overflow.
Signed-off-by: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: default avatarWey-Yi Guy <wey-yi.w.guy@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 1a849613
...@@ -641,11 +641,13 @@ void iwl_tt_initialize(struct iwl_priv *priv) ...@@ -641,11 +641,13 @@ void iwl_tt_initialize(struct iwl_priv *priv)
if (priv->cfg->base_params->adv_thermal_throttle) { if (priv->cfg->base_params->adv_thermal_throttle) {
IWL_DEBUG_TEMP(priv, "Advanced Thermal Throttling\n"); IWL_DEBUG_TEMP(priv, "Advanced Thermal Throttling\n");
tt->restriction = kzalloc(sizeof(struct iwl_tt_restriction) * tt->restriction = kcalloc(IWL_TI_STATE_MAX,
IWL_TI_STATE_MAX, GFP_KERNEL); sizeof(struct iwl_tt_restriction),
tt->transaction = kzalloc(sizeof(struct iwl_tt_trans) * GFP_KERNEL);
IWL_TI_STATE_MAX * (IWL_TI_STATE_MAX - 1), tt->transaction = kcalloc(IWL_TI_STATE_MAX *
GFP_KERNEL); (IWL_TI_STATE_MAX - 1),
sizeof(struct iwl_tt_trans),
GFP_KERNEL);
if (!tt->restriction || !tt->transaction) { if (!tt->restriction || !tt->transaction) {
IWL_ERR(priv, "Fallback to Legacy Throttling\n"); IWL_ERR(priv, "Fallback to Legacy Throttling\n");
priv->thermal_throttle.advanced_tt = false; priv->thermal_throttle.advanced_tt = false;
......
...@@ -125,12 +125,12 @@ int iwl_init_geos(struct iwl_priv *priv) ...@@ -125,12 +125,12 @@ int iwl_init_geos(struct iwl_priv *priv)
return 0; return 0;
} }
channels = kzalloc(sizeof(struct ieee80211_channel) * channels = kcalloc(priv->channel_count,
priv->channel_count, GFP_KERNEL); sizeof(struct ieee80211_channel), GFP_KERNEL);
if (!channels) if (!channels)
return -ENOMEM; return -ENOMEM;
rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY), rates = kcalloc(IWL_RATE_COUNT_LEGACY, sizeof(struct ieee80211_rate),
GFP_KERNEL); GFP_KERNEL);
if (!rates) { if (!rates) {
kfree(channels); kfree(channels);
......
...@@ -899,8 +899,9 @@ int iwl_init_channel_map(struct iwl_priv *priv) ...@@ -899,8 +899,9 @@ int iwl_init_channel_map(struct iwl_priv *priv)
IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n", IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n",
priv->channel_count); priv->channel_count);
priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * priv->channel_info = kcalloc(priv->channel_count,
priv->channel_count, GFP_KERNEL); sizeof(struct iwl_channel_info),
GFP_KERNEL);
if (!priv->channel_info) { if (!priv->channel_info) {
IWL_ERR(priv, "Could not allocate channel_info\n"); IWL_ERR(priv, "Could not allocate channel_info\n");
priv->channel_count = 0; priv->channel_count = 0;
......
...@@ -304,8 +304,8 @@ static int iwl_trans_txq_alloc(struct iwl_trans *trans, ...@@ -304,8 +304,8 @@ static int iwl_trans_txq_alloc(struct iwl_trans *trans,
txq->q.n_window = slots_num; txq->q.n_window = slots_num;
txq->meta = kzalloc(sizeof(txq->meta[0]) * slots_num, GFP_KERNEL); txq->meta = kcalloc(slots_num, sizeof(txq->meta[0]), GFP_KERNEL);
txq->cmd = kzalloc(sizeof(txq->cmd[0]) * slots_num, GFP_KERNEL); txq->cmd = kcalloc(slots_num, sizeof(txq->cmd[0]), GFP_KERNEL);
if (!txq->meta || !txq->cmd) if (!txq->meta || !txq->cmd)
goto error; goto error;
...@@ -322,8 +322,8 @@ static int iwl_trans_txq_alloc(struct iwl_trans *trans, ...@@ -322,8 +322,8 @@ static int iwl_trans_txq_alloc(struct iwl_trans *trans,
/* Driver private data, only for Tx (not command) queues, /* Driver private data, only for Tx (not command) queues,
* not shared with device. */ * not shared with device. */
if (txq_id != trans->shrd->cmd_queue) { if (txq_id != trans->shrd->cmd_queue) {
txq->skbs = kzalloc(sizeof(txq->skbs[0]) * txq->skbs = kcalloc(TFD_QUEUE_SIZE_MAX, sizeof(txq->skbs[0]),
TFD_QUEUE_SIZE_MAX, GFP_KERNEL); GFP_KERNEL);
if (!txq->skbs) { if (!txq->skbs) {
IWL_ERR(trans, "kmalloc for auxiliary BD " IWL_ERR(trans, "kmalloc for auxiliary BD "
"structures failed\n"); "structures failed\n");
...@@ -534,8 +534,8 @@ static int iwl_trans_tx_alloc(struct iwl_trans *trans) ...@@ -534,8 +534,8 @@ static int iwl_trans_tx_alloc(struct iwl_trans *trans)
goto error; goto error;
} }
trans_pcie->txq = kzalloc(sizeof(struct iwl_tx_queue) * trans_pcie->txq = kcalloc(hw_params(trans).max_txq_num,
hw_params(trans).max_txq_num, GFP_KERNEL); sizeof(struct iwl_tx_queue), GFP_KERNEL);
if (!trans_pcie->txq) { if (!trans_pcie->txq) {
IWL_ERR(trans, "Not enough memory for txq\n"); IWL_ERR(trans, "Not enough memory for txq\n");
ret = ENOMEM; ret = ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment