Skip to content

Commit 00e8744

Browse files
tasksetherbertx
authored andcommitted
crypto: caam - add missing put_device() call
The of_find_device_by_node() takes a reference to the underlying device structure, we should release that reference. Fixes: 35af640 ("crypto: caam - Check for CAAM block presence before registering with crypto layer") Fixes: b189817 ("crypto: caam/qi - add ablkcipher and authenc algorithms") Reviewed-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Wen Yang <yellowriver2010@hotmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent aa1abbe commit 00e8744

File tree

5 files changed

+50
-27
lines changed

5 files changed

+50
-27
lines changed

drivers/crypto/caam/caamalg.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,6 @@ static int __init caam_algapi_init(void)
34553455
{
34563456
struct device_node *dev_node;
34573457
struct platform_device *pdev;
3458-
struct device *ctrldev;
34593458
struct caam_drv_private *priv;
34603459
int i = 0, err = 0;
34613460
u32 aes_vid, aes_inst, des_inst, md_vid, md_inst, ccha_inst, ptha_inst;
@@ -3476,16 +3475,17 @@ static int __init caam_algapi_init(void)
34763475
return -ENODEV;
34773476
}
34783477

3479-
ctrldev = &pdev->dev;
3480-
priv = dev_get_drvdata(ctrldev);
3478+
priv = dev_get_drvdata(&pdev->dev);
34813479
of_node_put(dev_node);
34823480

34833481
/*
34843482
* If priv is NULL, it's probably because the caam driver wasn't
34853483
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
34863484
*/
3487-
if (!priv)
3488-
return -ENODEV;
3485+
if (!priv) {
3486+
err = -ENODEV;
3487+
goto out_put_dev;
3488+
}
34893489

34903490

34913491
/*
@@ -3626,6 +3626,8 @@ static int __init caam_algapi_init(void)
36263626
if (registered)
36273627
pr_info("caam algorithms registered in /proc/crypto\n");
36283628

3629+
out_put_dev:
3630+
put_device(&pdev->dev);
36293631
return err;
36303632
}
36313633

drivers/crypto/caam/caamalg_qi.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,12 +2492,15 @@ static int __init caam_qi_algapi_init(void)
24922492
* If priv is NULL, it's probably because the caam driver wasn't
24932493
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
24942494
*/
2495-
if (!priv || !priv->qi_present)
2496-
return -ENODEV;
2495+
if (!priv || !priv->qi_present) {
2496+
err = -ENODEV;
2497+
goto out_put_dev;
2498+
}
24972499

24982500
if (caam_dpaa2) {
24992501
dev_info(ctrldev, "caam/qi frontend driver not suitable for DPAA 2.x, aborting...\n");
2500-
return -ENODEV;
2502+
err = -ENODEV;
2503+
goto out_put_dev;
25012504
}
25022505

25032506
/*
@@ -2610,6 +2613,8 @@ static int __init caam_qi_algapi_init(void)
26102613
if (registered)
26112614
dev_info(priv->qidev, "algorithms registered in /proc/crypto\n");
26122615

2616+
out_put_dev:
2617+
put_device(ctrldev);
26132618
return err;
26142619
}
26152620

drivers/crypto/caam/caamhash.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,6 @@ static int __init caam_algapi_hash_init(void)
19931993
{
19941994
struct device_node *dev_node;
19951995
struct platform_device *pdev;
1996-
struct device *ctrldev;
19971996
int i = 0, err = 0;
19981997
struct caam_drv_private *priv;
19991998
unsigned int md_limit = SHA512_DIGEST_SIZE;
@@ -2012,16 +2011,17 @@ static int __init caam_algapi_hash_init(void)
20122011
return -ENODEV;
20132012
}
20142013

2015-
ctrldev = &pdev->dev;
2016-
priv = dev_get_drvdata(ctrldev);
2014+
priv = dev_get_drvdata(&pdev->dev);
20172015
of_node_put(dev_node);
20182016

20192017
/*
20202018
* If priv is NULL, it's probably because the caam driver wasn't
20212019
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
20222020
*/
2023-
if (!priv)
2024-
return -ENODEV;
2021+
if (!priv) {
2022+
err = -ENODEV;
2023+
goto out_put_dev;
2024+
}
20252025

20262026
/*
20272027
* Register crypto algorithms the device supports. First, identify
@@ -2043,8 +2043,10 @@ static int __init caam_algapi_hash_init(void)
20432043
* Skip registration of any hashing algorithms if MD block
20442044
* is not present.
20452045
*/
2046-
if (!md_inst)
2047-
return -ENODEV;
2046+
if (!md_inst) {
2047+
err = -ENODEV;
2048+
goto out_put_dev;
2049+
}
20482050

