All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: Fix memory leak in set_machine_constraints() error paths
@ 2011-07-14 13:29 Axel Lin
  2011-07-14 23:48 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Axel Lin @ 2011-07-14 13:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: Liam Girdwood, Mark Brown

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/core.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index f59821f..e7655a5 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -787,7 +787,6 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
 		if (ret < 0) {
 			rdev_err(rdev, "failed to apply %duV constraint\n",
 				 rdev->constraints->min_uV);
-			rdev->constraints = NULL;
 			return ret;
 		}
 	}
@@ -873,7 +872,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
 static int set_machine_constraints(struct regulator_dev *rdev,
 	const struct regulation_constraints *constraints)
 {
-	int ret = 0;
+	int ret;
 	struct regulator_ops *ops = rdev->desc->ops;
 
 	rdev->constraints = kmemdup(constraints, sizeof(*constraints),
@@ -890,7 +889,6 @@ static int set_machine_constraints(struct regulator_dev *rdev,
 		ret = suspend_prepare(rdev, rdev->constraints->initial_state);
 		if (ret < 0) {
 			rdev_err(rdev, "failed to set suspend state\n");
-			rdev->constraints = NULL;
 			goto out;
 		}
 	}
@@ -917,13 +915,15 @@ static int set_machine_constraints(struct regulator_dev *rdev,
 		ret = ops->enable(rdev);
 		if (ret < 0) {
 			rdev_err(rdev, "failed to enable\n");
-			rdev->constraints = NULL;
 			goto out;
 		}
 	}
 
 	print_constraints(rdev);
+	return 0;
 out:
+	kfree(rdev->constraints);
+	rdev->constraints = NULL;
 	return ret;
 }
 
-- 
1.7.4.1




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: Fix memory leak in set_machine_constraints() error paths
  2011-07-14 13:29 [PATCH] regulator: Fix memory leak in set_machine_constraints() error paths Axel Lin
@ 2011-07-14 23:48 ` Mark Brown
  2011-07-15  0:44   ` Axel Lin
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2011-07-14 23:48 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Liam Girdwood

On Thu, Jul 14, 2011 at 09:29:19PM +0800, Axel Lin wrote:
>  static int set_machine_constraints(struct regulator_dev *rdev,
>  	const struct regulation_constraints *constraints)
>  {
> -	int ret = 0;
> +	int ret;
>  	struct regulator_ops *ops = rdev->desc->ops;
>  

This doesn't look like a leak fix?  There's nothing that checks for
other errors here (like null pointers)?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: Fix memory leak in set_machine_constraints() error paths
  2011-07-14 23:48 ` Mark Brown
@ 2011-07-15  0:44   ` Axel Lin
  2011-07-15  2:43     ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Axel Lin @ 2011-07-15  0:44 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Liam Girdwood

2011/7/15 Mark Brown <broonie@opensource.wolfsonmicro.com>:
> On Thu, Jul 14, 2011 at 09:29:19PM +0800, Axel Lin wrote:
>>  static int set_machine_constraints(struct regulator_dev *rdev,
>>       const struct regulation_constraints *constraints)
>>  {
>> -     int ret = 0;
>> +     int ret;
>>       struct regulator_ops *ops = rdev->desc->ops;
>>
>
> This doesn't look like a leak fix?  There's nothing that checks for
> other errors here (like null pointers)?
>

I think it does checking null pointer for rdev->constraints in current
implementation:

static int set_machine_constraints(struct regulator_dev *rdev,
        const struct regulation_constraints *constraints)
{
        int ret;
        struct regulator_ops *ops = rdev->desc->ops;

        rdev->constraints = kmemdup(constraints, sizeof(*constraints),
                                    GFP_KERNEL);
        if (!rdev->constraints)
                return -ENOMEM;


Regards,
Axel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: Fix memory leak in set_machine_constraints() error paths
  2011-07-15  0:44   ` Axel Lin
@ 2011-07-15  2:43     ` Mark Brown
  2011-07-15  2:48       ` Axel Lin
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2011-07-15  2:43 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Liam Girdwood

On Fri, Jul 15, 2011 at 08:44:53AM +0800, Axel Lin wrote:

> I think it does checking null pointer for rdev->constraints in current
> implementation:

So, then does this perhaps open paths where ret might be used
uninitialized?  In general this seems like an unrelated stylistic change
which is unfortunately hard to review from a context diff alone.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] regulator: Fix memory leak in set_machine_constraints() error paths
  2011-07-15  2:43     ` Mark Brown
@ 2011-07-15  2:48       ` Axel Lin
  0 siblings, 0 replies; 5+ messages in thread
From: Axel Lin @ 2011-07-15  2:48 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Liam Girdwood

> So, then does this perhaps open paths where ret might be used
> uninitialized?  In general this seems like an unrelated stylistic change
> which is unfortunately hard to review from a context diff alone.
>
I got your point. will send a new version of the patch.

Thanks,
Axel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-15  2:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-14 13:29 [PATCH] regulator: Fix memory leak in set_machine_constraints() error paths Axel Lin
2011-07-14 23:48 ` Mark Brown
2011-07-15  0:44   ` Axel Lin
2011-07-15  2:43     ` Mark Brown
2011-07-15  2:48       ` Axel Lin

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.