diff options
author | Andrew Davis <afd@ti.com> | 2024-01-29 22:02:46 +0300 |
---|---|---|
committer | Sebastian Reichel <sebastian.reichel@collabora.com> | 2024-02-02 00:48:54 +0300 |
commit | cad1e6df54ca6231a3d1217bc4231d1a7eadbc0c (patch) | |
tree | 0a7c07b7cd54e0b52b992f61f4749db3466a94ce /drivers/power | |
parent | 478a253e466570c4f02cbd7c9386f29dffe4375d (diff) | |
download | linux-cad1e6df54ca6231a3d1217bc4231d1a7eadbc0c.tar.xz |
power: supply: wm8350: 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/20240129190246.73067-5-afd@ti.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/supply/wm8350_power.c | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/drivers/power/supply/wm8350_power.c b/drivers/power/supply/wm8350_power.c index f23b4f5343bc..3f79ab6f6abf 100644 --- a/drivers/power/supply/wm8350_power.c +++ b/drivers/power/supply/wm8350_power.c @@ -540,22 +540,17 @@ static int wm8350_power_probe(struct platform_device *pdev) struct wm8350_charger_policy *policy = power->policy; int ret; - power->ac = power_supply_register(&pdev->dev, &wm8350_ac_desc, NULL); + power->ac = devm_power_supply_register(&pdev->dev, &wm8350_ac_desc, NULL); if (IS_ERR(power->ac)) return PTR_ERR(power->ac); - power->battery = power_supply_register(&pdev->dev, &wm8350_battery_desc, - NULL); - if (IS_ERR(power->battery)) { - ret = PTR_ERR(power->battery); - goto battery_failed; - } + power->battery = devm_power_supply_register(&pdev->dev, &wm8350_battery_desc, NULL); + if (IS_ERR(power->battery)) + return PTR_ERR(power->battery); - power->usb = power_supply_register(&pdev->dev, &wm8350_usb_desc, NULL); - if (IS_ERR(power->usb)) { - ret = PTR_ERR(power->usb); - goto usb_failed; - } + power->usb = devm_power_supply_register(&pdev->dev, &wm8350_usb_desc, NULL); + if (IS_ERR(power->usb)) + return PTR_ERR(power->usb); ret = device_create_file(&pdev->dev, &dev_attr_charger_state); if (ret < 0) @@ -570,25 +565,14 @@ static int wm8350_power_probe(struct platform_device *pdev) } return ret; - -usb_failed: - power_supply_unregister(power->battery); -battery_failed: - power_supply_unregister(power->ac); - - return ret; } static void wm8350_power_remove(struct platform_device *pdev) { struct wm8350 *wm8350 = platform_get_drvdata(pdev); - struct wm8350_power *power = &wm8350->power; free_charger_irq(wm8350); device_remove_file(&pdev->dev, &dev_attr_charger_state); - power_supply_unregister(power->battery); - power_supply_unregister(power->ac); - power_supply_unregister(power->usb); } static struct platform_driver wm8350_power_driver = { |