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

power: supply: goldfish: Use devm_power_supply_register() helper

Use the device lifecycle managed register function. This helps prevent
mistakes like unregistering out of order in cleanup functions and
forgetting to unregister on error paths.

Signed-off-by: Andrew Davis <afd@ti.com>
Link: https://lore.kernel.org/r/20240123163653.384385-5-afd@ti.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Andrew Davis and committed by
Sebastian Reichel
ada63f1e 88a72257

+7 -17
+7 -17
drivers/power/supply/goldfish_battery.c
··· 232 232 233 233 psy_cfg.drv_data = data; 234 234 235 - data->ac = power_supply_register(&pdev->dev, &ac_desc, &psy_cfg); 235 + data->ac = devm_power_supply_register(&pdev->dev, 236 + &ac_desc, 237 + &psy_cfg); 236 238 if (IS_ERR(data->ac)) 237 239 return PTR_ERR(data->ac); 238 240 239 - data->battery = power_supply_register(&pdev->dev, &battery_desc, 240 - &psy_cfg); 241 - if (IS_ERR(data->battery)) { 242 - power_supply_unregister(data->ac); 241 + data->battery = devm_power_supply_register(&pdev->dev, 242 + &battery_desc, 243 + &psy_cfg); 244 + if (IS_ERR(data->battery)) 243 245 return PTR_ERR(data->battery); 244 - } 245 - 246 - platform_set_drvdata(pdev, data); 247 246 248 247 GOLDFISH_BATTERY_WRITE(data, BATTERY_INT_ENABLE, BATTERY_INT_MASK); 249 248 return 0; 250 - } 251 - 252 - static void goldfish_battery_remove(struct platform_device *pdev) 253 - { 254 - struct goldfish_battery_data *data = platform_get_drvdata(pdev); 255 - 256 - power_supply_unregister(data->battery); 257 - power_supply_unregister(data->ac); 258 249 } 259 250 260 251 static const struct of_device_id goldfish_battery_of_match[] = { ··· 264 273 265 274 static struct platform_driver goldfish_battery_device = { 266 275 .probe = goldfish_battery_probe, 267 - .remove_new = goldfish_battery_remove, 268 276 .driver = { 269 277 .name = "goldfish-battery", 270 278 .of_match_table = goldfish_battery_of_match,