Skip to content

Commit

Permalink
sundance: Handle DMA mapping errors
Browse files Browse the repository at this point in the history
Check for DMA mapping errors.

Signed-off-by: Denis Kirjanov <dkirjanov@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Denis Kirjanov authored and David S. Miller committed Sep 22, 2010
1 parent 0c8a745 commit d91dc27
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/net/sundance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,12 @@ static void init_ring(struct net_device *dev)
np->rx_ring[i].frag[0].addr = cpu_to_le32(
dma_map_single(&np->pci_dev->dev, skb->data,
np->rx_buf_sz, DMA_FROM_DEVICE));
if (dma_mapping_error(&np->pci_dev->dev,
np->rx_ring[i].frag[0].addr)) {
dev_kfree_skb(skb);
np->rx_skbuff[i] = NULL;
break;
}
np->rx_ring[i].frag[0].length = cpu_to_le32(np->rx_buf_sz | LastFrag);
}
np->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
Expand Down Expand Up @@ -1070,6 +1076,9 @@ start_tx (struct sk_buff *skb, struct net_device *dev)
txdesc->status = cpu_to_le32 ((entry << 2) | DisableAlign);
txdesc->frag[0].addr = cpu_to_le32(dma_map_single(&np->pci_dev->dev,
skb->data, skb->len, DMA_TO_DEVICE));
if (dma_mapping_error(&np->pci_dev->dev,
txdesc->frag[0].addr))
goto drop_frame;
txdesc->frag[0].length = cpu_to_le32 (skb->len | LastFrag);

/* Increment cur_tx before tasklet_schedule() */
Expand All @@ -1091,6 +1100,12 @@ start_tx (struct sk_buff *skb, struct net_device *dev)
dev->name, np->cur_tx, entry);
}
return NETDEV_TX_OK;

drop_frame:
dev_kfree_skb(skb);
np->tx_skbuff[entry] = NULL;
dev->stats.tx_dropped++;
return NETDEV_TX_OK;
}

/* Reset hardware tx and free all of tx buffers */
Expand Down Expand Up @@ -1398,6 +1413,12 @@ static void refill_rx (struct net_device *dev)
np->rx_ring[entry].frag[0].addr = cpu_to_le32(
dma_map_single(&np->pci_dev->dev, skb->data,
np->rx_buf_sz, DMA_FROM_DEVICE));
if (dma_mapping_error(&np->pci_dev->dev,
np->rx_ring[entry].frag[0].addr)) {
dev_kfree_skb_irq(skb);
np->rx_skbuff[entry] = NULL;
break;
}
}
/* Perhaps we need not reset this field. */
np->rx_ring[entry].frag[0].length =
Expand Down

0 comments on commit d91dc27

Please sign in to comment.