Skip to content

Commit 71791dc

Browse files
Andre-ARMdavem330
authored andcommitted
net: axienet: Check for DMA mapping errors
Especially with the default 32-bit DMA mask, DMA buffers are a limited resource, so their allocation can fail. So as the DMA API documentation requires, add error checking code after dma_map_single() calls to catch the case where we run out of "low" memory. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ab365c3 commit 71791dc

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

drivers/net/ethernet/xilinx/xilinx_axienet_main.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ static int axienet_dma_bd_init(struct net_device *ndev)
248248
skb->data,
249249
lp->max_frm_size,
250250
DMA_FROM_DEVICE);
251+
if (dma_mapping_error(ndev->dev.parent, lp->rx_bd_v[i].phys)) {
252+
netdev_err(ndev, "DMA mapping error\n");
253+
goto out;
254+
}
255+
251256
lp->rx_bd_v[i].cntrl = lp->max_frm_size;
252257
}
253258

@@ -679,6 +684,7 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
679684
dma_addr_t tail_p;
680685
struct axienet_local *lp = netdev_priv(ndev);
681686
struct axidma_bd *cur_p;
687+
u32 orig_tail_ptr = lp->tx_bd_tail;
682688

683689
num_frag = skb_shinfo(skb)->nr_frags;
684690
cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
@@ -714,9 +720,15 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
714720
cur_p->app0 |= 2; /* Tx Full Checksum Offload Enabled */
715721
}
716722

717-
cur_p->cntrl = skb_headlen(skb) | XAXIDMA_BD_CTRL_TXSOF_MASK;
718723
cur_p->phys = dma_map_single(ndev->dev.parent, skb->data,
719724
skb_headlen(skb), DMA_TO_DEVICE);
725+
if (unlikely(dma_mapping_error(ndev->dev.parent, cur_p->phys))) {
726+
if (net_ratelimit())
727+
netdev_err(ndev, "TX DMA mapping error\n");
728+
ndev->stats.tx_dropped++;
729+
return NETDEV_TX_OK;
730+
}
731+
cur_p->cntrl = skb_headlen(skb) | XAXIDMA_BD_CTRL_TXSOF_MASK;
720732

721733
for (ii = 0; ii < num_frag; ii++) {
722734
if (++lp->tx_bd_tail >= lp->tx_bd_num)
@@ -727,6 +739,16 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
727739
skb_frag_address(frag),
728740
skb_frag_size(frag),
729741
DMA_TO_DEVICE);
742+
if (unlikely(dma_mapping_error(ndev->dev.parent, cur_p->phys))) {
743+
if (net_ratelimit())
744+
netdev_err(ndev, "TX DMA mapping error\n");
745+
ndev->stats.tx_dropped++;
746+
axienet_free_tx_chain(ndev, orig_tail_ptr, ii + 1,
747+
NULL);
748+
lp->tx_bd_tail = orig_tail_ptr;
749+
750+
return NETDEV_TX_OK;
751+
}
730752
cur_p->cntrl = skb_frag_size(frag);
731753
}
732754

@@ -807,6 +829,13 @@ static void axienet_recv(struct net_device *ndev)
807829
cur_p->phys = dma_map_single(ndev->dev.parent, new_skb->data,
808830
lp->max_frm_size,
809831
DMA_FROM_DEVICE);
832+
if (unlikely(dma_mapping_error(ndev->dev.parent, cur_p->phys))) {
833+
if (net_ratelimit())
834+
netdev_err(ndev, "RX DMA mapping error\n");
835+
dev_kfree_skb(new_skb);
836+
return;
837+
}
838+
810839
cur_p->cntrl = lp->max_frm_size;
811840
cur_p->status = 0;
812841
cur_p->skb = new_skb;

0 commit comments

Comments
 (0)