drivers/video/backlight/adp5520_bl.c: use devm_ functions
authorJulia Lawall <Julia.Lawall@lip6.fr>
Fri, 23 Mar 2012 22:02:01 +0000 (15:02 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 23 Mar 2012 23:58:33 +0000 (16:58 -0700)
The various devm_ functions allocate memory that is released when a driver
detaches.  This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/video/backlight/adp5520_bl.c

index 2e630bf..4911ea7 100644 (file)
@@ -289,7 +289,7 @@ static int __devinit adp5520_bl_probe(struct platform_device *pdev)
        struct adp5520_bl *data;
        int ret = 0;
 
-       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
        if (data == NULL)
                return -ENOMEM;
 
@@ -298,7 +298,6 @@ static int __devinit adp5520_bl_probe(struct platform_device *pdev)
 
        if (data->pdata  == NULL) {
                dev_err(&pdev->dev, "missing platform data\n");
-               kfree(data);
                return -ENODEV;
        }
 
@@ -314,7 +313,6 @@ static int __devinit adp5520_bl_probe(struct platform_device *pdev)
                                       &adp5520_bl_ops, &props);
        if (IS_ERR(bl)) {
                dev_err(&pdev->dev, "failed to register backlight\n");
-               kfree(data);
                return PTR_ERR(bl);
        }
 
@@ -326,7 +324,6 @@ static int __devinit adp5520_bl_probe(struct platform_device *pdev)
        if (ret) {
                dev_err(&pdev->dev, "failed to register sysfs\n");
                backlight_device_unregister(bl);
-               kfree(data);
        }
 
        platform_set_drvdata(pdev, bl);
@@ -348,7 +345,6 @@ static int __devexit adp5520_bl_remove(struct platform_device *pdev)
                                &adp5520_bl_attr_group);
 
        backlight_device_unregister(bl);
-       kfree(data);
 
        return 0;
 }