Skip to content

Commit

Permalink
ice: Do not use devm* functions for local uses
Browse files Browse the repository at this point in the history
In situations where we alloc and free memory within the same function do
not use the devm_* variants; use regular alloc and free functions. Remove
any unused vars if there are no usages after these changes.

Also, replace an allocate and copy with kmemdup() and remove an
unnecessary memset() to 0 after a kzalloc().

Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
  • Loading branch information
Tony Nguyen authored and Jeff Kirsher committed Nov 22, 2019
1 parent 1bc7a4a commit 9efe35d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 88 deletions.
25 changes: 14 additions & 11 deletions drivers/net/ethernet/intel/ice/ice_dcb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ void ice_dcb_rebuild(struct ice_pf *pf)
}

/* Retrieve DCB config and ensure same as current in SW */
prev_cfg = devm_kmemdup(&pf->pdev->dev, local_dcbx_cfg,
sizeof(*prev_cfg), GFP_KERNEL);
prev_cfg = kmemdup(local_dcbx_cfg, sizeof(*prev_cfg), GFP_KERNEL);
if (!prev_cfg) {
dev_err(&pf->pdev->dev, "Failed to alloc space for DCB cfg\n");
goto dcb_error;
Expand All @@ -361,11 +360,12 @@ void ice_dcb_rebuild(struct ice_pf *pf)
if (ice_dcb_need_recfg(pf, prev_cfg, local_dcbx_cfg)) {
/* difference in cfg detected - disable DCB till next MIB */
dev_err(&pf->pdev->dev, "Set local MIB not accurate\n");
kfree(prev_cfg);
goto dcb_error;
}

/* fetched config congruent to previous configuration */
devm_kfree(&pf->pdev->dev, prev_cfg);
kfree(prev_cfg);

/* Set the local desired config */
if (local_dcbx_cfg->dcbx_mode == ICE_DCBX_MODE_CEE)
Expand All @@ -389,13 +389,16 @@ void ice_dcb_rebuild(struct ice_pf *pf)

dcb_error:
dev_err(&pf->pdev->dev, "Disabling DCB until new settings occur\n");
prev_cfg = devm_kzalloc(&pf->pdev->dev, sizeof(*prev_cfg), GFP_KERNEL);
prev_cfg = kzalloc(sizeof(*prev_cfg), GFP_KERNEL);
if (!prev_cfg)
return;

prev_cfg->etscfg.willing = true;
prev_cfg->etscfg.tcbwtable[0] = ICE_TC_MAX_BW;
prev_cfg->etscfg.tsatable[0] = ICE_IEEE_TSA_ETS;
memcpy(&prev_cfg->etsrec, &prev_cfg->etscfg, sizeof(prev_cfg->etsrec));
ice_pf_dcb_cfg(pf, prev_cfg, false);
devm_kfree(&pf->pdev->dev, prev_cfg);
kfree(prev_cfg);
}

/**
Expand All @@ -410,18 +413,17 @@ static int ice_dcb_init_cfg(struct ice_pf *pf, bool locked)
int ret = 0;

pi = pf->hw.port_info;
newcfg = devm_kzalloc(&pf->pdev->dev, sizeof(*newcfg), GFP_KERNEL);
newcfg = kmemdup(&pi->local_dcbx_cfg, sizeof(*newcfg), GFP_KERNEL);
if (!newcfg)
return -ENOMEM;

memcpy(newcfg, &pi->local_dcbx_cfg, sizeof(*newcfg));
memset(&pi->local_dcbx_cfg, 0, sizeof(*newcfg));

dev_info(&pf->pdev->dev, "Configuring initial DCB values\n");
if (ice_pf_dcb_cfg(pf, newcfg, locked))
ret = -EINVAL;

devm_kfree(&pf->pdev->dev, newcfg);
kfree(newcfg);

return ret;
}
Expand All @@ -442,9 +444,10 @@ static int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked)

hw = &pf->hw;
pi = hw->port_info;
dcbcfg = devm_kzalloc(&pf->pdev->dev, sizeof(*dcbcfg), GFP_KERNEL);
dcbcfg = kzalloc(sizeof(*dcbcfg), GFP_KERNEL);
if (!dcbcfg)
return -ENOMEM;

memset(dcbcfg, 0, sizeof(*dcbcfg));
memset(&pi->local_dcbx_cfg, 0, sizeof(*dcbcfg));

dcbcfg->etscfg.willing = ets_willing ? 1 : 0;
Expand All @@ -465,7 +468,7 @@ static int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked)
dcbcfg->app[0].prot_id = ICE_APP_PROT_ID_FCOE;

ret = ice_pf_dcb_cfg(pf, dcbcfg, locked);
devm_kfree(&pf->pdev->dev, dcbcfg);
kfree(dcbcfg);
if (ret)
return ret;

Expand Down
50 changes: 22 additions & 28 deletions drivers/net/ethernet/intel/ice/ice_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
}

/* Get last SW configuration */
caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
caps = kzalloc(sizeof(*caps), GFP_KERNEL);
if (!caps)
return -ENOMEM;

Expand Down Expand Up @@ -1007,7 +1007,7 @@ static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
}

done:
devm_kfree(&vsi->back->pdev->dev, caps);
kfree(caps);
return err;
}

Expand Down Expand Up @@ -1083,7 +1083,7 @@ ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
break;
}

caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
caps = kzalloc(sizeof(*caps), GFP_KERNEL);
if (!caps)
return -ENOMEM;

Expand All @@ -1110,7 +1110,7 @@ ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
fecparam->fec |= ETHTOOL_FEC_OFF;

