Skip to content

Commit d748287

Browse files
committed
Merge tag 'regulator-fix-v5.10-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator fixes from Mark Brown: "Mostly core fixes here, one set from Michał Mirosław which cleans up some issues introduced as part of the coupled regulators work, one memory leak during probe and two due to regulators which have an input supply name and regulator name which are identical, which is very unusual. There's also a fix for our handling of the similarly unusual case where we can't determine if a regulator is enabled during boot" * tag 'regulator-fix-v5.10-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: regulator: ti-abb: Fix array out of bound read access on the first transition regulator: workaround self-referent regulators regulator: avoid resolve_supply() infinite recursion regulator: fix memory leak with repeated set_machine_constraints() regulator: pfuze100: limit pfuze-support-disable-sw to pfuze{100,200} regulator: core: don't disable regulator if is_enabled return error.
2 parents 841d6e9 + 2ba546e commit d748287

3 files changed

Lines changed: 44 additions & 24 deletions

File tree

drivers/regulator/core.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,29 +1315,18 @@ static int _regulator_do_enable(struct regulator_dev *rdev);
13151315
/**
13161316
* set_machine_constraints - sets regulator constraints
13171317
* @rdev: regulator source
1318-
* @constraints: constraints to apply
13191318
*
13201319
* Allows platform initialisation code to define and constrain
13211320
* regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
13221321
* Constraints *must* be set by platform code in order for some
13231322
* regulator operations to proceed i.e. set_voltage, set_current_limit,
13241323
* set_mode.
13251324
*/
1326-
static int set_machine_constraints(struct regulator_dev *rdev,
1327-
const struct regulation_constraints *constraints)
1325+
static int set_machine_constraints(struct regulator_dev *rdev)
13281326
{
13291327
int ret = 0;
13301328
const struct regulator_ops *ops = rdev->desc->ops;
13311329

1332-
if (constraints)
1333-
rdev->constraints = kmemdup(constraints, sizeof(*constraints),
1334-
GFP_KERNEL);
1335-
else
1336-
rdev->constraints = kzalloc(sizeof(*constraints),
1337-
GFP_KERNEL);
1338-
if (!rdev->constraints)
1339-
return -ENOMEM;
1340-
13411330
ret = machine_constraints_voltage(rdev, rdev->constraints);
13421331
if (ret != 0)
13431332
return ret;
@@ -1852,6 +1841,15 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
18521841
}
18531842
}
18541843

1844+
if (r == rdev) {
1845+
dev_err(dev, "Supply for %s (%s) resolved to itself\n",
1846+
rdev->desc->name, rdev->supply_name);
1847+
if (!have_full_constraints())
1848+
return -EINVAL;
1849+
r = dummy_regulator_rdev;
1850+
get_device(&r->dev);
1851+
}
1852+
18551853
/*
18561854
* If the supply's parent device is not the same as the
18571855
* regulator's parent device, then ensure the parent device
@@ -5146,7 +5144,6 @@ struct regulator_dev *
51465144
regulator_register(const struct regulator_desc *regulator_desc,
51475145
const struct regulator_config *cfg)
51485146
{
5149-
const struct regulation_constraints *constraints = NULL;
51505147
const struct regulator_init_data *init_data;
51515148
struct regulator_config *config = NULL;
51525149
static atomic_t regulator_no = ATOMIC_INIT(-1);
@@ -5285,14 +5282,23 @@ regulator_register(const struct regulator_desc *regulator_desc,
52855282

52865283
/* set regulator constraints */
52875284
if (init_data)
5288-
constraints = &init_data->constraints;
5285+
rdev->constraints = kmemdup(&init_data->constraints,
5286+
sizeof(*rdev->constraints),
5287+
GFP_KERNEL);
5288+
else
5289+
rdev->constraints = kzalloc(sizeof(*rdev->constraints),
5290+
GFP_KERNEL);
5291+
if (!rdev->constraints) {
5292+
ret = -ENOMEM;
5293+
goto wash;
5294+
}
52895295

52905296
if (init_data && init_data->supply_regulator)
52915297
rdev->supply_name = init_data->supply_regulator;
52925298
else if (regulator_desc->supply_name)
52935299
rdev->supply_name = regulator_desc->supply_name;
52945300

5295-
ret = set_machine_constraints(rdev, constraints);
5301+
ret = set_machine_constraints(rdev);
52965302
if (ret == -EPROBE_DEFER) {
52975303
/* Regulator might be in bypass mode and so needs its supply
52985304
* to set the constraints */
@@ -5301,7 +5307,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
53015307
* that is just being created */
53025308
ret = regulator_resolve_supply(rdev);
53035309
if (!ret)
5304-
ret = set_machine_constraints(rdev, constraints);
5310+
ret = set_machine_constraints(rdev);
53055311
else
53065312
rdev_dbg(rdev, "unable to resolve supply early: %pe\n",
53075313
ERR_PTR(ret));
@@ -5843,13 +5849,14 @@ static int regulator_late_cleanup(struct device *dev, void *data)
58435849
if (rdev->use_count)
58445850
goto unlock;
58455851

5846-
/* If we can't read the status assume it's on. */
5852+
/* If we can't read the status assume it's always on. */
58475853
if (ops->is_enabled)
58485854
enabled = ops->is_enabled(rdev);
58495855
else
58505856
enabled = 1;
58515857

5852-
if (!enabled)
5858+
/* But if reading the status failed, assume that it's off. */
5859+
if (enabled <= 0)
58535860
goto unlock;
58545861

58555862
if (have_full_constraints()) {

drivers/regulator/pfuze100-regulator.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,14 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
836836
* the switched regulator till yet.
837837
*/
838838
if (pfuze_chip->flags & PFUZE_FLAG_DISABLE_SW) {
839-
if (pfuze_chip->regulator_descs[i].sw_reg) {
840-
desc->ops = &pfuze100_sw_disable_regulator_ops;
841-
desc->enable_val = 0x8;
842-
desc->disable_val = 0x0;
843-
desc->enable_time = 500;
839+
if (pfuze_chip->chip_id == PFUZE100 ||
840+
pfuze_chip->chip_id == PFUZE200) {
841+
if (pfuze_chip->regulator_descs[i].sw_reg) {
842+
desc->ops = &pfuze100_sw_disable_regulator_ops;
843+
desc->enable_val = 0x8;
844+
desc->disable_val = 0x0;
845+
desc->enable_time = 500;
846+
}
844847
}
845848
}
846849

drivers/regulator/ti-abb-regulator.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,25 @@ static int ti_abb_set_voltage_sel(struct regulator_dev *rdev, unsigned sel)
342342
return ret;
343343
}
344344

345-
/* If data is exactly the same, then just update index, no change */
346345
info = &abb->info[sel];
346+
/*
347+
* When Linux kernel is starting up, we are'nt sure of the
348+
* Bias configuration that bootloader has configured.
349+
* So, we get to know the actual setting the first time
350+
* we are asked to transition.
351+
*/
352+
if (abb->current_info_idx == -EINVAL)
353+
goto just_set_abb;
354+
355+
/* If data is exactly the same, then just update index, no change */
347356
oinfo = &abb->info[abb->current_info_idx];
348357
if (!memcmp(info, oinfo, sizeof(*info))) {
349358
dev_dbg(dev, "%s: Same data new idx=%d, old idx=%d\n", __func__,
350359
sel, abb->current_info_idx);
351360
goto out;
352361
}
353362

363+
just_set_abb:
354364
ret = ti_abb_set_opp(rdev, abb, info);
355365

356366
out:

0 commit comments

Comments
 (0)