Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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>
Cc: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Julia Lawall and committed by
Linus Torvalds
ce969228 1107d40a

+18 -47
+2 -6
drivers/video/backlight/88pm860x_bl.c
··· 187 187 return -EINVAL; 188 188 } 189 189 190 - data = kzalloc(sizeof(struct pm860x_backlight_data), GFP_KERNEL); 190 + data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_backlight_data), 191 + GFP_KERNEL); 191 192 if (data == NULL) 192 193 return -ENOMEM; 193 194 strncpy(name, res->name, MFD_NAME_SIZE); ··· 201 200 data->port = pdata->flags; 202 201 if (data->port < 0) { 203 202 dev_err(&pdev->dev, "wrong platform data is assigned"); 204 - kfree(data); 205 203 return -EINVAL; 206 204 } 207 205 ··· 211 211 &pm860x_backlight_ops, &props); 212 212 if (IS_ERR(bl)) { 213 213 dev_err(&pdev->dev, "failed to register backlight\n"); 214 - kfree(data); 215 214 return PTR_ERR(bl); 216 215 } 217 216 bl->props.brightness = MAX_BRIGHTNESS; ··· 246 247 return 0; 247 248 out: 248 249 backlight_device_unregister(bl); 249 - kfree(data); 250 250 return ret; 251 251 } 252 252 253 253 static int pm860x_backlight_remove(struct platform_device *pdev) 254 254 { 255 255 struct backlight_device *bl = platform_get_drvdata(pdev); 256 - struct pm860x_backlight_data *data = bl_get_data(bl); 257 256 258 257 backlight_device_unregister(bl); 259 - kfree(data); 260 258 return 0; 261 259 } 262 260
+4 -5
drivers/video/backlight/aat2870_bl.c
··· 145 145 goto out; 146 146 } 147 147 148 - aat2870_bl = kzalloc(sizeof(struct aat2870_bl_driver_data), GFP_KERNEL); 148 + aat2870_bl = devm_kzalloc(&pdev->dev, 149 + sizeof(struct aat2870_bl_driver_data), 150 + GFP_KERNEL); 149 151 if (!aat2870_bl) { 150 152 dev_err(&pdev->dev, 151 153 "Failed to allocate memory for aat2870 backlight\n"); ··· 164 162 dev_err(&pdev->dev, 165 163 "Failed allocate memory for backlight device\n"); 166 164 ret = PTR_ERR(bd); 167 - goto out_kfree; 165 + goto out; 168 166 } 169 167 170 168 aat2870_bl->pdev = pdev; ··· 201 199 202 200 out_bl_dev_unregister: 203 201 backlight_device_unregister(bd); 204 - out_kfree: 205 - kfree(aat2870_bl); 206 202 out: 207 203 return ret; 208 204 } ··· 215 215 backlight_update_status(bd); 216 216 217 217 backlight_device_unregister(bd); 218 - kfree(aat2870_bl); 219 218 220 219 return 0; 221 220 }
+1 -2
drivers/video/backlight/cr_bllcd.c
··· 212 212 &gpio_bar); 213 213 gpio_bar &= ~0x3F; 214 214 215 - crp = kzalloc(sizeof(*crp), GFP_KERNEL); 215 + crp = devm_kzalloc(&pdev->dev, sizeof(*crp), GFP_KERNEL); 216 216 if (!crp) { 217 217 lcd_device_unregister(ldp); 218 218 backlight_device_unregister(bdp); ··· 243 243 backlight_device_unregister(crp->cr_backlight_device); 244 244 lcd_device_unregister(crp->cr_lcd_device); 245 245 pci_dev_put(lpc_dev); 246 - kfree(crp); 247 246 248 247 return 0; 249 248 }
+1 -5
drivers/video/backlight/da903x_bl.c
··· 110 110 struct backlight_properties props; 111 111 int max_brightness; 112 112 113 - data = kzalloc(sizeof(*data), GFP_KERNEL); 113 + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 114 114 if (data == NULL) 115 115 return -ENOMEM; 116 116 ··· 124 124 default: 125 125 dev_err(&pdev->dev, "invalid backlight device ID(%d)\n", 126 126 pdev->id); 127 - kfree(data); 128 127 return -EINVAL; 129 128 } 130 129 ··· 142 143 &da903x_backlight_ops, &props); 143 144 if (IS_ERR(bl)) { 144 145 dev_err(&pdev->dev, "failed to register backlight\n"); 145 - kfree(data); 146 146 return PTR_ERR(bl); 147 147 } 148 148 ··· 155 157 static int da903x_backlight_remove(struct platform_device *pdev) 156 158 { 157 159 struct backlight_device *bl = platform_get_drvdata(pdev); 158 - struct da903x_backlight_data *data = bl_get_data(bl); 159 160 160 161 backlight_device_unregister(bl); 161 - kfree(data); 162 162 return 0; 163 163 } 164 164
+2 -5
drivers/video/backlight/max8925_bl.c
··· 129 129 return -EINVAL; 130 130 } 131 131 132 - data = kzalloc(sizeof(struct max8925_backlight_data), GFP_KERNEL); 132 + data = devm_kzalloc(&pdev->dev, sizeof(struct max8925_backlight_data), 133 + GFP_KERNEL); 133 134 if (data == NULL) 134 135 return -ENOMEM; 135 136 strncpy(name, res->name, MAX8925_NAME_SIZE); ··· 144 143 &max8925_backlight_ops, &props); 145 144 if (IS_ERR(bl)) { 146 145 dev_err(&pdev->dev, "failed to register backlight\n"); 147 - kfree(data); 148 146 return PTR_ERR(bl); 149 147 } 150 148 bl->props.brightness = MAX_BRIGHTNESS; ··· 165 165 return 0; 166 166 out: 167 167 backlight_device_unregister(bl); 168 - kfree(data); 169 168 return ret; 170 169 } 171 170 172 171 static int __devexit max8925_backlight_remove(struct platform_device *pdev) 173 172 { 174 173 struct backlight_device *bl = platform_get_drvdata(pdev); 175 - struct max8925_backlight_data *data = bl_get_data(bl); 176 174 177 175 backlight_device_unregister(bl); 178 - kfree(data); 179 176 return 0; 180 177 } 181 178
+3 -6
drivers/video/backlight/omap1_bl.c
··· 141 141 if (!pdata) 142 142 return -ENXIO; 143 143 144 - bl = kzalloc(sizeof(struct omap_backlight), GFP_KERNEL); 144 + bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight), 145 + GFP_KERNEL); 145 146 if (unlikely(!bl)) 146 147 return -ENOMEM; 147 148 ··· 151 150 props.max_brightness = OMAPBL_MAX_INTENSITY; 152 151 dev = backlight_device_register("omap-bl", &pdev->dev, bl, &omapbl_ops, 153 152 &props); 154 - if (IS_ERR(dev)) { 155 - kfree(bl); 153 + if (IS_ERR(dev)) 156 154 return PTR_ERR(dev); 157 - } 158 155 159 156 bl->powermode = FB_BLANK_POWERDOWN; 160 157 bl->current_intensity = 0; ··· 176 177 static int omapbl_remove(struct platform_device *pdev) 177 178 { 178 179 struct backlight_device *dev = platform_get_drvdata(pdev); 179 - struct omap_backlight *bl = dev_get_drvdata(&dev->dev); 180 180 181 181 backlight_device_unregister(dev); 182 - kfree(bl); 183 182 184 183 return 0; 185 184 }
+3 -13
drivers/video/backlight/pcf50633-backlight.c
··· 101 101 102 102 static int __devinit pcf50633_bl_probe(struct platform_device *pdev) 103 103 { 104 - int ret; 105 104 struct pcf50633_bl *pcf_bl; 106 105 struct device *parent = pdev->dev.parent; 107 106 struct pcf50633_platform_data *pcf50633_data = parent->platform_data; 108 107 struct pcf50633_bl_platform_data *pdata = pcf50633_data->backlight_data; 109 108 struct backlight_properties bl_props; 110 109 111 - pcf_bl = kzalloc(sizeof(*pcf_bl), GFP_KERNEL); 110 + pcf_bl = devm_kzalloc(&pdev->dev, sizeof(*pcf_bl), GFP_KERNEL); 112 111 if (!pcf_bl) 113 112 return -ENOMEM; 114 113 ··· 128 129 pcf_bl->bl = backlight_device_register(pdev->name, &pdev->dev, pcf_bl, 129 130 &pcf50633_bl_ops, &bl_props); 130 131 131 - if (IS_ERR(pcf_bl->bl)) { 132 - ret = PTR_ERR(pcf_bl->bl); 133 - goto err_free; 134 - } 132 + if (IS_ERR(pcf_bl->bl)) 133 + return PTR_ERR(pcf_bl->bl); 135 134 136 135 platform_set_drvdata(pdev, pcf_bl); 137 136 ··· 142 145 backlight_update_status(pcf_bl->bl); 143 146 144 147 return 0; 145 - 146 - err_free: 147 - kfree(pcf_bl); 148 - 149 - return ret; 150 148 } 151 149 152 150 static int __devexit pcf50633_bl_remove(struct platform_device *pdev) ··· 151 159 backlight_device_unregister(pcf_bl->bl); 152 160 153 161 platform_set_drvdata(pdev, NULL); 154 - 155 - kfree(pcf_bl); 156 162 157 163 return 0; 158 164 }
+2 -5
drivers/video/backlight/pwm_bl.c
··· 102 102 return ret; 103 103 } 104 104 105 - pb = kzalloc(sizeof(*pb), GFP_KERNEL); 105 + pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL); 106 106 if (!pb) { 107 107 dev_err(&pdev->dev, "no memory for state\n"); 108 108 ret = -ENOMEM; ··· 121 121 if (IS_ERR(pb->pwm)) { 122 122 dev_err(&pdev->dev, "unable to request PWM for backlight\n"); 123 123 ret = PTR_ERR(pb->pwm); 124 - goto err_pwm; 124 + goto err_alloc; 125 125 } else 126 126 dev_dbg(&pdev->dev, "got pwm for backlight\n"); 127 127 ··· 144 144 145 145 err_bl: 146 146 pwm_free(pb->pwm); 147 - err_pwm: 148 - kfree(pb); 149 147 err_alloc: 150 148 if (data->exit) 151 149 data->exit(&pdev->dev); ··· 160 162 pwm_config(pb->pwm, 0, pb->period); 161 163 pwm_disable(pb->pwm); 162 164 pwm_free(pb->pwm); 163 - kfree(pb); 164 165 if (data->exit) 165 166 data->exit(&pdev->dev); 166 167 return 0;