backlight: convert platform_lcd to devm_kzalloc()
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 10 Jan 2012 23:09:21 +0000 (15:09 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Jan 2012 00:30:48 +0000 (16:30 -0800)
Saves some error handling code and eliminates a class of leaks.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/video/backlight/platform_lcd.c

index 187da59e3a13f652bb44650b9c618c15593039f5..f0bf491ed087a57d86fade373ad326fb6c68300d 100644 (file)
@@ -85,7 +85,8 @@ static int __devinit platform_lcd_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
-       plcd = kzalloc(sizeof(struct platform_lcd), GFP_KERNEL);
+       plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
+                           GFP_KERNEL);
        if (!plcd) {
                dev_err(dev, "no memory for state\n");
                return -ENOMEM;
@@ -98,7 +99,7 @@ static int __devinit platform_lcd_probe(struct platform_device *pdev)
        if (IS_ERR(plcd->lcd)) {
                dev_err(dev, "cannot register lcd device\n");
                err = PTR_ERR(plcd->lcd);
-               goto err_mem;
+               goto err;
        }
 
        platform_set_drvdata(pdev, plcd);
@@ -106,8 +107,7 @@ static int __devinit platform_lcd_probe(struct platform_device *pdev)
 
        return 0;
 
- err_mem:
-       kfree(plcd);
+ err:
        return err;
 }
 
@@ -116,7 +116,6 @@ static int __devexit platform_lcd_remove(struct platform_device *pdev)
        struct platform_lcd *plcd = platform_get_drvdata(pdev);
 
        lcd_device_unregister(plcd->lcd);
-       kfree(plcd);
 
        return 0;
 }