summaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorAndrew Davis <afd@ti.com>2024-12-02 22:15:17 +0100
committerSebastian Reichel <sebastian.reichel@collabora.com>2024-12-04 22:31:31 +0100
commit1481f9f39091b95aec52553a9652d84a827a6004 (patch)
tree195842b864046caa46fc1e1386a4094d50dadef7 /drivers/power
parentpower: supply: ds2782: Free IDA with devm action (diff)
downloadlinux-1481f9f39091b95aec52553a9652d84a827a6004.tar.xz
linux-1481f9f39091b95aec52553a9652d84a827a6004.zip
power: supply: ds2782: Use devm based memory allocators
Use device lifecycle managed memory alloc helpers. This helps prevent mistakes like freeing out of order in cleanup functions and forgetting to free on all error paths. Signed-off-by: Andrew Davis <afd@ti.com> Link: https://lore.kernel.org/r/20241202211519.199635-3-afd@ti.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/ds2782_battery.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c
index 28ad11c8f82d..a72d8c26650d 100644
--- a/drivers/power/supply/ds2782_battery.c
+++ b/drivers/power/supply/ds2782_battery.c
@@ -316,8 +316,6 @@ static void ds278x_battery_remove(struct i2c_client *client)
power_supply_unregister(info->battery);
cancel_delayed_work_sync(&info->bat_work);
- kfree(info->battery_desc.name);
- kfree(info);
}
#ifdef CONFIG_PM_SLEEP
@@ -394,16 +392,14 @@ static int ds278x_battery_probe(struct i2c_client *client)
if (ret)
return ret;
- info = kzalloc(sizeof(*info), GFP_KERNEL);
+ info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
if (!info)
return -ENOMEM;
- info->battery_desc.name = kasprintf(GFP_KERNEL, "%s-%d",
- client->name, num);
- if (!info->battery_desc.name) {
- ret = -ENOMEM;
- goto fail_name;
- }
+ info->battery_desc.name = devm_kasprintf(&client->dev, GFP_KERNEL,
+ "%s-%d", client->name, num);
+ if (!info->battery_desc.name)
+ return -ENOMEM;
if (id->driver_data == DS2786)
info->rsns = pdata->rsns;
@@ -423,19 +419,12 @@ static int ds278x_battery_probe(struct i2c_client *client)
&info->battery_desc, &psy_cfg);
if (IS_ERR(info->battery)) {
dev_err(&client->dev, "failed to register battery\n");
- ret = PTR_ERR(info->battery);
- goto fail_register;
+ return PTR_ERR(info->battery);
} else {
schedule_delayed_work(&info->bat_work, DS278x_DELAY);
}
return 0;
-
-fail_register:
- kfree(info->battery_desc.name);
-fail_name:
- kfree(info);
- return ret;
}
static const struct i2c_device_id ds278x_id[] = {