The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] hwmon: Introduce the use of the managed version of kzalloc
@ 2014-05-20 18:15 Himangi Saraogi
  2014-05-20 20:03 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Himangi Saraogi @ 2014-05-20 18:15 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, lm-sensors, 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, the unnecessary label out_free is removed.

The following Coccinelle semantic patch was used for making 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>
---
v2: fix whitespace error
Not compile tested.

 drivers/hwmon/ultra45_env.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index fb3e693..7d46586 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -252,7 +252,7 @@ static const struct attribute_group env_group = {
 
 static int env_probe(struct platform_device *op)
 {
-	struct env *p = kzalloc(sizeof(*p), GFP_KERNEL);
+	struct env *p = devm_kzalloc(&op->dev, sizeof(*p), GFP_KERNEL);
 	int err = -ENOMEM;
 
 	if (!p)
@@ -262,7 +262,7 @@ static int env_probe(struct platform_device *op)
 
 	p->regs = of_ioremap(&op->resource[0], 0, REG_SIZE, "pic16f747");
 	if (!p->regs)
-		goto out_free;
+		goto out;
 
 	err = sysfs_create_group(&op->dev.kobj, &env_group);
 	if (err)
@@ -286,8 +286,6 @@ out_sysfs_remove_group:
 out_iounmap:
 	of_iounmap(&op->resource[0], p->regs, REG_SIZE);
 
-out_free:
-	kfree(p);
 	goto out;
 }
 
@@ -299,7 +297,6 @@ static int env_remove(struct platform_device *op)
 		sysfs_remove_group(&op->dev.kobj, &env_group);
 		hwmon_device_unregister(p->hwmon_dev);
 		of_iounmap(&op->resource[0], p->regs, REG_SIZE);
-		kfree(p);
 	}
 
 	return 0;
-- 
1.9.1


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

* Re: [PATCH v2] hwmon: Introduce the use of the managed version of kzalloc
  2014-05-20 18:15 [PATCH v2] hwmon: Introduce the use of the managed version of kzalloc Himangi Saraogi
@ 2014-05-20 20:03 ` Guenter Roeck
  2014-05-20 21:20   ` Jean Delvare
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2014-05-20 20:03 UTC (permalink / raw)
  To: Himangi Saraogi; +Cc: Jean Delvare, lm-sensors, linux-kernel, julia.lawall

On Tue, May 20, 2014 at 11:45:37PM +0530, 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, the unnecessary label out_free is removed.
> 
> The following Coccinelle semantic patch was used for making 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>

Applied to -next, just for the sake of it, but frankly that driver
is screwed up so badly that it is pretty much unusable anyway.
Almost all of its attributes are non-standard, and for most of them
that is completely unnecsssary.

Maybe we should create a to-be-removed list and put it there
as first candidate.

Guenter

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

* Re: [PATCH v2] hwmon: Introduce the use of the managed version of kzalloc
  2014-05-20 20:03 ` Guenter Roeck
@ 2014-05-20 21:20   ` Jean Delvare
  0 siblings, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2014-05-20 21:20 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Himangi Saraogi, lm-sensors, linux-kernel, julia.lawall

On Tue, 20 May 2014 13:03:36 -0700, Guenter Roeck wrote:
> On Tue, May 20, 2014 at 11:45:37PM +0530, Himangi Saraogi wrote:
> Applied to -next, just for the sake of it, but frankly that driver
> is screwed up so badly that it is pretty much unusable anyway.
> Almost all of its attributes are non-standard, and for most of them
> that is completely unnecsssary.
> 
> Maybe we should create a to-be-removed list and put it there
> as first candidate.

The traditional way for this is to move the driver to drivers/staging,
mention a deadline in the commit message, and delete it after a few
releases if nobody steps up.

An alternative would be to contact the maintainer (or short of that,
the original contributor) of the driver for an update. Again, with a
deadline.

-- 
Jean Delvare
SUSE L3 Support

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

end of thread, other threads:[~2014-05-20 21:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-20 18:15 [PATCH v2] hwmon: Introduce the use of the managed version of kzalloc Himangi Saraogi
2014-05-20 20:03 ` Guenter Roeck
2014-05-20 21:20   ` Jean Delvare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox