pmbus_core: Refactor pmbus_is_enabled function
PATCH 1/3 pmbus_core: Refactor pmbus_is_enabled function
From: Patrick Rudolph <[email protected]>
Refactor the pmbus_is_enabled() function to return the raw status without any additional processing as its already done in _pmbus_is_enabled function.
--- drivers/hwmon/pmbus/pmbus_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus_core.c +1 -1
@@ -2768,7 +2768,7 @@ static int __maybe_unused pmbus_is_enabled(struct device *dev, u8 page) ret =_pmbus_is_enabled (dev, page);mutex_unlock (&data->update_lock); -return !!(ret &PB_OPERATION_CONTROL_ON ); +return ret; }#define to_dev_attr (_dev_attr) \
base-commit: 55612007f16b5d7b1fb83a7b0f5bb686829db7c7
Signature · 1 line
2.41.0
PATCH 2/3 pmbus_core: Fix NULL pointer dereference
From: Patrick Rudolph <[email protected]>
Pass i2c_client to _pmbus_is_enabled to drop the assumption that a regulator device is passed in.
This will fix the issue of a NULL pointer dereference when called from _pmbus_get_flags.
--- drivers/hwmon/pmbus/pmbus_core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +4 -6
@@ -2745,9 +2745,8 @@ static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[] }, }; -static int _pmbus_is_enabled (struct device *dev,u8 page) +static int _pmbus_is_enabled (struct i2c_client *client,u8 page) { -struct i2c_client *client =to_i2c_client (dev->parent);int ret; ret =_pmbus_read_byte_data (client, page,PMBUS_OPERATION );
@@ -2758,14 +2757,13 @@ static int _pmbus_is_enabled(struct device *dev, u8 page)return !!(ret &PB_OPERATION_CONTROL_ON ); } -static int __maybe_unused pmbus_is_enabled (struct device *dev,u8 page) +static int __maybe_unused pmbus_is_enabled (struct i2c_client *client,u8 page) { -struct i2c_client *client =to_i2c_client (dev->parent);struct pmbus_data *data =i2c_get_clientdata (client);int ret;mutex_lock (&data->update_lock); - ret =_pmbus_is_enabled (dev, page); + ret =_pmbus_is_enabled (client, page);mutex_unlock (&data->update_lock);return ret;
@@ -2844,7 +2842,7 @@ static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flagif (status <0 )return status; -if (_pmbus_is_enabled (dev, page)) { +if (_pmbus_is_enabled (client, page)) {if (status &PB_STATUS_OFF ) { *flags |=REGULATOR_ERROR_FAIL ; *event |=REGULATOR_EVENT_FAIL ;
Signature · 1 line
2.41.0
PATCH 3/3 pmbus_core: Fix Deadlock
In reply to Naresh SolankiFrom: Patrick Rudolph <[email protected]>
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.
--- drivers/hwmon/pmbus/pmbus_core.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +10 -20
@@ -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)
Signature · 1 line
2.41.0