Skip to content

Commit 8e6ce7e

Browse files
ffainellidavem330
authored andcommitted
net: cavium: liquidio: Avoid dma_unmap_single on uninitialized ndata
The label lio_xmit_failed is used 3 times through liquidio_xmit() but it always makes a call to dma_unmap_single() using potentially uninitialized variables from "ndata" variable. Out of the 3 gotos, 2 run after ndata has been initialized, and had a prior dma_map_single() call. Fix this by adding a new error label: lio_xmit_dma_failed which does this dma_unmap_single() and then processed with the lio_xmit_failed fallthrough. Fixes: f21fb3e ("Add support of Cavium Liquidio ethernet adapters") Reported-by: coverity (CID 1309740) Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ea6ff11 commit 8e6ce7e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/net/ethernet/cavium/liquidio/lio_main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
28212821
if (!g) {
28222822
netif_info(lio, tx_err, lio->netdev,
28232823
"Transmit scatter gather: glist null!\n");
2824-
goto lio_xmit_failed;
2824+
goto lio_xmit_dma_failed;
28252825
}
28262826

28272827
cmdsetup.s.gather = 1;
@@ -2892,7 +2892,7 @@ static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
28922892
else
28932893
status = octnet_send_nic_data_pkt(oct, &ndata, xmit_more);
28942894
if (status == IQ_SEND_FAILED)
2895-
goto lio_xmit_failed;
2895+
goto lio_xmit_dma_failed;
28962896

28972897
netif_info(lio, tx_queued, lio->netdev, "Transmit queued successfully\n");
28982898

@@ -2906,12 +2906,13 @@ static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
29062906

29072907
return NETDEV_TX_OK;
29082908

2909+
lio_xmit_dma_failed:
2910+
dma_unmap_single(&oct->pci_dev->dev, ndata.cmd.dptr,
2911+
ndata.datasize, DMA_TO_DEVICE);
29092912
lio_xmit_failed:
29102913
stats->tx_dropped++;
29112914
netif_info(lio, tx_err, lio->netdev, "IQ%d Transmit dropped:%llu\n",
29122915
iq_no, stats->tx_dropped);
2913-
dma_unmap_single(&oct->pci_dev->dev, ndata.cmd.dptr,
2914-
ndata.datasize, DMA_TO_DEVICE);
29152916
recv_buffer_free(skb);
29162917
return NETDEV_TX_OK;
29172918
}

0 commit comments

Comments
 (0)