From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753815AbcBWPTM (ORCPT ); Tue, 23 Feb 2016 10:19:12 -0500 Received: from hqemgate14.nvidia.com ([216.228.121.143]:9836 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753737AbcBWPTG (ORCPT ); Tue, 23 Feb 2016 10:19:06 -0500 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Tue, 23 Feb 2016 07:19:00 -0800 Subject: Re: [PATCH] regulator: core: fix error path of regulator_ena_gpio_free To: Krzysztof Adamski , Mark Brown , "linux-tegra@vger.kernel.org" , Linux Kernel Mailing List References: <56CC6979.3050305@nvidia.com> <1456238830-13733-1-git-send-email-krzysztof.adamski@tieto.com> From: Jon Hunter Message-ID: <56CC7863.4080202@nvidia.com> Date: Tue, 23 Feb 2016 15:18:59 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1456238830-13733-1-git-send-email-krzysztof.adamski@tieto.com> X-Originating-IP: [10.21.132.159] X-ClientProxiedBy: UKMAIL102.nvidia.com (10.26.138.15) To UKMAIL102.nvidia.com (10.26.138.15) Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/02/16 14:47, Krzysztof Adamski wrote: > This problem was introduced by: > commit daad134d6649 ("regulator: core: Request GPIO before creating > sysfs entries") > > The error path was not updated correctly and in case > regulator_ena_gpio_free failed, device_unregister was called even though > it was not registered yet. > > Signed-off-by: Krzysztof Adamski > Reported-by: Jon Hunter Nit ... I think that order of the above should be reversed. > --- > drivers/regulator/core.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c > index 6ee9ba4..d1e7859 100644 > --- a/drivers/regulator/core.c > +++ b/drivers/regulator/core.c > @@ -3919,7 +3919,7 @@ regulator_register(const struct regulator_desc *regulator_desc, > if (ret != 0) { > rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", > config->ena_gpio, ret); > - goto wash; > + goto clean; > } > } > > @@ -3942,7 +3942,7 @@ regulator_register(const struct regulator_desc *regulator_desc, > > ret = set_machine_constraints(rdev, constraints); > if (ret < 0) > - goto scrub; > + goto wash; > > if (init_data && init_data->supply_regulator) > rdev->supply_name = init_data->supply_regulator; > @@ -3972,10 +3972,8 @@ out: > unset_supplies: > unset_regulator_supplies(rdev); > > -scrub: > - regulator_ena_gpio_free(rdev); > - > wash: > + regulator_ena_gpio_free(rdev); > device_unregister(&rdev->dev); > /* device core frees rdev */ > rdev = ERR_PTR(ret); What about the case where device_register() fails? I think you still call clean and so you will leak the gpio? Jon