[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJKOXPf8WG5LQdEc4ZKAoTP3pbDm2QGgKRp7BJ-N2PKrrXGFbA@mail.gmail.com>
Date: Wed, 15 Jul 2015 17:01:43 +0900
From: Krzysztof Kozlowski <k.kozlowski@...sung.com>
To: Javier Martinez Canillas <javier@....samsung.com>
Cc: Mark Brown <broonie@...nel.org>,
Liam Girdwood <lgirdwood@...il.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()
2015-07-14 23:21 GMT+09:00 Javier Martinez Canillas <javier@....samsung.com>:
> The regulator_resolve_supply() function calls set_supply() which in turn
> calls create_regulator() to allocate a supply regulator.
>
> If an error occurs after set_supply() succeeded, the allocated regulator
> has to be freed before propagating the error code.
>
> Signed-off-by: Javier Martinez Canillas <javier@....samsung.com>
>
> ---
>
> drivers/regulator/core.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 68b616580533..325c0f5c13ca 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -109,6 +109,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
> static struct regulator *create_regulator(struct regulator_dev *rdev,
> struct device *dev,
> const char *supply_name);
> +static void _regulator_put(struct regulator *regulator);
>
> static const char *rdev_get_name(struct regulator_dev *rdev)
> {
> @@ -1402,8 +1403,11 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
> /* Cascade always-on state to supply */
> if (_regulator_is_enabled(rdev)) {
> ret = regulator_enable(rdev->supply);
> - if (ret < 0)
> + if (ret < 0) {
> + if (rdev->supply)
> + _regulator_put(rdev->supply);
The _regulator_put() reverts more work than create_regulator() did,
e.g.: module_put and rdev->open_count--. Maybe you need a
destroy_regulator() function?
Best regards,
Krzysztof
> return ret;
> + }
> }
>
> return 0;
> --
> 2.4.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@...r.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists