Skip to content

Commit 03bb918

Browse files
chunkeeygregkh
authored andcommitted
crypto: crypto4xx - fix crypto4xx_build_pdr, crypto4xx_build_sdr leak
commit 5d59ad6 upstream. If one of the later memory allocations in rypto4xx_build_pdr() fails: dev->pdr (and/or) dev->pdr_uinfo wouldn't be freed. crypto4xx_build_sdr() has the same issue with dev->sdr. Signed-off-by: Christian Lamparter <chunkeey@googlemail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Amit Pundir <amit.pundir@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 996a6a3 commit 03bb918

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎drivers/crypto/amcc/crypto4xx_core.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev)
207207
dev->pdr_pa);
208208
return -ENOMEM;
209209
}
210-
memset(dev->pdr, 0, sizeof(struct ce_pd) * PPC4XX_NUM_PD);
210+
memset(dev->pdr, 0, sizeof(struct ce_pd) * PPC4XX_NUM_PD);
211211
dev->shadow_sa_pool = dma_alloc_coherent(dev->core_dev->device,
212212
256 * PPC4XX_NUM_PD,
213213
&dev->shadow_sa_pool_pa,
@@ -240,13 +240,15 @@ static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev)
240240

241241
static void crypto4xx_destroy_pdr(struct crypto4xx_device *dev)
242242
{
243-
if (dev->pdr != NULL)
243+
if (dev->pdr)
244244
dma_free_coherent(dev->core_dev->device,
245245
sizeof(struct ce_pd) * PPC4XX_NUM_PD,
246246
dev->pdr, dev->pdr_pa);
247+
247248
if (dev->shadow_sa_pool)
248249
dma_free_coherent(dev->core_dev->device, 256 * PPC4XX_NUM_PD,
249250
dev->shadow_sa_pool, dev->shadow_sa_pool_pa);
251+
250252
if (dev->shadow_sr_pool)
251253
dma_free_coherent(dev->core_dev->device,
252254
sizeof(struct sa_state_record) * PPC4XX_NUM_PD,
@@ -416,12 +418,12 @@ static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev)
416418

417419
static void crypto4xx_destroy_sdr(struct crypto4xx_device *dev)
418420
{
419-
if (dev->sdr != NULL)
421+
if (dev->sdr)
420422
dma_free_coherent(dev->core_dev->device,
421423
sizeof(struct ce_sd) * PPC4XX_NUM_SD,
422424
dev->sdr, dev->sdr_pa);
423425

424-
if (dev->scatter_buffer_va != NULL)
426+
if (dev->scatter_buffer_va)
425427
dma_free_coherent(dev->core_dev->device,
426428
dev->scatter_buffer_size * PPC4XX_NUM_SD,
427429
dev->scatter_buffer_va,
@@ -1191,7 +1193,7 @@ static int crypto4xx_probe(struct platform_device *ofdev)
11911193

11921194
rc = crypto4xx_build_gdr(core_dev->dev);
11931195
if (rc)
1194-
goto err_build_gdr;
1196+
goto err_build_pdr;
11951197

11961198
rc = crypto4xx_build_sdr(core_dev->dev);
11971199
if (rc)
@@ -1234,12 +1236,11 @@ static int crypto4xx_probe(struct platform_device *ofdev)
12341236
err_request_irq:
12351237
irq_dispose_mapping(core_dev->irq);
12361238
tasklet_kill(&core_dev->tasklet);
1237-
crypto4xx_destroy_sdr(core_dev->dev);
12381239
err_build_sdr:
1240+
crypto4xx_destroy_sdr(core_dev->dev);
12391241
crypto4xx_destroy_gdr(core_dev->dev);
1240-
err_build_gdr:
1241-
crypto4xx_destroy_pdr(core_dev->dev);
12421242
err_build_pdr:
1243+
crypto4xx_destroy_pdr(core_dev->dev);
12431244
kfree(core_dev->dev);
12441245
err_alloc_dev:
12451246
kfree(core_dev);

0 commit comments

Comments
 (0)