20492051
/* Limit digest size based on LP256 */
20502052
if (md_vid == CHA_VER_VID_MD_LP256)
@@ -2101,6 +2103,8 @@ static int __init caam_algapi_hash_init(void)
21012103
list_add_tail(&t_alg->entry, &hash_list);
21022104
}
21032105

2106+
out_put_dev:
2107+
put_device(&pdev->dev);
21042108
return err;
21052109
}
21062110

drivers/crypto/caam/caampkc.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,10 @@ static int __init caam_pkc_init(void)
10421042
* If priv is NULL, it's probably because the caam driver wasn't
10431043
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
10441044
*/
1045-
if (!priv)
1046-
return -ENODEV;
1045+
if (!priv) {
1046+
err = -ENODEV;
1047+
goto out_put_dev;
1048+
}
10471049

10481050
/* Determine public key hardware accelerator presence. */
10491051
if (priv->era < 10)
@@ -1053,8 +1055,10 @@ static int __init caam_pkc_init(void)
10531055
pk_inst = rd_reg32(&priv->ctrl->vreg.pkha) & CHA_VER_NUM_MASK;
10541056

10551057
/* Do not register algorithms if PKHA is not present. */
1056-
if (!pk_inst)
1057-
return -ENODEV;
1058+
if (!pk_inst) {
1059+
err = -ENODEV;
1060+
goto out_put_dev;
1061+
}
10581062

10591063
err = crypto_register_akcipher(&caam_rsa);
10601064
if (err)
@@ -1063,6 +1067,8 @@ static int __init caam_pkc_init(void)
10631067
else
10641068
dev_info(ctrldev, "caam pkc algorithms registered in /proc/crypto\n");
10651069

1070+
out_put_dev:
1071+
put_device(ctrldev);
10661072
return err;
10671073
}
10681074

drivers/crypto/caam/caamrng.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ static int __init caam_rng_init(void)
308308
struct device *dev;
309309
struct device_node *dev_node;
310310
struct platform_device *pdev;
311-
struct device *ctrldev;
312311
struct caam_drv_private *priv;
313312
u32 rng_inst;
314313
int err;
@@ -326,16 +325,17 @@ static int __init caam_rng_init(void)
326325
return -ENODEV;
327326
}
328327

329-
ctrldev = &pdev->dev;
330-
priv = dev_get_drvdata(ctrldev);
328+
priv = dev_get_drvdata(&pdev->dev);
331329
of_node_put(dev_node);
332330

333331
/*
334332
* If priv is NULL, it's probably because the caam driver wasn't
335333
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
336334
*/
337-
if (!priv)
338-
return -ENODEV;
335+
if (!priv) {
336+
err = -ENODEV;
337+
goto out_put_dev;
338+
}
339339

340340
/* Check for an instantiated RNG before registration */
341341
if (priv->era < 10)
@@ -344,13 +344,16 @@ static int __init caam_rng_init(void)
344344
else
345345
rng_inst = rd_reg32(&priv->ctrl->vreg.rng) & CHA_VER_NUM_MASK;
346346

347-
if (!rng_inst)
348-
return -ENODEV;
347+
if (!rng_inst) {
348+
err = -ENODEV;
349+
goto out_put_dev;
350+
}
349351

350352
dev = caam_jr_alloc();
351353
if (IS_ERR(dev)) {
352354
pr_err("Job Ring Device allocation for transform failed\n");
353-
return PTR_ERR(dev);
355+
err = PTR_ERR(dev);
356+
goto out_put_dev;
354357
}
355358
rng_ctx = kmalloc(sizeof(*rng_ctx), GFP_DMA | GFP_KERNEL);
356359
if (!rng_ctx) {
@@ -361,13 +364,16 @@ static int __init caam_rng_init(void)
361364
if (err)
362365
goto free_rng_ctx;
363366

367+
put_device(&pdev->dev);
364368
dev_info(dev, "registering rng-caam\n");
365369
return hwrng_register(&caam_rng);
366370

367371
free_rng_ctx:
368372
kfree(rng_ctx);
369373
free_caam_alloc:
370374
caam_jr_free(dev);
375+
out_put_dev:
376+
put_device(&pdev->dev);
371377
return err;
372378
}
373379

0 commit comments

Comments
 (0)