提交 9d922f5d 编写于 作者: G Gustavo A. R. Silva 提交者: Jakub Kicinski

net: huawei: hinic: Use devm_kcalloc() instead of devm_kzalloc()

Use 2-factor multiplication argument form devm_kcalloc() instead
of devm_kzalloc().

Link: https://github.com/KSPP/linux/issues/162Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: NKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20211208040311.GA169838@embeddedorSigned-off-by: NJakub Kicinski <kuba@kernel.org>
上级 d7ca9a34
...@@ -814,7 +814,6 @@ static int api_chain_init(struct hinic_api_cmd_chain *chain, ...@@ -814,7 +814,6 @@ static int api_chain_init(struct hinic_api_cmd_chain *chain,
{ {
struct hinic_hwif *hwif = attr->hwif; struct hinic_hwif *hwif = attr->hwif;
struct pci_dev *pdev = hwif->pdev; struct pci_dev *pdev = hwif->pdev;
size_t cell_ctxt_size;
chain->hwif = hwif; chain->hwif = hwif;
chain->chain_type = attr->chain_type; chain->chain_type = attr->chain_type;
...@@ -826,8 +825,8 @@ static int api_chain_init(struct hinic_api_cmd_chain *chain, ...@@ -826,8 +825,8 @@ static int api_chain_init(struct hinic_api_cmd_chain *chain,
sema_init(&chain->sem, 1); sema_init(&chain->sem, 1);
cell_ctxt_size = chain->num_cells * sizeof(*chain->cell_ctxt); chain->cell_ctxt = devm_kcalloc(&pdev->dev, chain->num_cells,
chain->cell_ctxt = devm_kzalloc(&pdev->dev, cell_ctxt_size, GFP_KERNEL); sizeof(*chain->cell_ctxt), GFP_KERNEL);
if (!chain->cell_ctxt) if (!chain->cell_ctxt)
return -ENOMEM; return -ENOMEM;
......
...@@ -796,11 +796,10 @@ static int init_cmdqs_ctxt(struct hinic_hwdev *hwdev, ...@@ -796,11 +796,10 @@ static int init_cmdqs_ctxt(struct hinic_hwdev *hwdev,
struct hinic_cmdq_ctxt *cmdq_ctxts; struct hinic_cmdq_ctxt *cmdq_ctxts;
struct pci_dev *pdev = hwif->pdev; struct pci_dev *pdev = hwif->pdev;
struct hinic_pfhwdev *pfhwdev; struct hinic_pfhwdev *pfhwdev;
size_t cmdq_ctxts_size;
int err; int err;
cmdq_ctxts_size = HINIC_MAX_CMDQ_TYPES * sizeof(*cmdq_ctxts); cmdq_ctxts = devm_kcalloc(&pdev->dev, HINIC_MAX_CMDQ_TYPES,
cmdq_ctxts = devm_kzalloc(&pdev->dev, cmdq_ctxts_size, GFP_KERNEL); sizeof(*cmdq_ctxts), GFP_KERNEL);
if (!cmdq_ctxts) if (!cmdq_ctxts)
return -ENOMEM; return -ENOMEM;
...@@ -884,7 +883,6 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct hinic_hwif *hwif, ...@@ -884,7 +883,6 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct hinic_hwif *hwif,
struct hinic_func_to_io *func_to_io = cmdqs_to_func_to_io(cmdqs); struct hinic_func_to_io *func_to_io = cmdqs_to_func_to_io(cmdqs);
struct pci_dev *pdev = hwif->pdev; struct pci_dev *pdev = hwif->pdev;
struct hinic_hwdev *hwdev; struct hinic_hwdev *hwdev;
size_t saved_wqs_size;
u16 max_wqe_size; u16 max_wqe_size;
int err; int err;
...@@ -895,8 +893,8 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct hinic_hwif *hwif, ...@@ -895,8 +893,8 @@ int hinic_init_cmdqs(struct hinic_cmdqs *cmdqs, struct hinic_hwif *hwif,
if (!cmdqs->cmdq_buf_pool) if (!cmdqs->cmdq_buf_pool)
return -ENOMEM; return -ENOMEM;
saved_wqs_size = HINIC_MAX_CMDQ_TYPES * sizeof(struct hinic_wq); cmdqs->saved_wqs = devm_kcalloc(&pdev->dev, HINIC_MAX_CMDQ_TYPES,
cmdqs->saved_wqs = devm_kzalloc(&pdev->dev, saved_wqs_size, GFP_KERNEL); sizeof(*cmdqs->saved_wqs), GFP_KERNEL);
if (!cmdqs->saved_wqs) { if (!cmdqs->saved_wqs) {
err = -ENOMEM; err = -ENOMEM;
goto err_saved_wqs; goto err_saved_wqs;
......
...@@ -162,7 +162,6 @@ static int init_msix(struct hinic_hwdev *hwdev) ...@@ -162,7 +162,6 @@ static int init_msix(struct hinic_hwdev *hwdev)
struct hinic_hwif *hwif = hwdev->hwif; struct hinic_hwif *hwif = hwdev->hwif;
struct pci_dev *pdev = hwif->pdev; struct pci_dev *pdev = hwif->pdev;
int nr_irqs, num_aeqs, num_ceqs; int nr_irqs, num_aeqs, num_ceqs;
size_t msix_entries_size;
int i, err; int i, err;
num_aeqs = HINIC_HWIF_NUM_AEQS(hwif); num_aeqs = HINIC_HWIF_NUM_AEQS(hwif);
...@@ -171,8 +170,8 @@ static int init_msix(struct hinic_hwdev *hwdev) ...@@ -171,8 +170,8 @@ static int init_msix(struct hinic_hwdev *hwdev)
if (nr_irqs > HINIC_HWIF_NUM_IRQS(hwif)) if (nr_irqs > HINIC_HWIF_NUM_IRQS(hwif))
nr_irqs = HINIC_HWIF_NUM_IRQS(hwif); nr_irqs = HINIC_HWIF_NUM_IRQS(hwif);
msix_entries_size = nr_irqs * sizeof(*hwdev->msix_entries); hwdev->msix_entries = devm_kcalloc(&pdev->dev, nr_irqs,
hwdev->msix_entries = devm_kzalloc(&pdev->dev, msix_entries_size, sizeof(*hwdev->msix_entries),
GFP_KERNEL); GFP_KERNEL);
if (!hwdev->msix_entries) if (!hwdev->msix_entries)
return -ENOMEM; return -ENOMEM;
......
...@@ -631,16 +631,15 @@ static int alloc_eq_pages(struct hinic_eq *eq) ...@@ -631,16 +631,15 @@ static int alloc_eq_pages(struct hinic_eq *eq)
struct hinic_hwif *hwif = eq->hwif; struct hinic_hwif *hwif = eq->hwif;
struct pci_dev *pdev = hwif->pdev; struct pci_dev *pdev = hwif->pdev;
u32 init_val, addr, val; u32 init_val, addr, val;
size_t addr_size;
int err, pg; int err, pg;
addr_size = eq->num_pages * sizeof(*eq->dma_addr); eq->dma_addr = devm_kcalloc(&pdev->dev, eq->num_pages,
eq->dma_addr = devm_kzalloc(&pdev->dev, addr_size, GFP_KERNEL); sizeof(*eq->dma_addr), GFP_KERNEL);
if (!eq->dma_addr) if (!eq->dma_addr)
return -ENOMEM; return -ENOMEM;
addr_size = eq->num_pages * sizeof(*eq->virt_addr); eq->virt_addr = devm_kcalloc(&pdev->dev, eq->num_pages,
eq->virt_addr = devm_kzalloc(&pdev->dev, addr_size, GFP_KERNEL); sizeof(*eq->virt_addr), GFP_KERNEL);
if (!eq->virt_addr) { if (!eq->virt_addr) {
err = -ENOMEM; err = -ENOMEM;
goto err_virt_addr_alloc; goto err_virt_addr_alloc;
......
...@@ -193,20 +193,20 @@ static int alloc_page_arrays(struct hinic_wqs *wqs) ...@@ -193,20 +193,20 @@ static int alloc_page_arrays(struct hinic_wqs *wqs)
{ {
struct hinic_hwif *hwif = wqs->hwif; struct hinic_hwif *hwif = wqs->hwif;
struct pci_dev *pdev = hwif->pdev; struct pci_dev *pdev = hwif->pdev;
size_t size;
size = wqs->num_pages * sizeof(*wqs->page_paddr); wqs->page_paddr = devm_kcalloc(&pdev->dev, wqs->num_pages,
wqs->page_paddr = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); sizeof(*wqs->page_paddr), GFP_KERNEL);
if (!wqs->page_paddr) if (!wqs->page_paddr)
return -ENOMEM; return -ENOMEM;
size = wqs->num_pages * sizeof(*wqs->page_vaddr); wqs->page_vaddr = devm_kcalloc(&pdev->dev, wqs->num_pages,
wqs->page_vaddr = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); sizeof(*wqs->page_vaddr), GFP_KERNEL);
if (!wqs->page_vaddr) if (!wqs->page_vaddr)
goto err_page_vaddr; goto err_page_vaddr;
size = wqs->num_pages * sizeof(*wqs->shadow_page_vaddr); wqs->shadow_page_vaddr = devm_kcalloc(&pdev->dev, wqs->num_pages,
wqs->shadow_page_vaddr = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); sizeof(*wqs->shadow_page_vaddr),
GFP_KERNEL);
if (!wqs->shadow_page_vaddr) if (!wqs->shadow_page_vaddr)
goto err_page_shadow_vaddr; goto err_page_shadow_vaddr;
...@@ -379,15 +379,14 @@ static int alloc_wqes_shadow(struct hinic_wq *wq) ...@@ -379,15 +379,14 @@ static int alloc_wqes_shadow(struct hinic_wq *wq)
{ {
struct hinic_hwif *hwif = wq->hwif; struct hinic_hwif *hwif = wq->hwif;
struct pci_dev *pdev = hwif->pdev; struct pci_dev *pdev = hwif->pdev;
size_t size;
size = wq->num_q_pages * wq->max_wqe_size; wq->shadow_wqe = devm_kcalloc(&pdev->dev, wq->num_q_pages,
wq->shadow_wqe = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); wq->max_wqe_size, GFP_KERNEL);
if (!wq->shadow_wqe) if (!wq->shadow_wqe)
return -ENOMEM; return -ENOMEM;
size = wq->num_q_pages * sizeof(wq->prod_idx); wq->shadow_idx = devm_kcalloc(&pdev->dev, wq->num_q_pages,
wq->shadow_idx = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); sizeof(wq->prod_idx), GFP_KERNEL);
if (!wq->shadow_idx) if (!wq->shadow_idx)
goto err_shadow_idx; goto err_shadow_idx;
......
...@@ -144,13 +144,12 @@ static int create_txqs(struct hinic_dev *nic_dev) ...@@ -144,13 +144,12 @@ static int create_txqs(struct hinic_dev *nic_dev)
{ {
int err, i, j, num_txqs = hinic_hwdev_num_qps(nic_dev->hwdev); int err, i, j, num_txqs = hinic_hwdev_num_qps(nic_dev->hwdev);
struct net_device *netdev = nic_dev->netdev; struct net_device *netdev = nic_dev->netdev;
size_t txq_size;
if (nic_dev->txqs) if (nic_dev->txqs)
return -EINVAL; return -EINVAL;
txq_size = num_txqs * sizeof(*nic_dev->txqs); nic_dev->txqs = devm_kcalloc(&netdev->dev, num_txqs,
nic_dev->txqs = devm_kzalloc(&netdev->dev, txq_size, GFP_KERNEL); sizeof(*nic_dev->txqs), GFP_KERNEL);
if (!nic_dev->txqs) if (!nic_dev->txqs)
return -ENOMEM; return -ENOMEM;
...@@ -241,13 +240,12 @@ static int create_rxqs(struct hinic_dev *nic_dev) ...@@ -241,13 +240,12 @@ static int create_rxqs(struct hinic_dev *nic_dev)
{ {
int err, i, j, num_rxqs = hinic_hwdev_num_qps(nic_dev->hwdev); int err, i, j, num_rxqs = hinic_hwdev_num_qps(nic_dev->hwdev);
struct net_device *netdev = nic_dev->netdev; struct net_device *netdev = nic_dev->netdev;
size_t rxq_size;
if (nic_dev->rxqs) if (nic_dev->rxqs)
return -EINVAL; return -EINVAL;
rxq_size = num_rxqs * sizeof(*nic_dev->rxqs); nic_dev->rxqs = devm_kcalloc(&netdev->dev, num_rxqs,
nic_dev->rxqs = devm_kzalloc(&netdev->dev, rxq_size, GFP_KERNEL); sizeof(*nic_dev->rxqs), GFP_KERNEL);
if (!nic_dev->rxqs) if (!nic_dev->rxqs)
return -ENOMEM; return -ENOMEM;
......
...@@ -862,7 +862,6 @@ int hinic_init_txq(struct hinic_txq *txq, struct hinic_sq *sq, ...@@ -862,7 +862,6 @@ int hinic_init_txq(struct hinic_txq *txq, struct hinic_sq *sq,
struct hinic_dev *nic_dev = netdev_priv(netdev); struct hinic_dev *nic_dev = netdev_priv(netdev);
struct hinic_hwdev *hwdev = nic_dev->hwdev; struct hinic_hwdev *hwdev = nic_dev->hwdev;
int err, irqname_len; int err, irqname_len;
size_t sges_size;
txq->netdev = netdev; txq->netdev = netdev;
txq->sq = sq; txq->sq = sq;
...@@ -871,13 +870,13 @@ int hinic_init_txq(struct hinic_txq *txq, struct hinic_sq *sq, ...@@ -871,13 +870,13 @@ int hinic_init_txq(struct hinic_txq *txq, struct hinic_sq *sq,
txq->max_sges = HINIC_MAX_SQ_BUFDESCS; txq->max_sges = HINIC_MAX_SQ_BUFDESCS;
sges_size = txq->max_sges * sizeof(*txq->sges); txq->sges = devm_kcalloc(&netdev->dev, txq->max_sges,
txq->sges = devm_kzalloc(&netdev->dev, sges_size, GFP_KERNEL); sizeof(*txq->sges), GFP_KERNEL);
if (!txq->sges) if (!txq->sges)
return -ENOMEM; return -ENOMEM;
sges_size = txq->max_sges * sizeof(*txq->free_sges); txq->free_sges = devm_kcalloc(&netdev->dev, txq->max_sges,
txq->free_sges = devm_kzalloc(&netdev->dev, sges_size, GFP_KERNEL); sizeof(*txq->free_sges), GFP_KERNEL);
if (!txq->free_sges) { if (!txq->free_sges) {
err = -ENOMEM; err = -ENOMEM;
goto err_alloc_free_sges; goto err_alloc_free_sges;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册