Commit a21771dd authored by Matt Carlson's avatar Matt Carlson Committed by David S. Miller

tg3: Add more PCI DMA map error checking

This patch adds code to check the status of pci_map_single() before
allowing rx buffers to be used.  It also converts the pci_map_single()
call in tg3_run_loopback() to use skb_dma_map() instead.
Signed-off-by: default avatarMatt Carlson <mcarlson@broadcom.com>
Signed-off-by: default avatarMichael Chan <mchan@broadcom.com>
Signed-off-by: default avatarBenjamin Li <benli@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52cdf852
...@@ -4426,6 +4426,10 @@ static int tg3_alloc_rx_skb(struct tg3_napi *tnapi, u32 opaque_key, ...@@ -4426,6 +4426,10 @@ static int tg3_alloc_rx_skb(struct tg3_napi *tnapi, u32 opaque_key,
mapping = pci_map_single(tp->pdev, skb->data, skb_size, mapping = pci_map_single(tp->pdev, skb->data, skb_size,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if (pci_dma_mapping_error(tp->pdev, mapping)) {
dev_kfree_skb(skb);
return -EIO;
}
map->skb = skb; map->skb = skb;
pci_unmap_addr_set(map, mapping, mapping); pci_unmap_addr_set(map, mapping, mapping);
...@@ -10369,7 +10373,10 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) ...@@ -10369,7 +10373,10 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
for (i = 14; i < tx_len; i++) for (i = 14; i < tx_len; i++)
tx_data[i] = (u8) (i & 0xff); tx_data[i] = (u8) (i & 0xff);
map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); if (skb_dma_map(&tp->pdev->dev, skb, DMA_TO_DEVICE)) {
dev_kfree_skb(skb);
return -EIO;
}
tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
rnapi->coal_now); rnapi->coal_now);
...@@ -10380,7 +10387,8 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) ...@@ -10380,7 +10387,8 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
num_pkts = 0; num_pkts = 0;
tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, 0, 1); tg3_set_txd(tnapi, tnapi->tx_prod,
skb_shinfo(skb)->dma_head, tx_len, 0, 1);
tnapi->tx_prod++; tnapi->tx_prod++;
num_pkts++; num_pkts++;
...@@ -10404,7 +10412,7 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) ...@@ -10404,7 +10412,7 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
break; break;
} }
pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); skb_dma_unmap(&tp->pdev->dev, skb, DMA_TO_DEVICE);
dev_kfree_skb(skb); dev_kfree_skb(skb);
if (tx_idx != tnapi->tx_prod) if (tx_idx != tnapi->tx_prod)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment