regulator: core: Limit propagation of parent voltage count and list
PATCH v3 1/1 regulator: core: Limit propagation of parent voltage count and list
Commit 26988efe11b1 ("regulator: core: Allow to get voltage count and list from parent") introduces the propagation of the parent voltage count and list for regulators that don't provide this information themselves. The goal is to support simple switch regulators, however as a side effect normal continuous regulators can leak details of their supplies and provide consumers with inconsistent information.
Limit the propagation of the voltage count and list to switch regulators.
---
Changes in v3:
- Removed unused variable ops from regulator_count_voltages()
- Updated commit message to use correct format for referencing commits (sorry, both stem from using different trees for testing and upstreaming)
drivers/regulator/core.c | 10 ++++++++-- include/linux/regulator/driver.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/regulator/core.c +8 -2
@@ -2486,7 +2486,7 @@ static int _regulator_list_voltage(struct regulator *regulator, ret = ops->list_voltage (rdev, selector);if (lock)mutex_unlock (&rdev->mutex); - }else if (rdev->supply) { + }else if (rdev->is_switch && rdev->supply) { ret =_regulator_list_voltage (rdev->supply, selector, lock); }else {return -EINVAL ;
@@ -2544,7 +2544,7 @@ int regulator_count_voltages(struct regulator *regulator)if (rdev->desc->n_voltages)return rdev->desc->n_voltages; -if (!rdev->supply) +if (!rdev->is_switch || !rdev->supply)return -EINVAL ;return regulator_count_voltages (rdev->supply);
@@ -4099,6 +4099,12 @@ regulator_register(const struct regulator_desc *regulator_desc,mutex_unlock (®ulator_list_mutex); } +if (!rdev->desc->ops->get_voltage && + !rdev->desc->ops->get_voltage_sel && + !rdev->desc->ops->list_voltage && + !rdev->desc->fixed_uV) + rdev->is_switch = true; + ret =device_register (&rdev->dev);if (ret !=0 ) {put_device (&rdev->dev);
include/linux/regulator/driver.h +2 -0
@@ -429,6 +429,8 @@ struct regulator_dev {struct regulator_enable_gpio *ena_pin; unsigned int ena_gpio_state:1; + unsigned int is_switch:1; +/* time when this regulator was disabled last time */ unsigned long last_off_jiffy; };
Signature · 1 line
2.12.2.564.g063fe858b8-goog
Hello Matthias,
Quoted 10 lines · Matthias Kaehlcke
Commit
26988efe11b1("regulator: core: Allow to get voltage count and list from parent") introduces the propagation of the parent voltage count and list for regulators that don't provide this information themselves. The goal is to support simple switch regulators, however as a side effect normal continuous regulators can leak details of their supplies and provide consumers with inconsistent information.Limit the propagation of the voltage count and list to switch regulators.
Should we add a Fixes: 26988efe11b1 ("regulator: core: Allow to get voltage count and list from parent") tag?
Quoted 7 lines
Signed-off-by Matthias Kaehlcke <[email protected]>---
Changes in v3:
- Removed unused variable ops fromregulator_count_voltages()
- Updated commit message to use correct format for referencing commits (sorry, both stem from using different trees for testing and upstreaming)
You should add complete patch history, not only the delta with latest version.
[snip]
drivers/regulator/core.c regulator_register(const struct regulator_desc *regulator_desc, · line 4107
Quoted 7 lines
drivers/regulator/core.c +6
-0+if (!rdev->desc->ops->get_voltage && + !rdev->desc->ops->get_voltage_sel && + !rdev->desc->ops->list_voltage && + !rdev->desc->fixed_uV) + rdev->is_switch = true; +
Again, I think the check for get_voltage_sel is superfluous since !list_voltage implies the former, otherwise regulator_register() would had returned -EINVAL.
Patch looks good to me though and I also see no regressions with it so:
Best regards,
Signature · 3 lines
Javier Martinez Canillas Open Source Group Samsung Research America