Skip to content

Commit

Permalink
hwmon: (ultra45_env) Introduce managed version of kzalloc
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Himangi Saraogi authored and Guenter Roeck committed May 21, 2014
1 parent 41082d6 commit e8cba3c
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions drivers/hwmon/ultra45_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -286,8 +286,6 @@ static int env_probe(struct platform_device *op)
out_iounmap:
of_iounmap(&op->resource[0], p->regs, REG_SIZE);

out_free:
kfree(p);
goto out;
}

Expand All @@ -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;
Expand Down

0 comments on commit e8cba3c

Please sign in to comment.