regulator: lock supply in regulator enable
PATCH 1/1 regulator: lock supply in regulator enable
This patch add locks around regulator supply enable.
---
The previous patch I sent solves a problem seen in our system. This patch does not solve a problem I have seen but I still think it should be there. Or at least some locking of the supply in regulator enable. What do you guys think?
--- drivers/regulator/core.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/regulator/core.c +2 -0
@@ -1270,7 +1270,9 @@ static int _regulator_enable(struct regulator_dev *rdev)/* do we need to enable the supply regulator first */ if (rdev->supply) { +mutex_lock (&rdev->supply->mutex); ret =_regulator_enable (rdev->supply); +mutex_unlock (&rdev->supply->mutex);if (ret <0 ) {printk (KERN_ERR "%s: failed to enable %s: %d\n" , __func__,rdev_get_name (rdev), ret);
Signature · 1 line
1.6.3.3
Quoted 8 lines · Mattias Wallin
This patch add locks around regulator supply enable.
Signed-off-by Mattias Wallin <[email protected]>---
The previous patch I sent solves a problem seen in our system. This patch does not solve a problem I have seen but I still think it should be there. Or at least some locking of the supply in regulator enable. What do you guys think?
This sounds like guesswork. What exactly is the problem in your system ?
Liam
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
As I wrote, the problem that I had is solved with my previous patch. Right now I have no visible problem but I still think there is locks missing and would like your opinion on it.
/Wallin
Quoted 13 lines · Liam Girdwood
Quoted 8 lines · Mattias Wallin
This patch add locks around regulator supply enable.
Signed-off-by Mattias Wallin <[email protected]>---
The previous patch I sent solves a problem seen in our system. This patch does not solve a problem I have seen but I still think it should be there. Or at least some locking of the supply in regulator enable. What do you guys think?This sounds like guesswork. What exactly is the problem in your system ?
Liam
Quoted 4 lines · Mattias Wallin
As I wrote, the problem that I had is solved with my previous patch. Right now I have no visible problem but I still think there is locks missing and would like your opinion on it.
Quoted 15 lines
/Wallin
Quoted 12 lines · Liam Girdwood
Quoted 8 lines · Mattias Wallin
This patch add locks around regulator supply enable.
Signed-off-by Mattias Wallin <[email protected]>---
The previous patch I sent solves a problem seen in our system. This patch does not solve a problem I have seen but I still think it should be there. Or at least some locking of the supply in regulator enable. What do you guys think?This sounds like guesswork. What exactly is the problem in your system ?
Sorry, got a busy schedule atm. Can you give us your reasoning behind why you think we need a lock here ?
Thanks
Liam
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Quoted 3 lines
Sorry, got a busy schedule atm. Can you give us your reasoning behind why you think we need a lock here ?
Yes, when we enter regulator_enable() we take the lock only for that specific regulator rdev->mutex
and calls the locked function _regulator_enable().
This locked function then checks if we have a supply and recursively calls the locked _regulator_enable() again but with the supply rdev as argument. The supply rdev regulator is however not locked at this stage, only the "original" supplied regulator is locked.
So if we have two regulators with the same supply regulator trying to enable at approx. the same time they will both
enter the _regulator_enable without locks and we could get a race condition.
This would probably result in reference counting error and unbalanced regulator warnings.
In our system we make use the regulator hierarchy quite heavily.
Quoted 4 lines
Thanks
Liam
/Mattias Wallin
Liam Girdwood
AppliedQuoted 10 lines · Mattias Wallin
Quoted 2 lines
Sorry, got a busy schedule atm. Can you give us your reasoning behind why you think we need a lock here ?
Yes, when we enter
regulator_enable()we take the lock only for that specific regulatorrdev->mutex
and calls the locked function_regulator_enable().
This locked function then checks if we have a supply and recursively calls the locked_regulator_enable()again but with the supply rdev as argument. The supply rdev regulator is however not locked at this stage, only the "original" supplied regulator is locked.
So if we have two regulators with the same supply regulator trying to enable at approx. the same time they will both
enter the_regulator_enablewithout locks and we could get a race condition.
This would probably result in reference counting error and unbalanced regulator warnings.
Quoted 2 lines
In our system we make use the regulator hierarchy quite heavily.
Quoted 1 line
Applied.
Thanks
Liam
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Quoted 3 lines · Mattias Wallin
This patch add locks around regulator supply enable.
Signed-off-by Mattias Wallin <[email protected]>
Quoted 4 lines
The previous patch I sent solves a problem seen in our system. This patch does not solve a problem I have seen but I still think it should be there. Or at least some locking of the supply in regulator enable. What do you guys think?
If we're locking the regulator when it's directly enabled we need to do the same when enabling it via other ways.