[PATCH v2] ACPI: pmic: Replace mutex_lock/unlock() with guard()/scoped_guard()

From: Maxwell Doose

Date: Fri Apr 24 2026 - 18:01:21 EST


Replace mutex_lock() and unlock() macros with the newer guard() and
scoped_guard() macros. This will help modernize and clean the code.

Refactor control flow in affected functions by using direct returns,
as we no longer need to manually unlock mutexes at the end of
functions. This will simplify the return logic of affected functions.

In intel_soc_pmic_exec_mipi_pmic_seq_element(): While at it, remove
now redundant "ret" variable.

Signed-off-by: Maxwell Doose <m32285159@xxxxxxxxx>
---
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.

drivers/acpi/pmic/intel_pmic.c | 69 +++++++++++++++-------------------
1 file changed, 30 insertions(+), 39 deletions(-)

diff --git a/drivers/acpi/pmic/intel_pmic.c b/drivers/acpi/pmic/intel_pmic.c
index 134e9ca8eaa2..5c37a8f28e71 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(&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,27 +180,23 @@ static acpi_status intel_pmic_thermal_handler(u32 function,
if (result == -ENOENT)
return AE_BAD_PARAMETER;

- mutex_lock(&opregion->lock);
+ scoped_guard(&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,
+ 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);
-
- if (result < 0) {
- if (result == -EINVAL)
- return AE_BAD_PARAMETER;
else
- return AE_ERROR;
+ return AE_BAD_PARAMETER;
+
}

+ if (result < 0)
+ return AE_ERROR;
+
return AE_OK;
}

@@ -345,7 +339,6 @@ int intel_soc_pmic_exec_mipi_pmic_seq_element(u16 i2c_address, u32 reg_address,
u32 value, u32 mask)
{
const struct intel_pmic_opregion_data *d;
- int ret;

if (!intel_pmic_opregion) {
pr_warn("%s: No PMIC registered\n", __func__);
@@ -354,30 +347,28 @@ 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(&intel_pmic_opregion->lock);

if (d->exec_mipi_pmic_seq_element) {
- ret = d->exec_mipi_pmic_seq_element(intel_pmic_opregion->regmap,
- i2c_address, reg_address,
- value, mask);
- } else if (d->pmic_i2c_address) {
+ return d->exec_mipi_pmic_seq_element(intel_pmic_opregion->regmap,
+ i2c_address, reg_address,
+ value, mask);
+ }
+
+ if (d->pmic_i2c_address) {
if (i2c_address == d->pmic_i2c_address) {
- ret = regmap_update_bits(intel_pmic_opregion->regmap,
- reg_address, mask, value);
- } else {
- pr_err("%s: Unexpected i2c-addr: 0x%02x (reg-addr 0x%x value 0x%x mask 0x%x)\n",
- __func__, i2c_address, reg_address, value, mask);
- ret = -ENXIO;
+ return regmap_update_bits(intel_pmic_opregion->regmap,
+ reg_address, mask, value);
}
- } else {
- pr_warn("%s: Not implemented\n", __func__);
- pr_warn("%s: i2c-addr: 0x%x reg-addr 0x%x value 0x%x mask 0x%x\n",
- __func__, i2c_address, reg_address, value, mask);
- ret = -EOPNOTSUPP;
- }

- mutex_unlock(&intel_pmic_opregion->lock);
+ pr_err("%s: Unexpected i2c-addr: 0x%02x (reg-addr 0x%x value 0x%x mask 0x%x)\n",
+ __func__, i2c_address, reg_address, value, mask);
+ return -ENXIO;
+ }

- return ret;
+ pr_warn("%s: Not implemented\n", __func__);
+ pr_warn("%s: i2c-addr: 0x%x reg-addr 0x%x value 0x%x mask 0x%x\n",
+ __func__, i2c_address, reg_address, value, mask);
+ return -EOPNOTSUPP;
}
EXPORT_SYMBOL_GPL(intel_soc_pmic_exec_mipi_pmic_seq_element);
--
2.53.0