All of lore.kernel.org
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <javier@osg.samsung.com>
To: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Cc: Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()
Date: Wed, 15 Jul 2015 10:38:38 +0200	[thread overview]
Message-ID: <55A61C0E.4040707@osg.samsung.com> (raw)
In-Reply-To: <CAJKOXPf8WG5LQdEc4ZKAoTP3pbDm2QGgKRp7BJ-N2PKrrXGFbA@mail.gmail.com>

Hello Krzysztof,

Thanks a lot for your feedback.

On 07/15/2015 10:01 AM, Krzysztof Kozlowski wrote:
> 2015-07-14 23:21 GMT+09:00 Javier Martinez Canillas <javier@osg.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@osg.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?
>

Yes, it reverts more work than create_regulator() but the intention is to
revert what set_supply() did. If you look at the set_supply() function,
it does supply_rdev->open_count++.

I did indeed missed the module_put() but now looking at the code again, I
wonder if the problem is not that set_supply() is missing a try_module_get()
to be consistent with what the _regulator_get() function does.
 
> Best regards,
> Krzysztof
>

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America

  reply	other threads:[~2015-07-15  8:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14 14:21 [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply() Javier Martinez Canillas
2015-07-15  8:01 ` Krzysztof Kozlowski
2015-07-15  8:38   ` Javier Martinez Canillas [this message]
2015-07-15 11:27     ` Mark Brown
2015-07-15 12:46       ` Javier Martinez Canillas
2015-07-15 15:52         ` Mark Brown
2015-07-15 15:56           ` Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55A61C0E.4040707@osg.samsung.com \
    --to=javier@osg.samsung.com \
    --cc=broonie@kernel.org \
    --cc=k.kozlowski@samsung.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.