Skip to content

Commit 65946ea

Browse files
Cruzer-Sdavem330
authored andcommitted
net: dlink: handle dma_map_single() failure properly
There is no error handling for `dma_map_single()` failures. Add error handling by checking `dma_mapping_error()` and freeing the `skb` using `dev_kfree_skb()` (process context) when it fails. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Yeounsu Moon <yyyynoom@gmail.com> Tested-on: D-Link DGE-550T Rev-A3 Suggested-by: Simon Horman <horms@kernel.org> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3abc0e5 commit 65946ea

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

drivers/net/ethernet/dlink/dl2k.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,25 +508,34 @@ static int alloc_list(struct net_device *dev)
508508
for (i = 0; i < RX_RING_SIZE; i++) {
509509
/* Allocated fixed size of skbuff */
510510
struct sk_buff *skb;
511+
dma_addr_t addr;
511512

512513
skb = netdev_alloc_skb_ip_align(dev, np->rx_buf_sz);
513514
np->rx_skbuff[i] = skb;
514-
if (!skb) {
515-
free_list(dev);
516-
return -ENOMEM;
517-
}
515+
if (!skb)
516+
goto err_free_list;
517+
518+
addr = dma_map_single(&np->pdev->dev, skb->data,
519+
np->rx_buf_sz, DMA_FROM_DEVICE);
520+
if (dma_mapping_error(&np->pdev->dev, addr))
521+
goto err_kfree_skb;
518522

519523
np->rx_ring[i].next_desc = cpu_to_le64(np->rx_ring_dma +
520524
((i + 1) % RX_RING_SIZE) *
521525
sizeof(struct netdev_desc));
522526
/* Rubicon now supports 40 bits of addressing space. */
523-
np->rx_ring[i].fraginfo =
524-
cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
525-
np->rx_buf_sz, DMA_FROM_DEVICE));
527+
np->rx_ring[i].fraginfo = cpu_to_le64(addr);
526528
np->rx_ring[i].fraginfo |= cpu_to_le64((u64)np->rx_buf_sz << 48);
527529
}
528530

529531
return 0;
532+
533+
err_kfree_skb:
534+
dev_kfree_skb(np->rx_skbuff[i]);
535+
np->rx_skbuff[i] = NULL;
536+
err_free_list:
537+
free_list(dev);
538+
return -ENOMEM;
530539
}
531540

532541
static void rio_hw_init(struct net_device *dev)

0 commit comments

Comments
 (0)