837fbdc547a984a298cf6f7989ea27141fb7bcea
[openwrt/openwrt.git] / target / linux / apm821xx / patches-4.14 / 020-0011-crypto-crypto4xx-fix-crypto4xx_build_pdr-crypto4xx_b.patch
1 From 5d59ad6eea82ef8df92b4109615a0dde9d8093e9 Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@googlemail.com>
3 Date: Fri, 25 Aug 2017 15:47:24 +0200
4 Subject: [PATCH 11/25] crypto: crypto4xx - fix crypto4xx_build_pdr,
5 crypto4xx_build_sdr leak
6
7 If one of the later memory allocations in rypto4xx_build_pdr()
8 fails: dev->pdr (and/or) dev->pdr_uinfo wouldn't be freed.
9
10 crypto4xx_build_sdr() has the same issue with dev->sdr.
11
12 Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
13 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
14 ---
15 drivers/crypto/amcc/crypto4xx_core.c | 17 +++++++++--------
16 1 file changed, 9 insertions(+), 8 deletions(-)
17
18 --- a/drivers/crypto/amcc/crypto4xx_core.c
19 +++ b/drivers/crypto/amcc/crypto4xx_core.c
20 @@ -209,7 +209,7 @@ static u32 crypto4xx_build_pdr(struct cr
21 dev->pdr_pa);
22 return -ENOMEM;
23 }
24 - memset(dev->pdr, 0, sizeof(struct ce_pd) * PPC4XX_NUM_PD);
25 + memset(dev->pdr, 0, sizeof(struct ce_pd) * PPC4XX_NUM_PD);
26 dev->shadow_sa_pool = dma_alloc_coherent(dev->core_dev->device,
27 256 * PPC4XX_NUM_PD,
28 &dev->shadow_sa_pool_pa,
29 @@ -242,13 +242,15 @@ static u32 crypto4xx_build_pdr(struct cr
30
31 static void crypto4xx_destroy_pdr(struct crypto4xx_device *dev)
32 {
33 - if (dev->pdr != NULL)
34 + if (dev->pdr)
35 dma_free_coherent(dev->core_dev->device,
36 sizeof(struct ce_pd) * PPC4XX_NUM_PD,
37 dev->pdr, dev->pdr_pa);
38 +
39 if (dev->shadow_sa_pool)
40 dma_free_coherent(dev->core_dev->device, 256 * PPC4XX_NUM_PD,
41 dev->shadow_sa_pool, dev->shadow_sa_pool_pa);
42 +
43 if (dev->shadow_sr_pool)
44 dma_free_coherent(dev->core_dev->device,
45 sizeof(struct sa_state_record) * PPC4XX_NUM_PD,
46 @@ -417,12 +419,12 @@ static u32 crypto4xx_build_sdr(struct cr
47
48 static void crypto4xx_destroy_sdr(struct crypto4xx_device *dev)
49 {
50 - if (dev->sdr != NULL)
51 + if (dev->sdr)
52 dma_free_coherent(dev->core_dev->device,
53 sizeof(struct ce_sd) * PPC4XX_NUM_SD,
54 dev->sdr, dev->sdr_pa);
55
56 - if (dev->scatter_buffer_va != NULL)
57 + if (dev->scatter_buffer_va)
58 dma_free_coherent(dev->core_dev->device,
59 PPC4XX_SD_BUFFER_SIZE * PPC4XX_NUM_SD,
60 dev->scatter_buffer_va,
61 @@ -1223,7 +1225,7 @@ static int crypto4xx_probe(struct platfo
62
63 rc = crypto4xx_build_gdr(core_dev->dev);
64 if (rc)
65 - goto err_build_gdr;
66 + goto err_build_pdr;
67
68 rc = crypto4xx_build_sdr(core_dev->dev);
69 if (rc)
70 @@ -1266,12 +1268,11 @@ err_iomap:
71 err_request_irq:
72 irq_dispose_mapping(core_dev->irq);
73 tasklet_kill(&core_dev->tasklet);
74 - crypto4xx_destroy_sdr(core_dev->dev);
75 err_build_sdr:
76 + crypto4xx_destroy_sdr(core_dev->dev);
77 crypto4xx_destroy_gdr(core_dev->dev);
78 -err_build_gdr:
79 - crypto4xx_destroy_pdr(core_dev->dev);
80 err_build_pdr:
81 + crypto4xx_destroy_pdr(core_dev->dev);
82 kfree(core_dev->dev);
83 err_alloc_dev:
84 kfree(core_dev);