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:
Vladislav Litvinov 2024-04-15 15:16:33 +02:00 committed by Carles Cufí
commit 95622e49b2

View file

@ -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++;
}
}
}