Commit ce969228 authored by Julia Lawall's avatar Julia Lawall Committed by Linus Torvalds

drivers/video/backlight: use devm_ functions

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: default avatarJulia 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>
Cc: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1107d40a
...@@ -187,7 +187,8 @@ static int pm860x_backlight_probe(struct platform_device *pdev) ...@@ -187,7 +187,8 @@ static int pm860x_backlight_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
data = kzalloc(sizeof(struct pm860x_backlight_data), GFP_KERNEL); data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_backlight_data),
GFP_KERNEL);
if (data == NULL) if (data == NULL)
return -ENOMEM; return -ENOMEM;
strncpy(name, res->name, MFD_NAME_SIZE); strncpy(name, res->name, MFD_NAME_SIZE);
...@@ -200,7 +201,6 @@ static int pm860x_backlight_probe(struct platform_device *pdev) ...@@ -200,7 +201,6 @@ static int pm860x_backlight_probe(struct platform_device *pdev)
data->port = pdata->flags; data->port = pdata->flags;
if (data->port < 0) { if (data->port < 0) {
dev_err(&pdev->dev, "wrong platform data is assigned"); dev_err(&pdev->dev, "wrong platform data is assigned");
kfree(data);
return -EINVAL; return -EINVAL;
} }
...@@ -211,7 +211,6 @@ static int pm860x_backlight_probe(struct platform_device *pdev) ...@@ -211,7 +211,6 @@ static int pm860x_backlight_probe(struct platform_device *pdev)
&pm860x_backlight_ops, &props); &pm860x_backlight_ops, &props);
if (IS_ERR(bl)) { if (IS_ERR(bl)) {
dev_err(&pdev->dev, "failed to register backlight\n"); dev_err(&pdev->dev, "failed to register backlight\n");
kfree(data);
return PTR_ERR(bl); return PTR_ERR(bl);
} }
bl->props.brightness = MAX_BRIGHTNESS; bl->props.brightness = MAX_BRIGHTNESS;
...@@ -247,17 +246,14 @@ static int pm860x_backlight_probe(struct platform_device *pdev) ...@@ -247,17 +246,14 @@ static int pm860x_backlight_probe(struct platform_device *pdev)
return 0; return 0;
out: out:
backlight_device_unregister(bl); backlight_device_unregister(bl);
kfree(data);
return ret; return ret;
} }
static int pm860x_backlight_remove(struct platform_device *pdev) static int pm860x_backlight_remove(struct platform_device *pdev)
{ {
struct backlight_device *bl = platform_get_drvdata(pdev); struct backlight_device *bl = platform_get_drvdata(pdev);
struct pm860x_backlight_data *data = bl_get_data(bl);
backlight_device_unregister(bl); backlight_device_unregister(bl);
kfree(data);
return 0; return 0;
} }
......
...@@ -145,7 +145,9 @@ static int aat2870_bl_probe(struct platform_device *pdev) ...@@ -145,7 +145,9 @@ static int aat2870_bl_probe(struct platform_device *pdev)
goto out; goto out;
} }
aat2870_bl = kzalloc(sizeof(struct aat2870_bl_driver_data), GFP_KERNEL); aat2870_bl = devm_kzalloc(&pdev->dev,
sizeof(struct aat2870_bl_driver_data),
GFP_KERNEL);
if (!aat2870_bl) { if (!aat2870_bl) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Failed to allocate memory for aat2870 backlight\n"); "Failed to allocate memory for aat2870 backlight\n");
...@@ -162,7 +164,7 @@ static int aat2870_bl_probe(struct platform_device *pdev) ...@@ -162,7 +164,7 @@ static int aat2870_bl_probe(struct platform_device *pdev)
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Failed allocate memory for backlight device\n"); "Failed allocate memory for backlight device\n");
ret = PTR_ERR(bd); ret = PTR_ERR(bd);
goto out_kfree; goto out;
} }
aat2870_bl->pdev = pdev; aat2870_bl->pdev = pdev;
...@@ -199,8 +201,6 @@ static int aat2870_bl_probe(struct platform_device *pdev) ...@@ -199,8 +201,6 @@ static int aat2870_bl_probe(struct platform_device *pdev)
out_bl_dev_unregister: out_bl_dev_unregister:
backlight_device_unregister(bd); backlight_device_unregister(bd);
out_kfree:
kfree(aat2870_bl);
out: out:
return ret; return ret;
} }
...@@ -215,7 +215,6 @@ static int aat2870_bl_remove(struct platform_device *pdev) ...@@ -215,7 +215,6 @@ static int aat2870_bl_remove(struct platform_device *pdev)
backlight_update_status(bd); backlight_update_status(bd);
backlight_device_unregister(bd); backlight_device_unregister(bd);
kfree(aat2870_bl);
return 0; return 0;
} }
......
...@@ -212,7 +212,7 @@ static int cr_backlight_probe(struct platform_device *pdev) ...@@ -212,7 +212,7 @@ static int cr_backlight_probe(struct platform_device *pdev)
&gpio_bar); &gpio_bar);
gpio_bar &= ~0x3F; gpio_bar &= ~0x3F;
crp = kzalloc(sizeof(*crp), GFP_KERNEL); crp = devm_kzalloc(&pdev->dev, sizeof(*crp), GFP_KERNEL);
if (!crp) { if (!crp) {
lcd_device_unregister(ldp); lcd_device_unregister(ldp);
backlight_device_unregister(bdp); backlight_device_unregister(bdp);
...@@ -243,7 +243,6 @@ static int cr_backlight_remove(struct platform_device *pdev) ...@@ -243,7 +243,6 @@ static int cr_backlight_remove(struct platform_device *pdev)
backlight_device_unregister(crp->cr_backlight_device); backlight_device_unregister(crp->cr_backlight_device);
lcd_device_unregister(crp->cr_lcd_device); lcd_device_unregister(crp->cr_lcd_device);
pci_dev_put(lpc_dev); pci_dev_put(lpc_dev);
kfree(crp);
return 0; return 0;
} }
......
...@@ -110,7 +110,7 @@ static int da903x_backlight_probe(struct platform_device *pdev) ...@@ -110,7 +110,7 @@ static int da903x_backlight_probe(struct platform_device *pdev)
struct backlight_properties props; struct backlight_properties props;
int max_brightness; int max_brightness;
data = kzalloc(sizeof(*data), GFP_KERNEL); data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (data == NULL) if (data == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -124,7 +124,6 @@ static int da903x_backlight_probe(struct platform_device *pdev) ...@@ -124,7 +124,6 @@ static int da903x_backlight_probe(struct platform_device *pdev)
default: default:
dev_err(&pdev->dev, "invalid backlight device ID(%d)\n", dev_err(&pdev->dev, "invalid backlight device ID(%d)\n",
pdev->id); pdev->id);
kfree(data);
return -EINVAL; return -EINVAL;
} }
...@@ -143,7 +142,6 @@ static int da903x_backlight_probe(struct platform_device *pdev) ...@@ -143,7 +142,6 @@ static int da903x_backlight_probe(struct platform_device *pdev)
&da903x_backlight_ops, &props); &da903x_backlight_ops, &props);
if (IS_ERR(bl)) { if (IS_ERR(bl)) {
dev_err(&pdev->dev, "failed to register backlight\n"); dev_err(&pdev->dev, "failed to register backlight\n");
kfree(data);
return PTR_ERR(bl); return PTR_ERR(bl);
} }
...@@ -157,10 +155,8 @@ static int da903x_backlight_probe(struct platform_device *pdev) ...@@ -157,10 +155,8 @@ static int da903x_backlight_probe(struct platform_device *pdev)
static int da903x_backlight_remove(struct platform_device *pdev) static int da903x_backlight_remove(struct platform_device *pdev)
{ {
struct backlight_device *bl = platform_get_drvdata(pdev); struct backlight_device *bl = platform_get_drvdata(pdev);
struct da903x_backlight_data *data = bl_get_data(bl);
backlight_device_unregister(bl); backlight_device_unregister(bl);
kfree(data);
return 0; return 0;
} }
......
...@@ -129,7 +129,8 @@ static int __devinit max8925_backlight_probe(struct platform_device *pdev) ...@@ -129,7 +129,8 @@ static int __devinit max8925_backlight_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
data = kzalloc(sizeof(struct max8925_backlight_data), GFP_KERNEL); data = devm_kzalloc(&pdev->dev, sizeof(struct max8925_backlight_data),
GFP_KERNEL);
if (data == NULL) if (data == NULL)
return -ENOMEM; return -ENOMEM;
strncpy(name, res->name, MAX8925_NAME_SIZE); strncpy(name, res->name, MAX8925_NAME_SIZE);
...@@ -143,7 +144,6 @@ static int __devinit max8925_backlight_probe(struct platform_device *pdev) ...@@ -143,7 +144,6 @@ static int __devinit max8925_backlight_probe(struct platform_device *pdev)
&max8925_backlight_ops, &props); &max8925_backlight_ops, &props);
if (IS_ERR(bl)) { if (IS_ERR(bl)) {
dev_err(&pdev->dev, "failed to register backlight\n"); dev_err(&pdev->dev, "failed to register backlight\n");
kfree(data);
return PTR_ERR(bl); return PTR_ERR(bl);
} }
bl->props.brightness = MAX_BRIGHTNESS; bl->props.brightness = MAX_BRIGHTNESS;
...@@ -165,17 +165,14 @@ static int __devinit max8925_backlight_probe(struct platform_device *pdev) ...@@ -165,17 +165,14 @@ static int __devinit max8925_backlight_probe(struct platform_device *pdev)
return 0; return 0;
out: out:
backlight_device_unregister(bl); backlight_device_unregister(bl);
kfree(data);
return ret; return ret;
} }
static int __devexit max8925_backlight_remove(struct platform_device *pdev) static int __devexit max8925_backlight_remove(struct platform_device *pdev)
{ {
struct backlight_device *bl = platform_get_drvdata(pdev); struct backlight_device *bl = platform_get_drvdata(pdev);
struct max8925_backlight_data *data = bl_get_data(bl);
backlight_device_unregister(bl); backlight_device_unregister(bl);
kfree(data);
return 0; return 0;
} }
......
...@@ -141,7 +141,8 @@ static int omapbl_probe(struct platform_device *pdev) ...@@ -141,7 +141,8 @@ static int omapbl_probe(struct platform_device *pdev)
if (!pdata) if (!pdata)
return -ENXIO; return -ENXIO;
bl = kzalloc(sizeof(struct omap_backlight), GFP_KERNEL); bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight),
GFP_KERNEL);
if (unlikely(!bl)) if (unlikely(!bl))
return -ENOMEM; return -ENOMEM;
...@@ -150,10 +151,8 @@ static int omapbl_probe(struct platform_device *pdev) ...@@ -150,10 +151,8 @@ static int omapbl_probe(struct platform_device *pdev)
props.max_brightness = OMAPBL_MAX_INTENSITY; props.max_brightness = OMAPBL_MAX_INTENSITY;
dev = backlight_device_register("omap-bl", &pdev->dev, bl, &omapbl_ops, dev = backlight_device_register("omap-bl", &pdev->dev, bl, &omapbl_ops,
&props); &props);
if (IS_ERR(dev)) { if (IS_ERR(dev))
kfree(bl);
return PTR_ERR(dev); return PTR_ERR(dev);
}
bl->powermode = FB_BLANK_POWERDOWN; bl->powermode = FB_BLANK_POWERDOWN;
bl->current_intensity = 0; bl->current_intensity = 0;
...@@ -177,10 +176,8 @@ static int omapbl_probe(struct platform_device *pdev) ...@@ -177,10 +176,8 @@ static int omapbl_probe(struct platform_device *pdev)
static int omapbl_remove(struct platform_device *pdev) static int omapbl_remove(struct platform_device *pdev)
{ {
struct backlight_device *dev = platform_get_drvdata(pdev); struct backlight_device *dev = platform_get_drvdata(pdev);
struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
backlight_device_unregister(dev); backlight_device_unregister(dev);
kfree(bl);
return 0; return 0;
} }
......
...@@ -101,14 +101,13 @@ static const struct backlight_ops pcf50633_bl_ops = { ...@@ -101,14 +101,13 @@ static const struct backlight_ops pcf50633_bl_ops = {
static int __devinit pcf50633_bl_probe(struct platform_device *pdev) static int __devinit pcf50633_bl_probe(struct platform_device *pdev)
{ {
int ret;
struct pcf50633_bl *pcf_bl; struct pcf50633_bl *pcf_bl;
struct device *parent = pdev->dev.parent; struct device *parent = pdev->dev.parent;
struct pcf50633_platform_data *pcf50633_data = parent->platform_data; struct pcf50633_platform_data *pcf50633_data = parent->platform_data;
struct pcf50633_bl_platform_data *pdata = pcf50633_data->backlight_data; struct pcf50633_bl_platform_data *pdata = pcf50633_data->backlight_data;
struct backlight_properties bl_props; struct backlight_properties bl_props;
pcf_bl = kzalloc(sizeof(*pcf_bl), GFP_KERNEL); pcf_bl = devm_kzalloc(&pdev->dev, sizeof(*pcf_bl), GFP_KERNEL);
if (!pcf_bl) if (!pcf_bl)
return -ENOMEM; return -ENOMEM;
...@@ -129,10 +128,8 @@ static int __devinit pcf50633_bl_probe(struct platform_device *pdev) ...@@ -129,10 +128,8 @@ static int __devinit pcf50633_bl_probe(struct platform_device *pdev)
pcf_bl->bl = backlight_device_register(pdev->name, &pdev->dev, pcf_bl, pcf_bl->bl = backlight_device_register(pdev->name, &pdev->dev, pcf_bl,
&pcf50633_bl_ops, &bl_props); &pcf50633_bl_ops, &bl_props);
if (IS_ERR(pcf_bl->bl)) { if (IS_ERR(pcf_bl->bl))
ret = PTR_ERR(pcf_bl->bl); return PTR_ERR(pcf_bl->bl);
goto err_free;
}
platform_set_drvdata(pdev, pcf_bl); platform_set_drvdata(pdev, pcf_bl);
...@@ -145,11 +142,6 @@ static int __devinit pcf50633_bl_probe(struct platform_device *pdev) ...@@ -145,11 +142,6 @@ static int __devinit pcf50633_bl_probe(struct platform_device *pdev)
backlight_update_status(pcf_bl->bl); backlight_update_status(pcf_bl->bl);
return 0; return 0;
err_free:
kfree(pcf_bl);
return ret;
} }
static int __devexit pcf50633_bl_remove(struct platform_device *pdev) static int __devexit pcf50633_bl_remove(struct platform_device *pdev)
...@@ -160,8 +152,6 @@ static int __devexit pcf50633_bl_remove(struct platform_device *pdev) ...@@ -160,8 +152,6 @@ static int __devexit pcf50633_bl_remove(struct platform_device *pdev)
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
kfree(pcf_bl);
return 0; return 0;
} }
......
...@@ -102,7 +102,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -102,7 +102,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
return ret; return ret;
} }
pb = kzalloc(sizeof(*pb), GFP_KERNEL); pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL);
if (!pb) { if (!pb) {
dev_err(&pdev->dev, "no memory for state\n"); dev_err(&pdev->dev, "no memory for state\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -121,7 +121,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -121,7 +121,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
if (IS_ERR(pb->pwm)) { if (IS_ERR(pb->pwm)) {
dev_err(&pdev->dev, "unable to request PWM for backlight\n"); dev_err(&pdev->dev, "unable to request PWM for backlight\n");
ret = PTR_ERR(pb->pwm); ret = PTR_ERR(pb->pwm);
goto err_pwm; goto err_alloc;
} else } else
dev_dbg(&pdev->dev, "got pwm for backlight\n"); dev_dbg(&pdev->dev, "got pwm for backlight\n");
...@@ -144,8 +144,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -144,8 +144,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
err_bl: err_bl:
pwm_free(pb->pwm); pwm_free(pb->pwm);
err_pwm:
kfree(pb);
err_alloc: err_alloc:
if (data->exit) if (data->exit)
data->exit(&pdev->dev); data->exit(&pdev->dev);
...@@ -162,7 +160,6 @@ static int pwm_backlight_remove(struct platform_device *pdev) ...@@ -162,7 +160,6 @@ static int pwm_backlight_remove(struct platform_device *pdev)
pwm_config(pb->pwm, 0, pb->period); pwm_config(pb->pwm, 0, pb->period);
pwm_disable(pb->pwm); pwm_disable(pb->pwm);
pwm_free(pb->pwm); pwm_free(pb->pwm);
kfree(pb);
if (data->exit) if (data->exit)
data->exit(&pdev->dev); data->exit(&pdev->dev);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment