Skip to content

Commit 4776d38

Browse files
himangi774herbertx
authored andcommitted
crypto: caam - Introduce the use of the managed version of kzalloc
This patch moves data allocated using kzalloc to managed data allocated using devm_kzalloc and cleans now unnecessary kfrees in probe and remove functions. Also, linux/device.h is added to make sure the devm_*() routine declarations are unambiguously available. Earlier, in the probe function ctrlpriv was leaked on the failure of ctrl = of_iomap(nprop, 0); as well as on the failure of ctrlpriv->jrpdev = kzalloc(...); . These two bugs have been fixed by the patch. The following Coccinelle semantic patch was used for making the change: identifier p, probefn, removefn; @@ struct platform_driver p = { .probe = probefn, .remove = removefn, }; @prb@ identifier platform.probefn, pdev; expression e, e1, e2; @@ probefn(struct platform_device *pdev, ...) { <+... - e = kzalloc(e1, e2) + e = devm_kzalloc(&pdev->dev, e1, e2) ... ?-kfree(e); ...+> } @Rem depends on prb@ identifier platform.removefn; expression e; @@ removefn(...) { <... - kfree(e); ...> } Signed-off-by: Himangi Saraogi <himangi774@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Reviewed-by: Marek Vasut <marex@denx.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 42614b0 commit 4776d38

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎drivers/crypto/caam/ctrl.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright 2008-2012 Freescale Semiconductor, Inc.
66
*/
77

8+
#include <linux/device.h>
89
#include <linux/of_address.h>
910
#include <linux/of_irq.h>
1011

@@ -295,9 +296,6 @@ static int caam_remove(struct platform_device *pdev)
295296
/* Unmap controller region */
296297
iounmap(&topregs->ctrl);
297298

298-
kfree(ctrlpriv->jrpdev);
299-
kfree(ctrlpriv);
300-
301299
return ret;
302300
}
303301

@@ -382,7 +380,8 @@ static int caam_probe(struct platform_device *pdev)
382380
#endif
383381
u64 cha_vid;
384382

385-
ctrlpriv = kzalloc(sizeof(struct caam_drv_private), GFP_KERNEL);
383+
ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(struct caam_drv_private),
384+
GFP_KERNEL);
386385
if (!ctrlpriv)
387386
return -ENOMEM;
388387

@@ -432,8 +431,9 @@ static int caam_probe(struct platform_device *pdev)
432431
of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
433432
rspec++;
434433

435-
ctrlpriv->jrpdev = kzalloc(sizeof(struct platform_device *) * rspec,
436-
GFP_KERNEL);
434+
ctrlpriv->jrpdev = devm_kzalloc(&pdev->dev,
435+
sizeof(struct platform_device *) * rspec,
436+
GFP_KERNEL);
437437
if (ctrlpriv->jrpdev == NULL) {
438438
iounmap(&topregs->ctrl);
439439
return -ENOMEM;

0 commit comments

Comments
 (0)