From: Maxwell Doose <m32285159@gmail.com>
To: rafael@kernel.org, lenb@kernel.org
Cc: Andy Shevchenko <andy@kernel.org>,
Mika Westerberg <westeri@kernel.org>,
linux-acpi@vger.kernel.org (open list:ACPI PMIC DRIVERS),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v5] ACPI: pmic: Replace mutex_lock/unlock() with guard()/scoped_guard()
Date: Wed, 29 Apr 2026 20:35:06 -0500 [thread overview]
Message-ID: <20260430013507.46259-1-m32285159@gmail.com> (raw)
Replace mutex_lock() and unlock() macros with the newer guard() and
scoped_guard() macros. This will help modernize and clean the code.
Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
v2:
- Refactored control flow in certain functions as suggested by Andy.
- Indent code in scoped_guard block as suggested by Andy.
- Fix parameter list alignment issues that I found while making this
v2.
v3:
- Fixed guard(mutex)() and scoped_guard() syntax.
- Added some logical and style changes per Andy's request. The
requested changes and my personal thoughts can be found at
https://lore.kernel.org/linux-acpi/ae8QBnSs9fYvkv_i@ashevche-desk.local/
v4:
- Added else keyword to if statement in
intel_soc_pmic_exec_mipi_pmic_seq_element() per Andy's request.
v5:
- Misunderstanding at last version, v4 has been reverted.
- Made diff less invasive per Andy's request by leaving most code
below d->exec_mipi_pmic_seq_element check in
intel_soc_pmic_exec_mipi_pmic_seq_element() intact.
- Reinstated ret variable in
intel_soc_pmic_exec_mipi_pmic_seq_element() per Andy's request.
drivers/acpi/pmic/intel_pmic.c | 37 +++++++++++++++-------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/drivers/acpi/pmic/intel_pmic.c b/drivers/acpi/pmic/intel_pmic.c
index 134e9ca8eaa2..9bd46defc5a2 100644
--- a/drivers/acpi/pmic/intel_pmic.c
+++ b/drivers/acpi/pmic/intel_pmic.c
@@ -67,14 +67,12 @@ static acpi_status intel_pmic_power_handler(u32 function,
if (result == -ENOENT)
return AE_BAD_PARAMETER;
- mutex_lock(&opregion->lock);
+ guard(mutex)(&opregion->lock);
result = function == ACPI_READ ?
d->get_power(regmap, reg, bit, value64) :
d->update_power(regmap, reg, bit, *value64 == 1);
- mutex_unlock(&opregion->lock);
-
return result ? AE_ERROR : AE_OK;
}
@@ -182,19 +180,16 @@ static acpi_status intel_pmic_thermal_handler(u32 function,
if (result == -ENOENT)
return AE_BAD_PARAMETER;
- mutex_lock(&opregion->lock);
-
- if (pmic_thermal_is_temp(address))
- result = pmic_thermal_temp(opregion, reg, function, value64);
- else if (pmic_thermal_is_aux(address))
- result = pmic_thermal_aux(opregion, reg, function, value64);
- else if (pmic_thermal_is_pen(address))
- result = pmic_thermal_pen(opregion, reg, bit,
- function, value64);
- else
- result = -EINVAL;
-
- mutex_unlock(&opregion->lock);
+ scoped_guard(mutex, &opregion->lock) {
+ if (pmic_thermal_is_temp(address))
+ result = pmic_thermal_temp(opregion, reg, function, value64);
+ else if (pmic_thermal_is_aux(address))
+ result = pmic_thermal_aux(opregion, reg, function, value64);
+ else if (pmic_thermal_is_pen(address))
+ result = pmic_thermal_pen(opregion, reg, bit, function, value64);
+ else
+ result = -EINVAL;
+ }
if (result < 0) {
if (result == -EINVAL)
@@ -354,13 +349,15 @@ int intel_soc_pmic_exec_mipi_pmic_seq_element(u16 i2c_address, u32 reg_address,
d = intel_pmic_opregion->data;
- mutex_lock(&intel_pmic_opregion->lock);
+ guard(mutex)(&intel_pmic_opregion->lock);
if (d->exec_mipi_pmic_seq_element) {
- ret = d->exec_mipi_pmic_seq_element(intel_pmic_opregion->regmap,
+ return d->exec_mipi_pmic_seq_element(intel_pmic_opregion->regmap,
i2c_address, reg_address,
value, mask);
- } else if (d->pmic_i2c_address) {
+ }
+
+ if (d->pmic_i2c_address) {
if (i2c_address == d->pmic_i2c_address) {
ret = regmap_update_bits(intel_pmic_opregion->regmap,
reg_address, mask, value);
@@ -376,8 +373,6 @@ int intel_soc_pmic_exec_mipi_pmic_seq_element(u16 i2c_address, u32 reg_address,
ret = -EOPNOTSUPP;
}
- mutex_unlock(&intel_pmic_opregion->lock);
-
return ret;
}
EXPORT_SYMBOL_GPL(intel_soc_pmic_exec_mipi_pmic_seq_element);
--
2.53.0
next reply other threads:[~2026-04-30 1:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 1:35 Maxwell Doose [this message]
2026-04-30 6:23 ` [PATCH v5] ACPI: pmic: Replace mutex_lock/unlock() with guard()/scoped_guard() Andy Shevchenko
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=20260430013507.46259-1-m32285159@gmail.com \
--to=m32285159@gmail.com \
--cc=andy@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=westeri@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