Johnny Hughes
2019-02-04 c1f36c28393a7bb126cbf436cd6a4077a5b5c313
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From 7be8a46cfb0d162f7733ccd6dd57810285a0ce9e Mon Sep 17 00:00:00 2001
From: Antoine Tenart <antoine.tenart@free-electrons.com>
Date: Tue, 28 Nov 2017 14:19:48 +0100
Subject: [PATCH 10/46] net: mvpp2: fix the txq_init error path
 
When an allocation in the txq_init path fails, the allocated buffers
end-up being freed twice: in the txq_init error path, and in txq_deinit.
This lead to issues as txq_deinit would work on already freed memory
regions:
 
    kernel BUG at mm/slub.c:3915!
    Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
 
This patch fixes this by removing the txq_init own error path, as the
txq_deinit function is always called on errors. This was introduced by
TSO as way more buffers are allocated.
 
Fixes: 186cd4d4e414 ("net: mvpp2: software tso support")
Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit ba2d8d887d962c2f790e6dc01b2fd25b4608720b)
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 drivers/net/ethernet/marvell/mvpp2.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)
 
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index 6c20e81..79f01cd 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -5805,7 +5805,7 @@ static int mvpp2_txq_init(struct mvpp2_port *port,
                         sizeof(*txq_pcpu->buffs),
                         GFP_KERNEL);
         if (!txq_pcpu->buffs)
-            goto cleanup;
+            return -ENOMEM;
 
         txq_pcpu->count = 0;
         txq_pcpu->reserved_num = 0;
@@ -5821,26 +5821,10 @@ static int mvpp2_txq_init(struct mvpp2_port *port,
                        &txq_pcpu->tso_headers_dma,
                        GFP_KERNEL);
         if (!txq_pcpu->tso_headers)
-            goto cleanup;
+            return -ENOMEM;
     }
 
     return 0;
-cleanup:
-    for_each_present_cpu(cpu) {
-        txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
-        kfree(txq_pcpu->buffs);
-
-        dma_free_coherent(port->dev->dev.parent,
-                  txq_pcpu->size * TSO_HEADER_SIZE,
-                  txq_pcpu->tso_headers,
-                  txq_pcpu->tso_headers_dma);
-    }
-
-    dma_free_coherent(port->dev->dev.parent,
-              txq->size * MVPP2_DESC_ALIGNED_SIZE,
-              txq->descs, txq->descs_dma);
-
-    return -ENOMEM;
 }
 
 /* Free allocated TXQ resources */
-- 
2.7.4