[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230725124954.3824954-3-Naresh.Solanki@9elements.com>
Date: Tue, 25 Jul 2023 14:49:52 +0200
From: Naresh Solanki <naresh.solanki@...ements.com>
To: Guenter Roeck <linux@...ck-us.net>, linux-hwmon@...r.kernel.org,
Jean Delvare <jdelvare@...e.com>
Cc: Patrick Rudolph <patrick.rudolph@...ements.com>,
Naresh Solanki <Naresh.Solanki@...ements.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH 3/3] pmbus_core: Fix Deadlock
From: Patrick Rudolph <patrick.rudolph@...ements.com>
pmbus_regulator_get_error_flags() will also acquire the update_lock,
thus unlock the mutex before trying to lock it again from within
the same thread.
Fixes a deadlock when trying to read the regulator status.
Signed-off-by: Patrick Rudolph <patrick.rudolph@...ements.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@...ements.com>
---
drivers/hwmon/pmbus/pmbus_core.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 1f7df36c48a8..1151a09243d3 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2946,37 +2946,27 @@ static int pmbus_regulator_get_status(struct regulator_dev *rdev)
mutex_lock(&data->update_lock);
status = pmbus_get_status(client, page, PMBUS_STATUS_WORD);
- if (status < 0) {
- ret = status;
- goto unlock;
- }
+ mutex_unlock(&data->update_lock);
+ if (status < 0)
+ return status;
- if (status & PB_STATUS_OFF) {
- ret = REGULATOR_STATUS_OFF;
- goto unlock;
- }
+ if (status & PB_STATUS_OFF)
+ return REGULATOR_STATUS_OFF;
/* If regulator is ON & reports power good then return ON */
- if (!(status & PB_STATUS_POWER_GOOD_N)) {
- ret = REGULATOR_STATUS_ON;
- goto unlock;
- }
+ if (!(status & PB_STATUS_POWER_GOOD_N))
+ return REGULATOR_STATUS_ON;
ret = pmbus_regulator_get_error_flags(rdev, &status);
if (ret)
- goto unlock;
+ return ret;
if (status & (REGULATOR_ERROR_UNDER_VOLTAGE | REGULATOR_ERROR_OVER_CURRENT |
REGULATOR_ERROR_REGULATION_OUT | REGULATOR_ERROR_FAIL | REGULATOR_ERROR_OVER_TEMP)) {
- ret = REGULATOR_STATUS_ERROR;
- goto unlock;
+ return REGULATOR_STATUS_ERROR;
}
- ret = REGULATOR_STATUS_UNDEFINED;
-
-unlock:
- mutex_unlock(&data->update_lock);
- return ret;
+ return REGULATOR_STATUS_UNDEFINED;
}
static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page)
--
2.41.0
Powered by blists - more mailing lists