regulator: fix memory leak with repeated set_machine_constraints()
Fixed commit introduced a possible second call to
set_machine_constraints() and that allocates memory for
rdev->constraints. Move the allocation to the caller so
it's easier to manage and done once.
Fixes: aea6cb9970
("regulator: resolve supply after creating regulator")
Cc: stable@vger.kernel.org
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Tested-by: Ahmad Fatoum <a.fatoum@pengutronix.de> # stpmic1
Link: https://lore.kernel.org/r/78c3d4016cebc08d441aad18cb924b4e4d9cf9df.1605226675.git.mirq-linux@rere.qmqm.pl
Signed-off-by: Mark Brown <broonie@kernel.org>
zero-sugar-mainline-defconfig
parent
365ec8b616
commit
57a6ad482a
|
@ -1315,7 +1315,6 @@ static int _regulator_do_enable(struct regulator_dev *rdev);
|
||||||
/**
|
/**
|
||||||
* set_machine_constraints - sets regulator constraints
|
* set_machine_constraints - sets regulator constraints
|
||||||
* @rdev: regulator source
|
* @rdev: regulator source
|
||||||
* @constraints: constraints to apply
|
|
||||||
*
|
*
|
||||||
* Allows platform initialisation code to define and constrain
|
* Allows platform initialisation code to define and constrain
|
||||||
* regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
|
* regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
|
||||||
|
@ -1323,21 +1322,11 @@ static int _regulator_do_enable(struct regulator_dev *rdev);
|
||||||
* regulator operations to proceed i.e. set_voltage, set_current_limit,
|
* regulator operations to proceed i.e. set_voltage, set_current_limit,
|
||||||
* set_mode.
|
* set_mode.
|
||||||
*/
|
*/
|
||||||
static int set_machine_constraints(struct regulator_dev *rdev,
|
static int set_machine_constraints(struct regulator_dev *rdev)
|
||||||
const struct regulation_constraints *constraints)
|
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
const struct regulator_ops *ops = rdev->desc->ops;
|
const struct regulator_ops *ops = rdev->desc->ops;
|
||||||
|
|
||||||
if (constraints)
|
|
||||||
rdev->constraints = kmemdup(constraints, sizeof(*constraints),
|
|
||||||
GFP_KERNEL);
|
|
||||||
else
|
|
||||||
rdev->constraints = kzalloc(sizeof(*constraints),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!rdev->constraints)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
ret = machine_constraints_voltage(rdev, rdev->constraints);
|
ret = machine_constraints_voltage(rdev, rdev->constraints);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -5146,7 +5135,6 @@ struct regulator_dev *
|
||||||
regulator_register(const struct regulator_desc *regulator_desc,
|
regulator_register(const struct regulator_desc *regulator_desc,
|
||||||
const struct regulator_config *cfg)
|
const struct regulator_config *cfg)
|
||||||
{
|
{
|
||||||
const struct regulation_constraints *constraints = NULL;
|
|
||||||
const struct regulator_init_data *init_data;
|
const struct regulator_init_data *init_data;
|
||||||
struct regulator_config *config = NULL;
|
struct regulator_config *config = NULL;
|
||||||
static atomic_t regulator_no = ATOMIC_INIT(-1);
|
static atomic_t regulator_no = ATOMIC_INIT(-1);
|
||||||
|
@ -5285,14 +5273,23 @@ regulator_register(const struct regulator_desc *regulator_desc,
|
||||||
|
|
||||||
/* set regulator constraints */
|
/* set regulator constraints */
|
||||||
if (init_data)
|
if (init_data)
|
||||||
constraints = &init_data->constraints;
|
rdev->constraints = kmemdup(&init_data->constraints,
|
||||||
|
sizeof(*rdev->constraints),
|
||||||
|
GFP_KERNEL);
|
||||||
|
else
|
||||||
|
rdev->constraints = kzalloc(sizeof(*rdev->constraints),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!rdev->constraints) {
|
||||||
|
ret = -ENOMEM;
|
||||||
|
goto wash;
|
||||||
|
}
|
||||||
|
|
||||||
if (init_data && init_data->supply_regulator)
|
if (init_data && init_data->supply_regulator)
|
||||||
rdev->supply_name = init_data->supply_regulator;
|
rdev->supply_name = init_data->supply_regulator;
|
||||||
else if (regulator_desc->supply_name)
|
else if (regulator_desc->supply_name)
|
||||||
rdev->supply_name = regulator_desc->supply_name;
|
rdev->supply_name = regulator_desc->supply_name;
|
||||||
|
|
||||||
ret = set_machine_constraints(rdev, constraints);
|
ret = set_machine_constraints(rdev);
|
||||||
if (ret == -EPROBE_DEFER) {
|
if (ret == -EPROBE_DEFER) {
|
||||||
/* Regulator might be in bypass mode and so needs its supply
|
/* Regulator might be in bypass mode and so needs its supply
|
||||||
* to set the constraints */
|
* to set the constraints */
|
||||||
|
@ -5301,7 +5298,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
|
||||||
* that is just being created */
|
* that is just being created */
|
||||||
ret = regulator_resolve_supply(rdev);
|
ret = regulator_resolve_supply(rdev);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = set_machine_constraints(rdev, constraints);
|
ret = set_machine_constraints(rdev);
|
||||||
else
|
else
|
||||||
rdev_dbg(rdev, "unable to resolve supply early: %pe\n",
|
rdev_dbg(rdev, "unable to resolve supply early: %pe\n",
|
||||||
ERR_PTR(ret));
|
ERR_PTR(ret));
|
||||||
|
|
Loading…
Reference in New Issue