Skip to content

Commit 892a925

Browse files
françois romieudavem330
authored andcommitted
8139cp: fix coherent mapping leak in error path.
cp_open [...] rc = cp_alloc_rings(cp); if (rc) return rc; cp_alloc_rings [...] mem = dma_alloc_coherent(&cp->pdev->dev, CP_RING_BYTES, &cp->ring_dma, GFP_KERNEL); - cp_alloc_rings never frees the coherent mapping it allocates - neither do cp_open when cp_alloc_rings fails Signed-off-by: Francois Romieu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 64022d0 commit 892a925

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/net/ethernet/realtek/8139cp.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,17 +1060,22 @@ static int cp_init_rings (struct cp_private *cp)
10601060

10611061
static int cp_alloc_rings (struct cp_private *cp)
10621062
{
1063+
struct device *d = &cp->pdev->dev;
10631064
void *mem;
1065+
int rc;
10641066

1065-
mem = dma_alloc_coherent(&cp->pdev->dev, CP_RING_BYTES,
1066-
&cp->ring_dma, GFP_KERNEL);
1067+
mem = dma_alloc_coherent(d, CP_RING_BYTES, &cp->ring_dma, GFP_KERNEL);
10671068
if (!mem)
10681069
return -ENOMEM;
10691070

10701071
cp->rx_ring = mem;
10711072
cp->tx_ring = &cp->rx_ring[CP_RX_RING_SIZE];
10721073

1073-
return cp_init_rings(cp);
1074+
rc = cp_init_rings(cp);
1075+
if (rc < 0)
1076+
dma_free_coherent(d, CP_RING_BYTES, cp->rx_ring, cp->ring_dma);
1077+
1078+
return rc;
10741079
}
10751080

10761081
static void cp_clean_rings (struct cp_private *cp)

0 commit comments

Comments
 (0)