Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1184410 > unrolled thread

Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()

Started byKrzysztof Kozlowski <k.kozlowski@samsung.com>
First post2015-07-15 10:20 +0200
Last post2015-07-15 14:50 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply() Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2015-07-15 10:20 +0200
    Re: [PATCH] regulator: core: Fix memory leak in  regulator_resolve_supply() Javier Martinez Canillas <javier@osg.samsung.com> - 2015-07-15 10:40 +0200
      Re: [PATCH] regulator: core: Fix memory leak in  regulator_resolve_supply() Mark Brown <broonie@kernel.org> - 2015-07-15 13:30 +0200
        Re: [PATCH] regulator: core: Fix memory leak in  regulator_resolve_supply() Javier Martinez Canillas <javier@osg.samsung.com> - 2015-07-15 14:50 +0200

#1184410 — Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()

FromKrzysztof Kozlowski <k.kozlowski@samsung.com>
Date2015-07-15 10:20 +0200
SubjectRe: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()
Message-ID<pMq54-1Kj-13@gated-at.bofh.it>
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?

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@vger.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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1184420 — Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()

FromJavier Martinez Canillas <javier@osg.samsung.com>
Date2015-07-15 10:40 +0200
SubjectRe: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()
Message-ID<pMqop-26J-3@gated-at.bofh.it>
In reply to#1184410
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1184703 — Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()

FromMark Brown <broonie@kernel.org>
Date2015-07-15 13:30 +0200
SubjectRe: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()
Message-ID<pMt2W-62p-15@gated-at.bofh.it>
In reply to#1184420

[Multipart message — attachments visible in raw view] — view raw

On Wed, Jul 15, 2015 at 10:38:38AM +0200, Javier Martinez Canillas wrote:
> On 07/15/2015 10:01 AM, Krzysztof Kozlowski wrote:

> > 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

Me too, I've dropped the patch.  At first glance everything looked safe
for multiple calls.

> 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.

The problem is more that it's a separate implementation and not just
using _regulator_get() I think.  A separate, rarely used, path is likely
to have this sort of issue.

[toc] | [prev] | [next] | [standalone]


#1184774 — Re: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()

FromJavier Martinez Canillas <javier@osg.samsung.com>
Date2015-07-15 14:50 +0200
SubjectRe: [PATCH] regulator: core: Fix memory leak in regulator_resolve_supply()
Message-ID<pMuim-7LZ-29@gated-at.bofh.it>
In reply to#1184703
Hello Mark,

On 07/15/2015 01:27 PM, Mark Brown wrote:
> On Wed, Jul 15, 2015 at 10:38:38AM +0200, Javier Martinez Canillas wrote:
>> On 07/15/2015 10:01 AM, Krzysztof Kozlowski wrote:
> 
>>> 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
> 
> Me too, I've dropped the patch.  At first glance everything looked safe
> for multiple calls.
>

Ok.
 
>> 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.
> 
> The problem is more that it's a separate implementation and not just
> using _regulator_get() I think.  A separate, rarely used, path is likely
> to have this sort of issue.
>

Exactly, do you agree then that a try_module_get() is missing in set_supply()?

It is OK if I add that in the same patch in v2 or do you prefer that to be
in a separate patch?

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web