From b7cd1b1386ff46e60452ad1f16530645761ca7b8 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 6 Mar 2017 17:34:48 +0100 Subject: regulator: core: use snprintf() instead of scnprintf() When creating the link to the device sysfs entry, the regulator core calls scnprintf() and then checks if the returned value is greater or equal than the buffer size. The former can never happen as scnprintf() returns the number of bytes that were actually written to the buffer, not the bytes that *would* have been written. Use the right function in this case: snprintf(). Signed-off-by: Bartosz Golaszewski Signed-off-by: Mark Brown --- drivers/regulator/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 53d4fc70dbd0..f20ad0a8fc38 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1326,8 +1326,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, regulator->dev = dev; /* Add a link to the device sysfs entry */ - size = scnprintf(buf, REG_STR_SIZE, "%s-%s", - dev->kobj.name, supply_name); + size = snprintf(buf, REG_STR_SIZE, "%s-%s", + dev->kobj.name, supply_name); if (size >= REG_STR_SIZE) goto overflow_err; -- cgit v1.2.3-59-g8ed1b From 0630b614391f8cbc35e837b4645ec8faaaa6465e Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Thu, 16 Mar 2017 18:07:14 -0700 Subject: regulator: Mark supply_name const and duplicate it as such The supply_name member of struct regulator can be const as we don't change it in the regulator core. Furthermore, when we copy the supply name we can use kstrdup_const() here to avoid a copy if the name is in the ro data section. Signed-off-by: Stephen Boyd Signed-off-by: Mark Brown --- drivers/regulator/core.c | 4 ++-- drivers/regulator/internal.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index f20ad0a8fc38..49a0b6a2e237 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1343,7 +1343,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, /* non-fatal */ } } else { - regulator->supply_name = kstrdup(supply_name, GFP_KERNEL); + regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL); if (regulator->supply_name == NULL) goto overflow_err; } @@ -1799,7 +1799,7 @@ static void _regulator_put(struct regulator *regulator) put_device(&rdev->dev); mutex_unlock(&rdev->mutex); - kfree(regulator->supply_name); + kfree_const(regulator->supply_name); kfree(regulator); module_put(rdev->owner); diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 1dd575b28564..66a8ea0c8386 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -29,7 +29,7 @@ struct regulator { int uA_load; int min_uV; int max_uV; - char *supply_name; + const char *supply_name; struct device_attribute dev_attr; struct regulator_dev *rdev; struct dentry *debugfs; -- cgit v1.2.3-59-g8ed1b From fffd1133388857f5b4b8c588b41b2ade16c7891c Mon Sep 17 00:00:00 2001 From: Tamara Diaconita Date: Tue, 28 Mar 2017 21:30:21 +0300 Subject: regulator: core: Fix kerneldoc comments Remove the description for the non-existing 'ret' to fix the build warning: ./drivers/regulator/core.c:1467: warning: Excess function parameter 'ret' description in 'regulator_dev_lookup'. The description found for the return value is: @ret: 0 on success, -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succeed in the future. Signed-off-by: Tamara Diaconita Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 49a0b6a2e237..c20b28a63d15 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1451,8 +1451,6 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name) * regulator_dev_lookup - lookup a regulator device. * @dev: device for regulator "consumer". * @supply: Supply name or regulator ID. - * @ret: 0 on success, -ENODEV if lookup fails permanently, -EPROBE_DEFER if - * lookup could succeed in the future. * * If successful, returns a struct regulator_dev that corresponds to the name * @supply and with the embedded struct device refcount incremented by one. -- cgit v1.2.3-59-g8ed1b From fd086045559d90cd7854818b4c60a7119eda6231 Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Mon, 27 Mar 2017 16:54:12 -0700 Subject: 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. Fixes: 26988efe11b1 ("regulator: core: Allow to get voltage count and list from parent") Signed-off-by: Matthias Kaehlcke Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas Signed-off-by: Mark Brown --- drivers/regulator/core.c | 9 +++++++-- include/linux/regulator/driver.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index c20b28a63d15..aff302dfab5d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2484,7 +2484,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; @@ -2542,7 +2542,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); @@ -4097,6 +4097,11 @@ regulator_register(const struct regulator_desc *regulator_desc, mutex_unlock(®ulator_list_mutex); } + if (!rdev->desc->ops->get_voltage && + !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); diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index dac8e7b16bc6..4cb1c9be6073 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -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; }; -- cgit v1.2.3-59-g8ed1b From 43fc99f293cc802866bea904ca2f1f8573f236f7 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 13 Apr 2017 18:36:59 +0100 Subject: regulator: core: Only propagate voltage changes to if it can change voltages When we are propagating voltage changes to parent regulators don't bother if the parent does not have permission to change voltages. This simplifies error checking in the function for cases where the regulator lacks some of the voltage operations. Reported-by: Dong Aisheng Tested-by: Dong Aisheng Reviewed-by: Dong Aisheng Signed-off-by: Mark Brown --- drivers/regulator/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index aff302dfab5d..3f424ec4fc56 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2939,8 +2939,10 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, if (ret < 0) goto out2; - if (rdev->supply && (rdev->desc->min_dropout_uV || - !rdev->desc->ops->get_voltage)) { + if (rdev->supply && + regulator_ops_is_valid(rdev->supply->rdev, + REGULATOR_CHANGE_VOLTAGE) && + (rdev->desc->min_dropout_uV || !rdev->desc->ops->get_voltage)) { int current_supply_uV; int selector; -- cgit v1.2.3-59-g8ed1b From c93609ab3924cc974fc90001fb6aa250a8900a3c Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 11 Apr 2017 21:31:40 +0100 Subject: regulator: core: Allow dummy regulators for supplies Rather than just not resolving the supply when there is explicitly no supply mapping fall through and allow a dummy supply to be substituted. This fixes issues with constant retries reported by Dong Aisheng. Signed-off-by: Mark Brown Tested-by: Dong Aisheng Reviewed-by: Dong Aisheng --- drivers/regulator/core.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 3f424ec4fc56..462e6e679ce1 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1532,14 +1532,6 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) if (IS_ERR(r)) { ret = PTR_ERR(r); - if (ret == -ENODEV) { - /* - * No supply was specified for this regulator and - * there will never be one. - */ - return 0; - } - /* Did the lookup explicitly defer for us? */ if (ret == -EPROBE_DEFER) return ret; -- cgit v1.2.3-59-g8ed1b