From: Boris Brezillon Date: Tue, 12 Apr 2016 10:31:00 +0000 (+0200) Subject: UPSTREAM: regulator: reorder initialization steps in regulator_register() X-Git-Tag: firefly_0821_release~466 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=286d645c529781e8cb5b44f97d1d5adfa42f6d4d;p=firefly-linux-kernel-4.4.55.git UPSTREAM: regulator: reorder initialization steps in regulator_register() device_register() is calling ->get_voltage() as part of it's sysfs attribute initialization process, and this functions might need to know the regulator constraints to return a valid value. This is at least true for the pwm regulator driver (when operating in continuous mode) which needs to know the minimum and maximum voltage values to calculate the current voltage: min_uV + (((max_uV - min_uV) * dutycycle) / 100); Move device_register() after set_machine_constraints() to make sure those constraints are correctly initialized when ->get_voltage() is called. Signed-off-by: Boris Brezillon Reported-by: Stephen Barber Tested-by: Caesar Wang Signed-off-by: Mark Brown (cherry picked from commit 469b640e4f4a28bdd50f0ac1d2b310907afb464c) Change-Id: I83c95e5baef0501876d19f1e2e7a7e3af8631b1f Signed-off-by: David Wu --- diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index f87310970f17..9aa91fcc2d3e 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3976,13 +3976,6 @@ regulator_register(const struct regulator_desc *regulator_desc, rdev->dev.parent = dev; dev_set_name(&rdev->dev, "regulator.%lu", (unsigned long) atomic_inc_return(®ulator_no)); - ret = device_register(&rdev->dev); - if (ret != 0) { - put_device(&rdev->dev); - goto wash; - } - - dev_set_drvdata(&rdev->dev, rdev); /* set regulator constraints */ if (init_data) @@ -3990,7 +3983,15 @@ regulator_register(const struct regulator_desc *regulator_desc, ret = set_machine_constraints(rdev, constraints); if (ret < 0) - goto scrub; + goto wash; + + ret = device_register(&rdev->dev); + if (ret != 0) { + put_device(&rdev->dev); + goto wash; + } + + dev_set_drvdata(&rdev->dev, rdev); if (init_data && init_data->supply_regulator) rdev->supply_name = init_data->supply_regulator; @@ -4022,14 +4023,13 @@ regulator_register(const struct regulator_desc *regulator_desc, unset_supplies: unset_regulator_supplies(rdev); - -scrub: regulator_ena_gpio_free(rdev); device_unregister(&rdev->dev); /* device core frees rdev */ goto out; wash: + kfree(rdev->constraints); regulator_ena_gpio_free(rdev); clean: kfree(rdev);