done:
devm_kfree(&vsi->back->pdev->dev, caps);
kfree(caps);
return err;
}

Expand Down Expand Up @@ -2141,7 +2141,7 @@ ice_get_link_ksettings(struct net_device *netdev,
/* flow control is symmetric and always supported */
ethtool_link_ksettings_add_link_mode(ks, supported, Pause);

caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
caps = kzalloc(sizeof(*caps), GFP_KERNEL);
if (!caps)
return -ENOMEM;

Expand Down Expand Up @@ -2199,7 +2199,7 @@ ice_get_link_ksettings(struct net_device *netdev,
ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);

done:
devm_kfree(&vsi->back->pdev->dev, caps);
kfree(caps);
return err;
}

Expand Down Expand Up @@ -2428,8 +2428,7 @@ ice_set_link_ksettings(struct net_device *netdev,
usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
}

abilities = devm_kzalloc(&pf->pdev->dev, sizeof(*abilities),
GFP_KERNEL);
abilities = kzalloc(sizeof(*abilities), GFP_KERNEL);
if (!abilities)
return -ENOMEM;

Expand Down Expand Up @@ -2521,7 +2520,7 @@ ice_set_link_ksettings(struct net_device *netdev,
}

done:
devm_kfree(&pf->pdev->dev, abilities);
kfree(abilities);
clear_bit(__ICE_CFG_BUSY, pf->state);

return err;
Expand Down Expand Up @@ -2649,8 +2648,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
vsi->tx_rings[0]->count, new_tx_cnt);

tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->num_txq,
sizeof(*tx_rings), GFP_KERNEL);
tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
if (!tx_rings) {
err = -ENOMEM;
goto done;
Expand All @@ -2666,7 +2664,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
if (err) {
while (i--)
ice_clean_tx_ring(&tx_rings[i]);
devm_kfree(&pf->pdev->dev, tx_rings);
kfree(tx_rings);
goto done;
}
}
Expand All @@ -2678,8 +2676,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
vsi->xdp_rings[0]->count, new_tx_cnt);

xdp_rings = devm_kcalloc(&pf->pdev->dev, vsi->num_xdp_txq,
sizeof(*xdp_rings), GFP_KERNEL);
xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
if (!xdp_rings) {
err = -ENOMEM;
goto free_tx;
Expand All @@ -2695,7 +2692,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
if (err) {
while (i--)
ice_clean_tx_ring(&xdp_rings[i]);
devm_kfree(&pf->pdev->dev, xdp_rings);
kfree(xdp_rings);
goto free_tx;
}
ice_set_ring_xdp(&xdp_rings[i]);
Expand All @@ -2709,8 +2706,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
vsi->rx_rings[0]->count, new_rx_cnt);

rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->num_rxq,
sizeof(*rx_rings), GFP_KERNEL);
rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
if (!rx_rings) {
err = -ENOMEM;
goto done;
Expand Down Expand Up @@ -2740,7 +2736,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
i--;
ice_free_rx_ring(&rx_rings[i]);
}
devm_kfree(&pf->pdev->dev, rx_rings);
kfree(rx_rings);
err = -ENOMEM;
goto free_tx;
}
Expand All @@ -2758,7 +2754,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
ice_free_tx_ring(vsi->tx_rings[i]);
*vsi->tx_rings[i] = tx_rings[i];
}
devm_kfree(&pf->pdev->dev, tx_rings);
kfree(tx_rings);
}

if (rx_rings) {
Expand All @@ -2776,15 +2772,15 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
rx_rings[i].next_to_alloc = 0;
*vsi->rx_rings[i] = rx_rings[i];
}
devm_kfree(&pf->pdev->dev, rx_rings);
kfree(rx_rings);
}

if (xdp_rings) {
for (i = 0; i < vsi->num_xdp_txq; i++) {
ice_free_tx_ring(vsi->xdp_rings[i]);
*vsi->xdp_rings[i] = xdp_rings[i];
}
devm_kfree(&pf->pdev->dev, xdp_rings);
kfree(xdp_rings);
}

vsi->num_tx_desc = new_tx_cnt;
Expand All @@ -2798,7 +2794,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
if (tx_rings) {
ice_for_each_txq(vsi, i)
ice_free_tx_ring(&tx_rings[i]);
devm_kfree(&pf->pdev->dev, tx_rings);
kfree(tx_rings);
}

done:
Expand Down Expand Up @@ -2846,7 +2842,6 @@ ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
struct ice_netdev_priv *np = netdev_priv(netdev);
struct ice_port_info *pi = np->vsi->port_info;
struct ice_aqc_get_phy_caps_data *pcaps;
struct ice_vsi *vsi = np->vsi;
struct ice_dcbx_cfg *dcbx_cfg;
enum ice_status status;

Expand All @@ -2856,8 +2851,7 @@ ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)

dcbx_cfg = &pi->local_dcbx_cfg;

pcaps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*pcaps),
GFP_KERNEL);
pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
if (!pcaps)
return;

Expand All @@ -2880,7 +2874,7 @@ ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
pause->rx_pause = 1;

out:
devm_kfree(&vsi->back->pdev->dev, pcaps);
kfree(pcaps);
}

/**
Expand Down Expand Up @@ -3061,7 +3055,7 @@ ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
return -EIO;
}

lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
if (!lut)
return -ENOMEM;

Expand All @@ -3074,7 +3068,7 @@ ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
indir[i] = (u32)(lut[i]);

out:
devm_kfree(&pf->pdev->dev, lut);
kfree(lut);
return ret;
}

Expand Down
Loading

0 comments on commit 9efe35d

Please sign in to comment.