mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 19:29:37 +00:00
power: supply: max17040: Use devm_ to automate remove
Two actions were performed during remove - power supply dereg and delayed work cleanup. Power supply dereg can be handled by using the devm_ version of the registration function. Work cleanup can be added as a devm_action. If probe fails after psy registration it will now be cleaned up properly. Signed-off-by: Iskren Chernev <iskren.chernev@gmail.com> Tested-by: Jonathan Bakker <xc-racer2@live.ca> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
05f94eb989
commit
e55a50613d
1 changed files with 21 additions and 18 deletions
|
@ -207,6 +207,19 @@ static void max17040_check_changes(struct i2c_client *client)
|
|||
max17040_get_status(client);
|
||||
}
|
||||
|
||||
static void max17040_queue_work(struct max17040_chip *chip)
|
||||
{
|
||||
queue_delayed_work(system_power_efficient_wq, &chip->work,
|
||||
MAX17040_DELAY);
|
||||
}
|
||||
|
||||
static void max17040_stop_work(void *data)
|
||||
{
|
||||
struct max17040_chip *chip = data;
|
||||
|
||||
cancel_delayed_work_sync(&chip->work);
|
||||
}
|
||||
|
||||
static void max17040_work(struct work_struct *work)
|
||||
{
|
||||
struct max17040_chip *chip;
|
||||
|
@ -223,8 +236,7 @@ static void max17040_work(struct work_struct *work)
|
|||
if (last_soc != chip->soc || last_status != chip->status)
|
||||
power_supply_changed(chip->battery);
|
||||
|
||||
queue_delayed_work(system_power_efficient_wq, &chip->work,
|
||||
MAX17040_DELAY);
|
||||
max17040_queue_work(chip);
|
||||
}
|
||||
|
||||
static irqreturn_t max17040_thread_handler(int id, void *dev)
|
||||
|
@ -339,7 +351,7 @@ static int max17040_probe(struct i2c_client *client,
|
|||
i2c_set_clientdata(client, chip);
|
||||
psy_cfg.drv_data = chip;
|
||||
|
||||
chip->battery = power_supply_register(&client->dev,
|
||||
chip->battery = devm_power_supply_register(&client->dev,
|
||||
&max17040_battery_desc, &psy_cfg);
|
||||
if (IS_ERR(chip->battery)) {
|
||||
dev_err(&client->dev, "failed: power supply register\n");
|
||||
|
@ -368,21 +380,14 @@ static int max17040_probe(struct i2c_client *client,
|
|||
}
|
||||
|
||||
INIT_DEFERRABLE_WORK(&chip->work, max17040_work);
|
||||
queue_delayed_work(system_power_efficient_wq, &chip->work,
|
||||
MAX17040_DELAY);
|
||||
ret = devm_add_action(&client->dev, max17040_stop_work, chip);
|
||||
if (ret)
|
||||
return ret;
|
||||
max17040_queue_work(chip);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int max17040_remove(struct i2c_client *client)
|
||||
{
|
||||
struct max17040_chip *chip = i2c_get_clientdata(client);
|
||||
|
||||
power_supply_unregister(chip->battery);
|
||||
cancel_delayed_work(&chip->work);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
|
||||
static int max17040_suspend(struct device *dev)
|
||||
|
@ -403,12 +408,11 @@ static int max17040_resume(struct device *dev)
|
|||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct max17040_chip *chip = i2c_get_clientdata(client);
|
||||
|
||||
queue_delayed_work(system_power_efficient_wq, &chip->work,
|
||||
MAX17040_DELAY);
|
||||
|
||||
if (client->irq && device_may_wakeup(dev))
|
||||
disable_irq_wake(client->irq);
|
||||
|
||||
max17040_queue_work(chip);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -442,7 +446,6 @@ static struct i2c_driver max17040_i2c_driver = {
|
|||
.pm = MAX17040_PM_OPS,
|
||||
},
|
||||
.probe = max17040_probe,
|
||||
.remove = max17040_remove,
|
||||
.id_table = max17040_id,
|
||||
};
|
||||
module_i2c_driver(max17040_i2c_driver);
|
||||
|
|
Loading…
Reference in a new issue