cxgb4: Use the bitmap API to allocate bitmaps
Use bitmap_zalloc()/bitmap_free() instead of hand-writing them. It is less verbose and it improves the semantic. While at it, remove a useless bitmap_zero(). The bitmap is already zeroed when allocated. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Link: https://lore.kernel.org/r/8a2168ef9871bd9c4f1cf19b8d5f7530662a5d15.1656866770.git.christophe.jaillet@wanadoo.fr Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
55ae465222
commit
ec53d77ae3
3 changed files with 17 additions and 24 deletions
|
@ -3429,18 +3429,18 @@ static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
|
|||
unsigned long *t;
|
||||
struct adapter *adap = filp->private_data;
|
||||
|
||||
t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
|
||||
t = bitmap_zalloc(adap->sge.egr_sz, GFP_KERNEL);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
|
||||
if (err) {
|
||||
kfree(t);
|
||||
bitmap_free(t);
|
||||
return err;
|
||||
}
|
||||
|
||||
bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
|
||||
kfree(t);
|
||||
bitmap_free(t);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
|
@ -2227,7 +2227,7 @@ void cxgb4_cleanup_ethtool_filters(struct adapter *adap)
|
|||
if (eth_filter_info) {
|
||||
for (i = 0; i < adap->params.nports; i++) {
|
||||
kvfree(eth_filter_info[i].loc_array);
|
||||
kfree(eth_filter_info[i].bmap);
|
||||
bitmap_free(eth_filter_info[i].bmap);
|
||||
}
|
||||
kfree(eth_filter_info);
|
||||
}
|
||||
|
@ -2270,9 +2270,7 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
|
|||
goto free_eth_finfo;
|
||||
}
|
||||
|
||||
eth_filter->port[i].bmap = kcalloc(BITS_TO_LONGS(nentries),
|
||||
sizeof(unsigned long),
|
||||
GFP_KERNEL);
|
||||
eth_filter->port[i].bmap = bitmap_zalloc(nentries, GFP_KERNEL);
|
||||
if (!eth_filter->port[i].bmap) {
|
||||
ret = -ENOMEM;
|
||||
goto free_eth_finfo;
|
||||
|
@ -2284,7 +2282,7 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
|
|||
|
||||
free_eth_finfo:
|
||||
while (i-- > 0) {
|
||||
kfree(eth_filter->port[i].bmap);
|
||||
bitmap_free(eth_filter->port[i].bmap);
|
||||
kvfree(eth_filter->port[i].loc_array);
|
||||
}
|
||||
kfree(eth_filter_info);
|
||||
|
|
|
@ -5047,28 +5047,24 @@ static int adap_init0(struct adapter *adap, int vpd_skip)
|
|||
/* Allocate the memory for the vaious egress queue bitmaps
|
||||
* ie starving_fl, txq_maperr and blocked_fl.
|
||||
*/
|
||||
adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
|
||||
sizeof(long), GFP_KERNEL);
|
||||
adap->sge.starving_fl = bitmap_zalloc(adap->sge.egr_sz, GFP_KERNEL);
|
||||
if (!adap->sge.starving_fl) {
|
||||
ret = -ENOMEM;
|
||||
goto bye;
|
||||
}
|
||||
|
||||
adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
|
||||
sizeof(long), GFP_KERNEL);
|
||||
adap->sge.txq_maperr = bitmap_zalloc(adap->sge.egr_sz, GFP_KERNEL);
|
||||
if (!adap->sge.txq_maperr) {
|
||||
ret = -ENOMEM;
|
||||
goto bye;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
|
||||
sizeof(long), GFP_KERNEL);
|
||||
adap->sge.blocked_fl = bitmap_zalloc(adap->sge.egr_sz, GFP_KERNEL);
|
||||
if (!adap->sge.blocked_fl) {
|
||||
ret = -ENOMEM;
|
||||
goto bye;
|
||||
}
|
||||
bitmap_zero(adap->sge.blocked_fl, adap->sge.egr_sz);
|
||||
#endif
|
||||
|
||||
params[0] = FW_PARAM_PFVF(CLIP_START);
|
||||
|
@ -5417,10 +5413,10 @@ bye:
|
|||
adap_free_hma_mem(adap);
|
||||
kfree(adap->sge.egr_map);
|
||||
kfree(adap->sge.ingr_map);
|
||||
kfree(adap->sge.starving_fl);
|
||||
kfree(adap->sge.txq_maperr);
|
||||
bitmap_free(adap->sge.starving_fl);
|
||||
bitmap_free(adap->sge.txq_maperr);
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
kfree(adap->sge.blocked_fl);
|
||||
bitmap_free(adap->sge.blocked_fl);
|
||||
#endif
|
||||
if (ret != -ETIMEDOUT && ret != -EIO)
|
||||
t4_fw_bye(adap, adap->mbox);
|
||||
|
@ -5854,8 +5850,7 @@ static int alloc_msix_info(struct adapter *adap, u32 num_vec)
|
|||
if (!msix_info)
|
||||
return -ENOMEM;
|
||||
|
||||
adap->msix_bmap.msix_bmap = kcalloc(BITS_TO_LONGS(num_vec),
|
||||
sizeof(long), GFP_KERNEL);
|
||||
adap->msix_bmap.msix_bmap = bitmap_zalloc(num_vec, GFP_KERNEL);
|
||||
if (!adap->msix_bmap.msix_bmap) {
|
||||
kfree(msix_info);
|
||||
return -ENOMEM;
|
||||
|
@ -5870,7 +5865,7 @@ static int alloc_msix_info(struct adapter *adap, u32 num_vec)
|
|||
|
||||
static void free_msix_info(struct adapter *adap)
|
||||
{
|
||||
kfree(adap->msix_bmap.msix_bmap);
|
||||
bitmap_free(adap->msix_bmap.msix_bmap);
|
||||
kfree(adap->msix_info);
|
||||
}
|
||||
|
||||
|
@ -6189,10 +6184,10 @@ static void free_some_resources(struct adapter *adapter)
|
|||
cxgb4_cleanup_ethtool_filters(adapter);
|
||||
kfree(adapter->sge.egr_map);
|
||||
kfree(adapter->sge.ingr_map);
|
||||
kfree(adapter->sge.starving_fl);
|
||||
kfree(adapter->sge.txq_maperr);
|
||||
bitmap_free(adapter->sge.starving_fl);
|
||||
bitmap_free(adapter->sge.txq_maperr);
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
kfree(adapter->sge.blocked_fl);
|
||||
bitmap_free(adapter->sge.blocked_fl);
|
||||
#endif
|
||||
disable_msi(adapter);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue