dt/powerpc: Introduce the use of the managed version of kzalloc
PATCH 1/1 dt/powerpc: Introduce the use of the managed version of kzalloc
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 now unnecessary labels out_free_priv and out are done away with.
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);
...>
}
---
Not compile tested due to incompatible architecture
arch/powerpc/platforms/pasemi/gpio_mdio.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
arch/powerpc/platforms/pasemi/gpio_mdio.c +3 -8
@@ -226,15 +226,14 @@ static int gpio_mdio_probe(struct platform_device *ofdev)const unsigned int *prop;int err; - err = -ENOMEM ; - priv =kzalloc (sizeof (struct gpio_priv ),GFP_KERNEL ); + priv =devm_kzalloc (&ofdev->dev,sizeof (struct gpio_priv ),GFP_KERNEL );if (!priv) - goto out; +return -ENOMEM ; new_bus =mdiobus_alloc ();if (!new_bus) - goto out_free_priv; +return -ENOMEM ; new_bus->name ="pasemi gpio mdio bus" ; new_bus->read = &gpio_mdio_read;
@@ -268,9 +267,6 @@ static int gpio_mdio_probe(struct platform_device *ofdev) out_free_irq:kfree (new_bus); -out_free_priv: -kfree (priv); -out:return err; }
@@ -283,7 +279,6 @@ static int gpio_mdio_remove(struct platform_device *dev)dev_set_drvdata (&dev->dev,NULL ); -kfree (bus->priv); bus->priv =NULL ;mdiobus_free (bus);
Signature · 1 line
1.9.1