diff options
| author | GuEe-GUI <[email protected]> | 2026-04-07 20:07:01 +0800 |
|---|---|---|
| committer | Rbb666 <[email protected]> | 2026-04-07 22:31:44 +0800 |
| commit | c6cfed353f16f7c47ad62a237c27a478e0e7e8cc (patch) | |
| tree | 5d63bf1210b36b78314c90d20f233e24190331bc /components | |
| parent | 256da7ef5f72e0fbec4595bb042a97af9f1ec835 (diff) | |
[dm][regulator] fixup the ref of enabled status
Signed-off-by: GuEe-GUI <[email protected]>
Diffstat (limited to 'components')
| -rw-r--r-- | components/drivers/regulator/regulator.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/components/drivers/regulator/regulator.c b/components/drivers/regulator/regulator.c index 3a852a0590..61c429f1df 100644 --- a/components/drivers/regulator/regulator.c +++ b/components/drivers/regulator/regulator.c @@ -18,7 +18,6 @@ #define DBG_LVL DBG_INFO #include <rtdbg.h> - struct rt_regulator { struct rt_regulator_node *reg_np; @@ -359,7 +358,6 @@ static rt_err_t regulator_enable(struct rt_regulator_node *reg_np) regulator_delay(enable_delay); } - rt_atomic_add(®_np->enabled_count, 1); err = regulator_notifier_call_chain(reg_np, RT_REGULATOR_MSG_ENABLE, RT_NULL); } } @@ -434,7 +432,7 @@ static rt_err_t regulator_disable(struct rt_regulator_node *reg_np) rt_err_t rt_regulator_disable(struct rt_regulator *reg) { - rt_err_t err; + rt_err_t err = RT_EOK; int enabled_cnt; if (!reg) @@ -450,20 +448,13 @@ rt_err_t rt_regulator_disable(struct rt_regulator *reg) rt_hw_spin_lock(&_regulator_lock.lock); enabled_cnt = rt_atomic_load(®->reg_np->enabled_count); - if (enabled_cnt > 0) - { - rt_atomic_sub(®->reg_np->enabled_count, 1); - enabled_cnt--; + rt_atomic_sub(®->reg_np->enabled_count, 1); - if (enabled_cnt > 0) - { - rt_hw_spin_unlock(&_regulator_lock.lock); - return RT_EOK; - } + if (enabled_cnt == 1) + { + err = regulator_disable(reg->reg_np); } - err = regulator_disable(reg->reg_np); - rt_hw_spin_unlock(&_regulator_lock.lock); return err; @@ -473,7 +464,7 @@ rt_bool_t rt_regulator_is_enabled(struct rt_regulator *reg) { if (!reg) { - return -RT_EINVAL; + return RT_FALSE; } if (reg->reg_np->ops->is_enabled) |
