drivers: regulator: fix reference count underflow
Fixes regulator reference count underflow and adds error code for attempting to disable an already disabled regulator Signed-off-by: Vladislav Litvinov <vladislav.litvinov@nordicsemi.no>
This commit is contained in:
parent
08cd4b6cce
commit
95622e49b2
1 changed files with 7 additions and 5 deletions
|
@ -183,12 +183,14 @@ int regulator_disable(const struct device *dev)
|
|||
(void)k_mutex_lock(&data->lock, K_FOREVER);
|
||||
#endif
|
||||
|
||||
data->refcnt--;
|
||||
if (data->refcnt > 0) {
|
||||
data->refcnt--;
|
||||
|
||||
if (data->refcnt == 0) {
|
||||
ret = api->disable(dev);
|
||||
if (ret < 0) {
|
||||
data->refcnt++;
|
||||
if (data->refcnt == 0) {
|
||||
ret = api->disable(dev);
|
||||
if (ret < 0) {
|
||||
data->refcnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue