From: Iskren Chernev <iskren.chernev@gmail.com>
To: Sebastian Reichel <sre@kernel.org>, Rob Herring <robh+dt@kernel.org>
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
~postmarketos/upstreaming@lists.sr.ht,
Jonathan Bakker <xc-racer2@live.ca>,
Vladimir Barinov <vladimir.barinov@cogentembedded.com>,
Iskren Chernev <iskren.chernev@gmail.com>
Subject: [PATCH v5 1/7] power: supply: max17040: Use devm_ to automate remove
Date: Tue, 22 Sep 2020 14:42:31 +0300 [thread overview]
Message-ID: <20200922114237.1803628-2-iskren.chernev@gmail.com> (raw)
In-Reply-To: <20200922114237.1803628-1-iskren.chernev@gmail.com>
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>
---
drivers/power/supply/max17040_battery.c | 39 +++++++++++++------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 6cb31b9a958dd..19b9e710bbd2f 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -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,18 +380,11 @@ 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);
-
- return 0;
-}
-
-static int max17040_remove(struct i2c_client *client)
-{
- struct max17040_chip *chip = i2c_get_clientdata(client);
+ ret = devm_add_action(&client->dev, max17040_stop_work, chip);
+ if (ret)
+ return ret;
+ max17040_queue_work(chip);
- power_supply_unregister(chip->battery);
- cancel_delayed_work(&chip->work);
return 0;
}
@@ -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);
--
2.28.0
next prev parent reply other threads:[~2020-09-22 11:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-22 11:42 [PATCH v5 0/7] power: supply: max17040 support compatible devices Iskren Chernev
2020-09-22 11:42 ` Iskren Chernev [this message]
2020-09-22 11:42 ` [PATCH v5 2/7] power: supply: max17040: Use regmap i2c Iskren Chernev
2020-09-22 11:42 ` [PATCH v5 3/7] dt-bindings: power: supply: Extend max17040 compatibility Iskren Chernev
2020-09-22 11:42 ` [PATCH v5 4/7] power: supply: max17040: Support compatible devices Iskren Chernev
2020-09-22 11:42 ` [PATCH v5 5/7] dt-bindings: power: supply: max17040: Add maxim,rcomp Iskren Chernev
2020-09-22 11:42 ` [PATCH v5 6/7] power: supply: max17040: Support setting rcomp Iskren Chernev
2020-09-22 11:42 ` [PATCH v5 7/7] power: supply: max17040: Support soc alert Iskren Chernev
2020-10-03 19:12 ` [PATCH v5 0/7] power: supply: max17040 support compatible devices Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200922114237.1803628-2-iskren.chernev@gmail.com \
--to=iskren.chernev@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
--cc=vladimir.barinov@cogentembedded.com \
--cc=xc-racer2@live.ca \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).