Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: core: make regulator_register() EPROBE_DEFER aware

Sometimes it can happen that the regulator_of_get_init_data() can't
retrieve the config due to a not probed device the regulator depends on.
Fix that by checking the return value of of_parse_cb() and return
EPROBE_DEFER in such cases.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Link: https://lore.kernel.org/r/20190917154021.14693-4-m.felsch@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Marco Felsch and committed by
Mark Brown
f8970d34 131cb121

+27 -5
+13
drivers/regulator/core.c
··· 5053 5053 5054 5054 init_data = regulator_of_get_init_data(dev, regulator_desc, config, 5055 5055 &rdev->dev.of_node); 5056 + 5057 + /* 5058 + * Sometimes not all resources are probed already so we need to take 5059 + * that into account. This happens most the time if the ena_gpiod comes 5060 + * from a gpio extender or something else. 5061 + */ 5062 + if (PTR_ERR(init_data) == -EPROBE_DEFER) { 5063 + kfree(config); 5064 + kfree(rdev); 5065 + ret = -EPROBE_DEFER; 5066 + goto rinse; 5067 + } 5068 + 5056 5069 /* 5057 5070 * We need to keep track of any GPIO descriptor coming from the 5058 5071 * device tree until we have handled it over to the core. If the
+14 -5
drivers/regulator/of_regulator.c
··· 445 445 goto error; 446 446 } 447 447 448 - if (desc->of_parse_cb && desc->of_parse_cb(child, desc, config)) { 449 - dev_err(dev, 450 - "driver callback failed to parse DT for regulator %pOFn\n", 451 - child); 452 - goto error; 448 + if (desc->of_parse_cb) { 449 + int ret; 450 + 451 + ret = desc->of_parse_cb(child, desc, config); 452 + if (ret) { 453 + if (ret == -EPROBE_DEFER) { 454 + of_node_put(child); 455 + return ERR_PTR(-EPROBE_DEFER); 456 + } 457 + dev_err(dev, 458 + "driver callback failed to parse DT for regulator %pOFn\n", 459 + child); 460 + goto error; 461 + } 453 462 } 454 463 455 464 *node = child;