mfd: Convert wm8994 to devm_kzalloc()
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 25 Oct 2011 11:45:40 +0000 (13:45 +0200)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 12 Dec 2011 16:09:29 +0000 (00:09 +0800)
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/mfd/wm8994-core.c

index 74d4746..a6846b0 100644 (file)
@@ -401,9 +401,9 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
                goto err_regmap;
        }
 
-       wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
-                                  wm8994->num_supplies,
-                                  GFP_KERNEL);
+       wm8994->supplies = devm_kzalloc(wm8994->dev,
+                                       sizeof(struct regulator_bulk_data) *
+                                       wm8994->num_supplies, GFP_KERNEL);
        if (!wm8994->supplies) {
                ret = -ENOMEM;
                goto err_regmap;
@@ -431,7 +431,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
                                 wm8994->supplies);
        if (ret != 0) {
                dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
-               goto err_supplies;
+               goto err_regmap;
        }
 
        ret = regulator_bulk_enable(wm8994->num_supplies,
@@ -559,12 +559,9 @@ err_enable:
                               wm8994->supplies);
 err_get:
        regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
-err_supplies:
-       kfree(wm8994->supplies);
 err_regmap:
        regmap_exit(wm8994->regmap);
        mfd_remove_devices(wm8994->dev);
-       kfree(wm8994);
        return ret;
 }
 
@@ -576,9 +573,7 @@ static void wm8994_device_exit(struct wm8994 *wm8994)
        regulator_bulk_disable(wm8994->num_supplies,
                               wm8994->supplies);
        regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
-       kfree(wm8994->supplies);
        regmap_exit(wm8994->regmap);
-       kfree(wm8994);
 }
 
 static const struct of_device_id wm8994_of_match[] = {
@@ -595,7 +590,7 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
        struct wm8994 *wm8994;
        int ret;
 
-       wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL);
+       wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL);
        if (wm8994 == NULL)
                return -ENOMEM;
 
@@ -609,7 +604,6 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
                ret = PTR_ERR(wm8994->regmap);
                dev_err(wm8994->dev, "Failed to allocate register map: %d\n",
                        ret);
-               kfree(wm8994);
                return ret;
        }