Skip to content

Commit 612a7c4

Browse files
lwfingerdavem330
authored andcommitted
forcedeth: Fix WARNINGS that result when DMA mapping is not checked
With 3.8-rc1, the first call of pci_map_single() that is not checked with a corresponding pci_dma_mapping_error() call results in a warning with a splat as follows: WARNING: at lib/dma-debug.c:933 check_unmap+0x480/0x950() Hardware name: HP Pavilion dv2700 Notebook PC forcedeth 0000:00:0a.0: DMA-API: device driver failed to check map error[device address=0x00000000b176e002] [size=90 bytes] [mapped as single] Reviewed-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6817266 commit 612a7c4

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎drivers/net/ethernet/nvidia/forcedeth.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,11 @@ static int nv_alloc_rx(struct net_device *dev)
18211821
skb->data,
18221822
skb_tailroom(skb),
18231823
PCI_DMA_FROMDEVICE);
1824+
if (pci_dma_mapping_error(np->pci_dev,
1825+
np->put_rx_ctx->dma)) {
1826+
kfree_skb(skb);
1827+
goto packet_dropped;
1828+
}
18241829
np->put_rx_ctx->dma_len = skb_tailroom(skb);
18251830
np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
18261831
wmb();
@@ -1830,6 +1835,7 @@ static int nv_alloc_rx(struct net_device *dev)
18301835
if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
18311836
np->put_rx_ctx = np->first_rx_ctx;
18321837
} else {
1838+
packet_dropped:
18331839
u64_stats_update_begin(&np->swstats_rx_syncp);
18341840
np->stat_rx_dropped++;
18351841
u64_stats_update_end(&np->swstats_rx_syncp);
@@ -1856,6 +1862,11 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
18561862
skb->data,
18571863
skb_tailroom(skb),
18581864
PCI_DMA_FROMDEVICE);
1865+
if (pci_dma_mapping_error(np->pci_dev,
1866+
np->put_rx_ctx->dma)) {
1867+
kfree_skb(skb);
1868+
goto packet_dropped;
1869+
}
18591870
np->put_rx_ctx->dma_len = skb_tailroom(skb);
18601871
np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
18611872
np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
@@ -1866,6 +1877,7 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
18661877
if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
18671878
np->put_rx_ctx = np->first_rx_ctx;
18681879
} else {
1880+
packet_dropped:
18691881
u64_stats_update_begin(&np->swstats_rx_syncp);
18701882
np->stat_rx_dropped++;
18711883
u64_stats_update_end(&np->swstats_rx_syncp);
@@ -2217,6 +2229,15 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
22172229
bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
22182230
np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
22192231
PCI_DMA_TODEVICE);
2232+
if (pci_dma_mapping_error(np->pci_dev,
2233+
np->put_tx_ctx->dma)) {
2234+
/* on DMA mapping error - drop the packet */
2235+
kfree_skb(skb);
2236+
u64_stats_update_begin(&np->swstats_tx_syncp);
2237+
np->stat_tx_dropped++;
2238+
u64_stats_update_end(&np->swstats_tx_syncp);
2239+
return NETDEV_TX_OK;
2240+
}
22202241
np->put_tx_ctx->dma_len = bcnt;
22212242
np->put_tx_ctx->dma_single = 1;
22222243
put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
@@ -2337,6 +2358,15 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
23372358
bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
23382359
np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
23392360
PCI_DMA_TODEVICE);
2361+
if (pci_dma_mapping_error(np->pci_dev,
2362+
np->put_tx_ctx->dma)) {
2363+
/* on DMA mapping error - drop the packet */
2364+
kfree_skb(skb);
2365+
u64_stats_update_begin(&np->swstats_tx_syncp);
2366+
np->stat_tx_dropped++;
2367+
u64_stats_update_end(&np->swstats_tx_syncp);
2368+
return NETDEV_TX_OK;
2369+
}
23402370
np->put_tx_ctx->dma_len = bcnt;
23412371
np->put_tx_ctx->dma_single = 1;
23422372
put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
@@ -5003,6 +5033,11 @@ static int nv_loopback_test(struct net_device *dev)
50035033
test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
50045034
skb_tailroom(tx_skb),
50055035
PCI_DMA_FROMDEVICE);
5036+
if (pci_dma_mapping_error(np->pci_dev,
5037+
test_dma_addr)) {
5038+
dev_kfree_skb_any(tx_skb);
5039+
goto out;
5040+
}
50065041
pkt_data = skb_put(tx_skb, pkt_len);
50075042
for (i = 0; i < pkt_len; i++)
50085043
pkt_data[i] = (u8)(i & 0xff);

0 commit comments

Comments
 (0)