From: Andrew Davis <afd@ti.com>
To: "Pali Rohár" <pali@kernel.org>, "Sebastian Reichel" <sre@kernel.org>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Andrew Davis <afd@ti.com>
Subject: [PATCH 3/5] power: supply: bq27xxx: Use devm to free device mutex
Date: Tue, 23 Jan 2024 09:09:12 -0600 [thread overview]
Message-ID: <20240123150914.308510-3-afd@ti.com> (raw)
In-Reply-To: <20240123150914.308510-1-afd@ti.com>
Use a device lifecycle managed action to free the device mutex.
This helps prevent mistakes like freeing out of order in cleanup
functions and forgetting to free on error paths.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/power/supply/bq27xxx_battery.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 1c4a9d1377442..d3b6327b16b56 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -2101,6 +2101,13 @@ static void bq27xxx_external_power_changed(struct power_supply *psy)
mod_delayed_work(system_wq, &di->work, HZ / 2);
}
+static void bq27xxx_battery_mutex_destroy(void *data)
+{
+ struct mutex *lock = data;
+
+ mutex_destroy(lock);
+}
+
int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
{
struct power_supply_desc *psy_desc;
@@ -2108,9 +2115,14 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
.of_node = di->dev->of_node,
.drv_data = di,
};
+ int ret;
INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll);
mutex_init(&di->lock);
+ ret = devm_add_action_or_reset(di->dev, bq27xxx_battery_mutex_destroy,
+ &di->lock);
+ if (ret)
+ return ret;
di->regs = bq27xxx_chip_data[di->chip].regs;
di->unseal_key = bq27xxx_chip_data[di->chip].unseal_key;
@@ -2158,7 +2170,6 @@ void bq27xxx_battery_teardown(struct bq27xxx_device_info *di)
cancel_delayed_work_sync(&di->work);
power_supply_unregister(di->bat);
- mutex_destroy(&di->lock);
}
EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown);
--
2.39.2
next prev parent reply other threads:[~2024-01-23 15:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 15:09 [PATCH 1/5] power: supply: bq27xxx: Switch to a simpler IDA interface Andrew Davis
2024-01-23 15:09 ` [PATCH 2/5] power: supply: bq27xxx: Add devm action to free IDA Andrew Davis
2024-01-23 15:09 ` Andrew Davis [this message]
2024-01-23 15:09 ` [PATCH 4/5] power: supply: bq27xxx: Use devm_power_supply_register() helper Andrew Davis
2024-01-23 15:09 ` [PATCH 5/5] power: supply: bq27xxx: Move one time design full read out of poll Andrew Davis
2024-01-27 0:48 ` (subset) [PATCH 1/5] power: supply: bq27xxx: Switch to a simpler IDA interface Sebastian Reichel
2024-01-27 1:32 ` 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=20240123150914.308510-3-afd@ti.com \
--to=afd@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pali@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