Commit 74f0aaba authored by Sven Van Asbroeck's avatar Sven Van Asbroeck Committed by Sebastian Reichel

power: supply: ds2782: fix possible use-after-free on remove

In remove(), use cancel_delayed_work_sync() to cancel the
delayed work. Otherwise there's a chance that this work
will continue to run until after the device has been removed.

While we're here, fix the deallocation order in remove(),
to correspond to the inverse of the probe() allocation
order. This guarantees that any remaining work can run
to completion with all driver structures still intact.

This issue was detected with the help of Coccinelle.
Signed-off-by: default avatarSven Van Asbroeck <TheSven73@gmail.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent f83a6ece
......@@ -319,17 +319,17 @@ static void ds278x_power_supply_init(struct power_supply_desc *battery)
static int ds278x_battery_remove(struct i2c_client *client)
{
struct ds278x_info *info = i2c_get_clientdata(client);
int id = info->id;
power_supply_unregister(info->battery);
cancel_delayed_work_sync(&info->bat_work);
kfree(info->battery_desc.name);
kfree(info);
mutex_lock(&battery_lock);
idr_remove(&battery_id, info->id);
idr_remove(&battery_id, id);
mutex_unlock(&battery_lock);
cancel_delayed_work(&info->bat_work);
kfree(info);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment