Skip to content

Commit 03e3f54

Browse files
Thomas-fourierNipaLocal
authored andcommitted
net: ag71xx: Add missing check after DMA map
The DMA map functions can fail and should be tested for errors. Fixes: d51b6ce ("net: ethernet: add ag71xx driver") Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: NipaLocal <nipa@local>
1 parent 99c2baf commit 03e3f54

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/net/ethernet/atheros/ag71xx.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ static int ag71xx_buffer_size(struct ag71xx *ag)
11981198

11991199
static bool ag71xx_fill_rx_buf(struct ag71xx *ag, struct ag71xx_buf *buf,
12001200
int offset,
1201-
void *(*alloc)(unsigned int size))
1201+
void *(*alloc)(unsigned int size),
1202+
void (*free)(void *))
12021203
{
12031204
struct ag71xx_ring *ring = &ag->rx_ring;
12041205
struct ag71xx_desc *desc;
@@ -1213,6 +1214,11 @@ static bool ag71xx_fill_rx_buf(struct ag71xx *ag, struct ag71xx_buf *buf,
12131214
buf->rx.rx_buf = data;
12141215
buf->rx.dma_addr = dma_map_single(&ag->pdev->dev, data, ag->rx_buf_size,
12151216
DMA_FROM_DEVICE);
1217+
if (dma_mapping_error(&ag->pdev->dev, buf->rx.dma_addr)) {
1218+
free(data);
1219+
buf->rx.rx_buf = NULL;
1220+
return false;
1221+
}
12161222
desc->data = (u32)buf->rx.dma_addr + offset;
12171223
return true;
12181224
}
@@ -1241,7 +1247,7 @@ static int ag71xx_ring_rx_init(struct ag71xx *ag)
12411247
struct ag71xx_desc *desc = ag71xx_ring_desc(ring, i);
12421248

12431249
if (!ag71xx_fill_rx_buf(ag, &ring->buf[i], ag->rx_buf_offset,
1244-
netdev_alloc_frag)) {
1250+
netdev_alloc_frag, skb_free_frag)) {
12451251
ret = -ENOMEM;
12461252
break;
12471253
}
@@ -1275,7 +1281,7 @@ static int ag71xx_ring_rx_refill(struct ag71xx *ag)
12751281

12761282
if (!ring->buf[i].rx.rx_buf &&
12771283
!ag71xx_fill_rx_buf(ag, &ring->buf[i], offset,
1278-
napi_alloc_frag))
1284+
napi_alloc_frag, skb_free_frag))
12791285
break;
12801286

12811287
desc->ctrl = DESC_EMPTY;
@@ -1511,6 +1517,10 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
15111517

15121518
dma_addr = dma_map_single(&ag->pdev->dev, skb->data, skb->len,
15131519
DMA_TO_DEVICE);
1520+
if (dma_mapping_error(&ag->pdev->dev, dma_addr)) {
1521+
netif_dbg(ag, tx_err, ndev, "DMA mapping error\n");
1522+
goto err_drop;
1523+
}
15141524

15151525
i = ring->curr & ring_mask;
15161526
desc = ag71xx_ring_desc(ring, i);

0 commit comments

Comments
 (0)