2010-11-02 12:23:15

by Mattias Wallin

[permalink] [raw]
Subject: [PATCH] regulator: regulator disable supply fix

This patch fixes a disable failure when regulator supply is used.
A while loop in regulator disable checks for supply pointer != NULL
but the pointer is not always updated, resulting in the while loop
running too many times causing a disable failure.

Signed-off-by: Mattias Wallin <[email protected]>
---
drivers/regulator/core.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index f1d10c9..dc7d36e 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1424,6 +1424,7 @@ int regulator_disable(struct regulator *regulator)
/* decrease our supplies ref count and disable if required */
while (supply_rdev != NULL) {
rdev = supply_rdev;
+ supply_rdev = NULL;

mutex_lock(&rdev->mutex);
_regulator_disable(rdev, &supply_rdev);
--
1.6.3.3


2010-11-02 13:19:50

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regulator: regulator disable supply fix

On Tue, Nov 02, 2010 at 01:22:29PM +0100, Mattias Wallin wrote:
> This patch fixes a disable failure when regulator supply is used.
> A while loop in regulator disable checks for supply pointer != NULL
> but the pointer is not always updated, resulting in the while loop
> running too many times causing a disable failure.

> Signed-off-by: Mattias Wallin <[email protected]>

Hrm. This does fix the problem which is needed so:

Acked-by: Mark Brown <[email protected]>

> ---
> drivers/regulator/core.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index f1d10c9..dc7d36e 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -1424,6 +1424,7 @@ int regulator_disable(struct regulator *regulator)
> /* decrease our supplies ref count and disable if required */
> while (supply_rdev != NULL) {
> rdev = supply_rdev;
> + supply_rdev = NULL;
>
> mutex_lock(&rdev->mutex);
> _regulator_disable(rdev, &supply_rdev);

but this does smell a bit like it ought to be in the _regulator_disable()
call rather than the caller.

2010-11-02 13:46:11

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regulator: regulator disable supply fix

On Tue, Nov 02, 2010 at 02:45:26PM +0100, Mattias Wallin wrote:

> > but this does smell a bit like it ought to be in the _regulator_disable()
> > call rather than the caller.

> Would you prefer below solution instead?

Yes.

2010-11-02 14:03:23

by Mattias Wallin

[permalink] [raw]
Subject: Re: [PATCH] regulator: regulator disable supply fix



On 11/02/2010 02:19 PM, Mark Brown wrote:
> On Tue, Nov 02, 2010 at 01:22:29PM +0100, Mattias Wallin wrote:
>> This patch fixes a disable failure when regulator supply is used.
>> A while loop in regulator disable checks for supply pointer != NULL
>> but the pointer is not always updated, resulting in the while loop
>> running too many times causing a disable failure.
>
>> Signed-off-by: Mattias Wallin <[email protected]>
>
> Hrm. This does fix the problem which is needed so:
>
> Acked-by: Mark Brown <[email protected]>
>
>> ---
>> drivers/regulator/core.c | 1 +
>> 1 files changed, 1 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
>> index f1d10c9..dc7d36e 100644
>> --- a/drivers/regulator/core.c
>> +++ b/drivers/regulator/core.c
>> @@ -1424,6 +1424,7 @@ int regulator_disable(struct regulator *regulator)
>> /* decrease our supplies ref count and disable if required */
>> while (supply_rdev != NULL) {
>> rdev = supply_rdev;
>> + supply_rdev = NULL;
>>
>> mutex_lock(&rdev->mutex);
>> _regulator_disable(rdev, &supply_rdev);
>
> but this does smell a bit like it ought to be in the _regulator_disable()
> call rather than the caller.

Would you prefer below solution instead?

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index dc7d36e..51f66b2 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1359,6 +1359,7 @@ static int _regulator_disable(struct regulator_dev *rdev,
struct regulator_dev **supply_rdev_ptr)
{
int ret = 0;
+ *supply_rdev_ptr = NULL;

if (WARN(rdev->use_count <= 0,
"unbalanced disables for %s\n",