power: reset: ltc2952: prefer devm_kzalloc over kzalloc
authorFrans Klaver <frans.klaver@xsens.com>
Wed, 14 Jan 2015 08:15:34 +0000 (09:15 +0100)
committerSebastian Reichel <sre@kernel.org>
Tue, 20 Jan 2015 12:58:27 +0000 (13:58 +0100)
Make use of the fact that the allocated resources can be automatically
deallocated. This reduces cleanup code and chance of leaks.

Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/reset/ltc2952-poweroff.c

index 34f38a3dc3ffbc8e2fec49e7d668d5456c283c59..6487b991ed458a702efa27c648f0369441e13e2e 100644 (file)
@@ -292,7 +292,8 @@ static int ltc2952_poweroff_probe(struct platform_device *pdev)
                return -EBUSY;
        }
 
-       ltc2952_data = kzalloc(sizeof(*ltc2952_data), GFP_KERNEL);
+       ltc2952_data = devm_kzalloc(&pdev->dev, sizeof(*ltc2952_data),
+                                   GFP_KERNEL);
        if (!ltc2952_data)
                return -ENOMEM;
 
@@ -300,17 +301,13 @@ static int ltc2952_poweroff_probe(struct platform_device *pdev)
 
        ret = ltc2952_poweroff_init(pdev);
        if (ret)
-               goto err;
+               return ret;
 
        pm_power_off = &ltc2952_poweroff_kill;
 
        dev_info(&pdev->dev, "probe successful\n");
 
        return 0;
-
-err:
-       kfree(ltc2952_data);
-       return ret;
 }
 
 static int ltc2952_poweroff_remove(struct platform_device *pdev)
@@ -324,8 +321,6 @@ static int ltc2952_poweroff_remove(struct platform_device *pdev)
 
                for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++)
                        gpiod_put(ltc2952_data->gpio[i]);
-
-               kfree(ltc2952_data);
        }
 
        return 0;