Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756619AbcKETX6 (ORCPT ); Sat, 5 Nov 2016 15:23:58 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35176 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756040AbcKETX4 (ORCPT ); Sat, 5 Nov 2016 15:23:56 -0400 Date: Sun, 6 Nov 2016 00:53:45 +0530 From: Nadim Almas 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 Message-ID: <20161105192345.GA9854@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3346 Lines: 136 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: // @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); ...> } // Signed-off-by: Nadim Almas --- 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