[PATCH 4/5] power: supply: ds2782: Use devm_power_supply_register() helper
From: Andrew Davis
Date: Mon Dec 02 2024 - 16:16:06 EST
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@xxxxxx>
---
drivers/power/supply/ds2782_battery.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c
index a72d8c26650d7..ea687b9703314 100644
--- a/drivers/power/supply/ds2782_battery.c
+++ b/drivers/power/supply/ds2782_battery.c
@@ -314,7 +314,6 @@ static void ds278x_battery_remove(struct i2c_client *client)
{
struct ds278x_info *info = i2c_get_clientdata(client);
- power_supply_unregister(info->battery);
cancel_delayed_work_sync(&info->bat_work);
}
@@ -415,8 +414,9 @@ static int ds278x_battery_probe(struct i2c_client *client)
INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work);
- info->battery = power_supply_register(&client->dev,
- &info->battery_desc, &psy_cfg);
+ info->battery = devm_power_supply_register(&client->dev,
+ &info->battery_desc,
+ &psy_cfg);
if (IS_ERR(info->battery)) {
dev_err(&client->dev, "failed to register battery\n");
return PTR_ERR(info->battery);
--
2.39.2