linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nadim Almas <nadim.902@gmail.com>
To: julia.lawall@lip6.fr, lee.jones@linaro.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Mfd: used devm_kzalloc in place of kzalloc
Date: Sun, 6 Nov 2016 00:53:45 +0530	[thread overview]
Message-ID: <20161105192345.GA9854@gmail.com> (raw)

Switch to resource-managed function devm_kzalloc instead
of kzalloc and remove unneeded kzfree

Remove kfree in probe function and  remove
function as it is now has nothing to do

The Coccinelle semantic patch used to make this change is as follows:
//<smpl>
@platform@
identifier p, probefn, removefn;
@@

struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2,x;
@@
probefn(struct platform_device *pdev, ...) {
... when != x = f(...);
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
-kfree(e);
... when != g(...);

}
@rem depends on prb@
identifier platform.removefn;
expression prb.e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
//</smpl>

Signed-off-by: Nadim Almas <nadim.902@gmail.com>
---
 drivers/mfd/t7l66xb.c  | 4 +---
 drivers/mfd/tc6387xb.c | 4 +---
 drivers/mfd/tc6393xb.c | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index 94bd89c..9a2086b 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -317,7 +317,7 @@ static int t7l66xb_probe(struct platform_device *dev)
 	if (!iomem)
 		return -EINVAL;
 
-	t7l66xb = kzalloc(sizeof *t7l66xb, GFP_KERNEL);
+	t7l66xb = devm_kzalloc(&dev->dev, sizeof(*t7l66xb), GFP_KERNEL);
 	if (!t7l66xb)
 		return -ENOMEM;
 
@@ -395,7 +395,6 @@ static int t7l66xb_probe(struct platform_device *dev)
 	clk_put(t7l66xb->clk32k);
 err_clk32k_get:
 err_noirq:
-	kfree(t7l66xb);
 	return ret;
 }
 
@@ -414,7 +413,6 @@ static int t7l66xb_remove(struct platform_device *dev)
 	iounmap(t7l66xb->scr);
 	release_resource(&t7l66xb->rscr);
 	mfd_remove_devices(&dev->dev);
-	kfree(t7l66xb);
 
 	return ret;
 
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c
index 85fab37..aaab422 100644
--- a/drivers/mfd/tc6387xb.c
+++ b/drivers/mfd/tc6387xb.c
@@ -150,7 +150,7 @@ static int tc6387xb_probe(struct platform_device *dev)
 	if (!iomem)
 		return -EINVAL;
 
-	tc6387xb = kzalloc(sizeof(*tc6387xb), GFP_KERNEL);
+	tc6387xb = devm_kzalloc(&dev->dev, sizeof(*tc6387xb), GFP_KERNEL);
 	if (!tc6387xb)
 		return -ENOMEM;
 
@@ -203,7 +203,6 @@ static int tc6387xb_probe(struct platform_device *dev)
 	clk_put(clk32k);
 err_no_clk:
 err_no_irq:
-	kfree(tc6387xb);
 	return ret;
 }
 
@@ -216,7 +215,6 @@ static int tc6387xb_remove(struct platform_device *dev)
 	release_resource(&tc6387xb->rscr);
 	clk_disable_unprepare(tc6387xb->clk32k);
 	clk_put(tc6387xb->clk32k);
-	kfree(tc6387xb);
 
 	return 0;
 }
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index d42d322..bdb48e0 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -622,7 +622,7 @@ static int tc6393xb_probe(struct platform_device *dev)
 	if (!iomem)
 		return -EINVAL;
 
-	tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL);
+	tc6393xb = devm_kzalloc(&dev->dev, sizeof(*tc6393xb), GFP_KERNEL);
 	if (!tc6393xb) {
 		ret = -ENOMEM;
 		goto err_kzalloc;
@@ -735,7 +735,6 @@ static int tc6393xb_probe(struct platform_device *dev)
 	clk_put(tc6393xb->clk);
 err_noirq:
 err_clk_get:
-	kfree(tc6393xb);
 err_kzalloc:
 	return ret;
 }
@@ -761,7 +760,6 @@ static int tc6393xb_remove(struct platform_device *dev)
 	iounmap(tc6393xb->scr);
 	release_resource(&tc6393xb->rscr);
 	clk_put(tc6393xb->clk);
-	kfree(tc6393xb);
 
 	return ret;
 }
-- 
2.7.4

             reply	other threads:[~2016-11-05 19:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-05 19:23 Nadim Almas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-11-05 18:52 [PATCH] Mfd: used devm_kzalloc in place of kzalloc Nadim Almas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161105192345.GA9854@gmail.com \
    --to=nadim.902@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).