[PATCH 2/2] regulator: core: Fix race on multiple calls to regulator_disable_deferred()

From: Harald Geyer
Date: Wed Feb 22 2017 - 13:20:53 EST


The old code has two issues:
1) When multiple consumers call regulator_disable_deferred() close in time,
always the delay requested in the first call is used.
2) When a consumer calls regulator_disable_deferred(), but enables and
calls regulator_disable_deferred() again before the timer fires, the timer
isn't reset.

Both issues can cause the regulator to get disabled early.

Signed-off-by: Harald Geyer <harald@xxxxxxxxx>
---
drivers/regulator/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index cc68604..ce4923b 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2449,8 +2449,8 @@ int regulator_disable_deferred(struct regulator *regulator, int ms)
rdev->deferred_disables++;
mutex_unlock(&rdev->mutex);

- queue_delayed_work(system_power_efficient_wq, &rdev->disable_work,
- msecs_to_jiffies(ms));
+ mod_fwd_delayed_work(system_power_efficient_wq, &rdev->disable_work,
+ msecs_to_jiffies(ms));
return 0;
}
EXPORT_SYMBOL_GPL(regulator_disable_deferred);
--
2.1.4