Skip to content

Commit 0bd6678

Browse files
PatrickRudolphgroeck
authored andcommitted
hwmon: (pmbus_core) Fix NULL pointer dereference
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. Fixes: df5f6b6 ("hwmon: (pmbus/core) Generalise pmbus get status") Cc: [email protected] # v6.4 Signed-off-by: Patrick Rudolph <[email protected]> Signed-off-by: Naresh Solanki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 55aab08 commit 0bd6678

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/hwmon/pmbus/pmbus_core.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,9 +2745,8 @@ static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[]
27452745
},
27462746
};
27472747

2748-
static int _pmbus_is_enabled(struct device *dev, u8 page)
2748+
static int _pmbus_is_enabled(struct i2c_client *client, u8 page)
27492749
{
2750-
struct i2c_client *client = to_i2c_client(dev->parent);
27512750
int ret;
27522751

27532752
ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION);
@@ -2758,14 +2757,13 @@ static int _pmbus_is_enabled(struct device *dev, u8 page)
27582757
return !!(ret & PB_OPERATION_CONTROL_ON);
27592758
}
27602759

2761-
static int __maybe_unused pmbus_is_enabled(struct device *dev, u8 page)
2760+
static int __maybe_unused pmbus_is_enabled(struct i2c_client *client, u8 page)
27622761
{
2763-
struct i2c_client *client = to_i2c_client(dev->parent);
27642762
struct pmbus_data *data = i2c_get_clientdata(client);
27652763
int ret;
27662764

27672765
mutex_lock(&data->update_lock);
2768-
ret = _pmbus_is_enabled(dev, page);
2766+
ret = _pmbus_is_enabled(client, page);
27692767
mutex_unlock(&data->update_lock);
27702768

27712769
return ret;
@@ -2844,7 +2842,7 @@ static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flag
28442842
if (status < 0)
28452843
return status;
28462844

2847-
if (_pmbus_is_enabled(dev, page)) {
2845+
if (_pmbus_is_enabled(client, page)) {
28482846
if (status & PB_STATUS_OFF) {
28492847
*flags |= REGULATOR_ERROR_FAIL;
28502848
*event |= REGULATOR_EVENT_FAIL;
@@ -2898,7 +2896,10 @@ static int __maybe_unused pmbus_get_flags(struct pmbus_data *data, u8 page, unsi
28982896
#if IS_ENABLED(CONFIG_REGULATOR)
28992897
static int pmbus_regulator_is_enabled(struct regulator_dev *rdev)
29002898
{
2901-
return pmbus_is_enabled(rdev_get_dev(rdev), rdev_get_id(rdev));
2899+
struct device *dev = rdev_get_dev(rdev);
2900+
struct i2c_client *client = to_i2c_client(dev->parent);
2901+
2902+
return pmbus_is_enabled(client, rdev_get_id(rdev));
29022903
}
29032904

29042905
static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable)

0 commit comments

Comments
 (0)