Skip to content

Commit d3c7315

Browse files
osctobebroonie
authored andcommitted
regulator: plug of_node leak in regulator_register()'s error path
By calling device_initialize() earlier and noting that kfree(NULL) is ok, we can save a bit of code in error handling and plug of_node leak. Fixed commit already did part of the work. Fixes: 9177514 ("regulator: fix memory leak on error path of regulator_register()") Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Reviewed-by: Vladimir Zapolskiy <vz@mleia.com> Acked-by: Vladimir Zapolskiy <vz@mleia.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/f5035b1b4d40745e66bacd571bbbb5e4644d21a1.1597195321.git.mirq-linux@rere.qmqm.pl Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 5c06540 commit d3c7315

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

drivers/regulator/core.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,16 +5167,16 @@ regulator_register(const struct regulator_desc *regulator_desc,
51675167
ret = -ENOMEM;
51685168
goto rinse;
51695169
}
5170+
device_initialize(&rdev->dev);
51705171

51715172
/*
51725173
* Duplicate the config so the driver could override it after
51735174
* parsing init data.
51745175
*/
51755176
config = kmemdup(cfg, sizeof(*cfg), GFP_KERNEL);
51765177
if (config == NULL) {
5177-
kfree(rdev);
51785178
ret = -ENOMEM;
5179-
goto rinse;
5179+
goto clean;
51805180
}
51815181

51825182
init_data = regulator_of_get_init_data(dev, regulator_desc, config,
@@ -5188,10 +5188,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
51885188
* from a gpio extender or something else.
51895189
*/
51905190
if (PTR_ERR(init_data) == -EPROBE_DEFER) {
5191-
kfree(config);
5192-
kfree(rdev);
51935191
ret = -EPROBE_DEFER;
5194-
goto rinse;
5192+
goto clean;
51955193
}
51965194

51975195
/*
@@ -5244,7 +5242,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
52445242
}
52455243

52465244
/* register with sysfs */
5247-
device_initialize(&rdev->dev);
52485245
rdev->dev.class = &regulator_class;
52495246
rdev->dev.parent = dev;
52505247
dev_set_name(&rdev->dev, "regulator.%lu",
@@ -5322,13 +5319,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
53225319
mutex_lock(&regulator_list_mutex);
53235320
regulator_ena_gpio_free(rdev);
53245321
mutex_unlock(&regulator_list_mutex);
5325-
put_device(&rdev->dev);
5326-
rdev = NULL;
53275322
clean:
53285323
if (dangling_of_gpiod)
53295324
gpiod_put(config->ena_gpiod);
5330-
kfree(rdev);
53315325
kfree(config);
5326+
put_device(&rdev->dev);
53325327
rinse:
53335328
if (dangling_cfg_gpiod)
53345329
gpiod_put(cfg->ena_gpiod);

0 commit comments

Comments
 (0)