[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b7a3ad85-aab4-4718-a001-1d8b1c0eef36@roeck-us.net>
Date: Tue, 25 Jul 2023 08:06:45 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: Naresh Solanki <naresh.solanki@...ements.com>
Cc: linux-hwmon@...r.kernel.org, Jean Delvare <jdelvare@...e.com>,
Patrick Rudolph <patrick.rudolph@...ements.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 3/3] pmbus_core: Fix Deadlock
On Tue, Jul 25, 2023 at 02:54:27PM +0200, Naresh Solanki wrote:
> 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.
>
The idea was that the lock would cover both pmbus_get_status()
and pmbus_regulator_get_error_flags() to avoid inconsistencies.
This change defeats that purpose.
> 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 30aeb59062a5..42f4250c53ed 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -2949,37 +2949,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);
Why not just call _pmbus_get_flags() here instead ?
Guenter
> 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)
Powered by blists - more mailing lists