mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Himangi Saraogi <himangi774@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
	sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: julia.lawall@lip6.fr
Subject: [PATCH] sbus: Introduce the use of the managed version of kzalloc
Date: Fri, 23 May 2014 02:05:36 +0530	[thread overview]
Message-ID: <20140522203536.GA16457@himangi-Dell> (raw)

This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. The header file is added to make the devm function explicitly
available. Also, unnecessary assignment statements and labels are
removed.

The following Coccinelle semantic patch was used for making a part of
the change:

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

To send to: "David S. Miller" <davem@davemloft.net>,sparclinux@vger.kernel.org,linux-kernel@vger.kernel.org

 drivers/sbus/char/display7seg.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index 7c71e7b..367b64d 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -20,6 +20,7 @@
 #include <asm/io.h>
 
 #include <asm/display7seg.h>
+#include <linux/device.h>
 
 #define D7S_MINOR	193
 #define DRIVER_NAME	"d7s"
@@ -173,22 +174,21 @@ static struct miscdevice d7s_miscdev = {
 static int d7s_probe(struct platform_device *op)
 {
 	struct device_node *opts;
-	int err = -EINVAL;
+	int err;
 	struct d7s *p;
 	u8 regs;
 
 	if (d7s_device)
-		goto out;
+		return -EINVAL;
 
-	p = kzalloc(sizeof(*p), GFP_KERNEL);
-	err = -ENOMEM;
+	p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL);
 	if (!p)
-		goto out;
+		return -ENOMEM;
 
 	p->regs = of_ioremap(&op->resource[0], 0, sizeof(u8), "d7s");
 	if (!p->regs) {
 		printk(KERN_ERR PFX "Cannot map chip registers\n");
-		goto out_free;
+		return -ENOMEM;
 	}
 
 	err = misc_register(&d7s_miscdev);
@@ -222,17 +222,11 @@ static int d7s_probe(struct platform_device *op)
 
 	dev_set_drvdata(&op->dev, p);
 	d7s_device = p;
-	err = 0;
-
-out:
-	return err;
+	return 0;
 
 out_iounmap:
 	of_iounmap(&op->resource[0], p->regs, sizeof(u8));
-
-out_free:
-	kfree(p);
-	goto out;
+	return err;
 }
 
 static int d7s_remove(struct platform_device *op)
@@ -251,7 +245,6 @@ static int d7s_remove(struct platform_device *op)
 
 	misc_deregister(&d7s_miscdev);
 	of_iounmap(&op->resource[0], p->regs, sizeof(u8));
-	kfree(p);
 
 	return 0;
 }
-- 
1.9.1


             reply	other threads:[~2014-05-22 20:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 20:35 Himangi Saraogi [this message]
2014-05-23 20:17 ` Sam Ravnborg
2014-05-23 20:21   ` Sam Ravnborg
2014-05-24  7:55   ` Julia Lawall

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=20140522203536.GA16457@himangi-Dell \
    --to=himangi774@gmail.com \
    --cc=davem@davemloft.net \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sparclinux@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

all inboxes | Powered by JetHome®