Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965893AbcDMGlm (ORCPT ); Wed, 13 Apr 2016 02:41:42 -0400 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:36762 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757263AbcDMGlk (ORCPT ); Wed, 13 Apr 2016 02:41:40 -0400 From: Mark Brown To: Boris Brezillon Cc: Stephen Barber , Caesar Wang , Mark Brown , Mark Brown , Liam Girdwood , linux-kernel@vger.kernel.org, Caesar Wang , =?UTF-8?q?Heiko=20St=C3=BCbner?= , Stephen Barber , Douglas Anderson , Brian Norris In-Reply-To: <1460457060-3946-1-git-send-email-boris.brezillon@free-electrons.com> Message-Id: Date: Wed, 13 Apr 2016 07:41:28 +0100 X-SA-Exim-Connect-IP: 2a01:348:6:8808:fab::3 X-SA-Exim-Mail-From: broonie@sirena.org.uk Subject: Applied "regulator: reorder initialization steps in regulator_register()" to the regulator tree X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on mezzanine.sirena.org.uk) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3436 Lines: 107 The patch regulator: reorder initialization steps in regulator_register() has been applied to the regulator tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark >From 469b640e4f4a28bdd50f0ac1d2b310907afb464c Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 12 Apr 2016 12:31:00 +0200 Subject: [PATCH] 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 --- drivers/regulator/core.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e0b764284773..8258568c793a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3950,13 +3950,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) @@ -3964,7 +3957,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; @@ -3993,8 +3994,6 @@ out: unset_supplies: unset_regulator_supplies(rdev); - -scrub: regulator_ena_gpio_free(rdev); device_unregister(&rdev->dev); /* device core frees rdev */ @@ -4002,6 +4001,7 @@ scrub: goto out; wash: + kfree(rdev->constraints); regulator_ena_gpio_free(rdev); clean: kfree(rdev); -- 2.8.0.rc3