linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: caam: Introduce the use of the managed version of kzalloc
@ 2014-05-27 18:25 Himangi Saraogi
  2014-06-01 16:56 ` Marek Vasut
  0 siblings, 1 reply; 3+ messages in thread
From: Himangi Saraogi @ 2014-05-27 18:25 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller, linux-crypto, linux-kernel; +Cc: julia.lawall

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>
---
Not compile tested due to incompatible architecture.

 drivers/crypto/caam/ctrl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 1c38f86..34ffc35 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -5,6 +5,7 @@
  * Copyright 2008-2012 Freescale Semiconductor, Inc.
  */
 
+#include <linux/device.h>
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 
@@ -295,9 +296,6 @@ static int caam_remove(struct platform_device *pdev)
 	/* Unmap controller region */
 	iounmap(&topregs->ctrl);
 
-	kfree(ctrlpriv->jrpdev);
-	kfree(ctrlpriv);
-
 	return ret;
 }
 
@@ -382,7 +380,8 @@ static int caam_probe(struct platform_device *pdev)
 #endif
 	u64 cha_vid;
 
-	ctrlpriv = kzalloc(sizeof(struct caam_drv_private), GFP_KERNEL);
+	ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(struct caam_drv_private),
+				GFP_KERNEL);
 	if (!ctrlpriv)
 		return -ENOMEM;
 
@@ -432,8 +431,9 @@ static int caam_probe(struct platform_device *pdev)
 		    of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
 			rspec++;
 
-	ctrlpriv->jrpdev = kzalloc(sizeof(struct platform_device *) * rspec,
-								GFP_KERNEL);
+	ctrlpriv->jrpdev = devm_kzalloc(&pdev->dev,
+					sizeof(struct platform_device *) * rspec,
+					GFP_KERNEL);
 	if (ctrlpriv->jrpdev == NULL) {
 		iounmap(&topregs->ctrl);
 		return -ENOMEM;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: caam: Introduce the use of the managed version of kzalloc
  2014-05-27 18:25 [PATCH] crypto: caam: Introduce the use of the managed version of kzalloc Himangi Saraogi
@ 2014-06-01 16:56 ` Marek Vasut
  2014-06-20 18:41   ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2014-06-01 16:56 UTC (permalink / raw)
  To: Himangi Saraogi
  Cc: Herbert Xu, David S. Miller, linux-crypto, linux-kernel,
	julia.lawall

On Tuesday, May 27, 2014 at 08:25:48 PM, Himangi Saraogi wrote:
> 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:

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: caam: Introduce the use of the managed version of kzalloc
  2014-06-01 16:56 ` Marek Vasut
@ 2014-06-20 18:41   ` Herbert Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2014-06-20 18:41 UTC (permalink / raw)
  To: Marek Vasut
  Cc: Himangi Saraogi, David S. Miller, linux-crypto, linux-kernel,
	julia.lawall

On Sun, Jun 01, 2014 at 06:56:41PM +0200, Marek Vasut wrote:
> On Tuesday, May 27, 2014 at 08:25:48 PM, Himangi Saraogi wrote:
> > 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:
> 
> Reviewed-by: Marek Vasut <marex@denx.de>

Patch applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-20 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-27 18:25 [PATCH] crypto: caam: Introduce the use of the managed version of kzalloc Himangi Saraogi
2014-06-01 16:56 ` Marek Vasut
2014-06-20 18:41   ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).