From: Andrew Davis <afd@ti.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Andrew Davis <afd@ti.com>
Subject: [PATCH 5/5] power: supply: ds2782: Use devm_delayed_work_autocancel() helper
Date: Mon, 2 Dec 2024 15:15:19 -0600 [thread overview]
Message-ID: <20241202211519.199635-5-afd@ti.com> (raw)
In-Reply-To: <20241202211519.199635-1-afd@ti.com>
Use the device lifecycle managed work init function. This helps prevent
mistakes like canceling out of order in cleanup functions and
forgetting to canceling on error paths.
Note we move this to after the registering the power supply so that
the cancel is called before unregistering.
This was the last thing the .remove() function did, so remove that too.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/power/supply/ds2782_battery.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c
index ea687b9703314..cae95d35d3980 100644
--- a/drivers/power/supply/ds2782_battery.c
+++ b/drivers/power/supply/ds2782_battery.c
@@ -11,6 +11,7 @@
* UEvent sending added by Evgeny Romanov <romanov@neurosoft.ru>
*/
+#include <linux/devm-helpers.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
@@ -310,13 +311,6 @@ static void ds278x_power_supply_init(struct power_supply_desc *battery)
battery->external_power_changed = NULL;
}
-static void ds278x_battery_remove(struct i2c_client *client)
-{
- struct ds278x_info *info = i2c_get_clientdata(client);
-
- cancel_delayed_work_sync(&info->bat_work);
-}
-
#ifdef CONFIG_PM_SLEEP
static int ds278x_suspend(struct device *dev)
@@ -412,18 +406,19 @@ static int ds278x_battery_probe(struct i2c_client *client)
info->capacity = 100;
info->status = POWER_SUPPLY_STATUS_FULL;
- INIT_DELAYED_WORK(&info->bat_work, ds278x_bat_work);
-
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);
- } else {
- schedule_delayed_work(&info->bat_work, DS278x_DELAY);
}
+ ret = devm_delayed_work_autocancel(&client->dev, &info->bat_work, ds278x_bat_work);
+ if (ret)
+ return ret;
+ schedule_delayed_work(&info->bat_work, DS278x_DELAY);
+
return 0;
}
@@ -440,7 +435,6 @@ static struct i2c_driver ds278x_battery_driver = {
.pm = &ds278x_battery_pm_ops,
},
.probe = ds278x_battery_probe,
- .remove = ds278x_battery_remove,
.id_table = ds278x_id,
};
module_i2c_driver(ds278x_battery_driver);
--
2.39.2
next prev parent reply other threads:[~2024-12-02 21:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 21:15 [PATCH 1/5] power: supply: ds2782: Switch to simpler IDA interface Andrew Davis
2024-12-02 21:15 ` [PATCH 2/5] power: supply: ds2782: Free IDA with devm action Andrew Davis
2024-12-02 21:15 ` [PATCH 3/5] power: supply: ds2782: Use devm based memory allocators Andrew Davis
2024-12-02 21:15 ` [PATCH 4/5] power: supply: ds2782: Use devm_power_supply_register() helper Andrew Davis
2024-12-02 21:15 ` Andrew Davis [this message]
2024-12-05 1:36 ` [PATCH 1/5] power: supply: ds2782: Switch to simpler IDA interface 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=20241202211519.199635-5-afd@ti.com \
--to=afd@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sre@kernel.org \
/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