Skip to content

Commit cd4bc63

Browse files
rtg-canonicaldavem330
authored andcommitted
net: enetc: unmap DMA in enetc_send_cmd()
Coverity complains of a possible dereference of a null return value. 5. returned_null: kzalloc returns NULL. [show details] 6. var_assigned: Assigning: si_data = NULL return value from kzalloc. 488 si_data = kzalloc(data_size, __GFP_DMA | GFP_KERNEL); 489 cbd.length = cpu_to_le16(data_size); 490 491 dma = dma_map_single(&priv->si->pdev->dev, si_data, 492 data_size, DMA_FROM_DEVICE); While this kzalloc() is unlikely to fail, I did notice that the function returned without unmapping si_data. Fix this by refactoring the error paths and checking for kzalloc() failure. Fixes: 888ae5a ("net: enetc: add tc flower psfp offload driver") Cc: Claudiu Manoil <claudiu.manoil@nxp.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Jakub Kicinski <kuba@kernel.org> Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org (open list) Signed-off-by: Tim Gardner <tim.gardner@canonical.com> Acked-by: Claudiu Manoil <claudiu.manoil@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5b92be6 commit cd4bc63

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎drivers/net/ethernet/freescale/enetc/enetc_qos.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,16 @@ static int enetc_streamid_hw_set(struct enetc_ndev_priv *priv,
486486

487487
data_size = sizeof(struct streamid_data);
488488
si_data = kzalloc(data_size, __GFP_DMA | GFP_KERNEL);
489+
if (!si_data)
490+
return -ENOMEM;
489491
cbd.length = cpu_to_le16(data_size);
490492

491493
dma = dma_map_single(&priv->si->pdev->dev, si_data,
492494
data_size, DMA_FROM_DEVICE);
493495
if (dma_mapping_error(&priv->si->pdev->dev, dma)) {
494496
netdev_err(priv->si->ndev, "DMA mapping failed!\n");
495-
kfree(si_data);
496-
return -ENOMEM;
497+
err = -ENOMEM;
498+
goto out;
497499
}
498500

499501
cbd.addr[0] = cpu_to_le32(lower_32_bits(dma));
@@ -512,12 +514,10 @@ static int enetc_streamid_hw_set(struct enetc_ndev_priv *priv,
512514

513515
err = enetc_send_cmd(priv->si, &cbd);
514516
if (err)
515-
return -EINVAL;
517+
goto out;
516518

517-
if (!enable) {
518-
kfree(si_data);
519-
return 0;
520-
}
519+
if (!enable)
520+
goto out;
521521

522522
/* Enable the entry overwrite again incase space flushed by hardware */
523523
memset(&cbd, 0, sizeof(cbd));
@@ -560,6 +560,10 @@ static int enetc_streamid_hw_set(struct enetc_ndev_priv *priv,
560560
}
561561

562562
err = enetc_send_cmd(priv->si, &cbd);
563+
out:
564+
if (!dma_mapping_error(&priv->si->pdev->dev, dma))
565+
dma_unmap_single(&priv->si->pdev->dev, dma, data_size, DMA_FROM_DEVICE);
566+
563567
kfree(si_data);
564568

565569
return err;

0 commit comments

Comments
 (0)