regulator: core: flush deferred disables before suspend
Subsystems (2)
PATCH v2 1/1 regulator: core: flush deferred disables before suspend
regulator_disable_deferred() can leave hardware access pending while the system enters suspend. Allowing that work to run during device suspend can access a regulator after its backing bus has been suspended.
Moving deferred disables to a freezable workqueue is not sufficient. DAPM uses deferred disables while suspending audio devices, and work queued after the workqueue is frozen would leave the supply enabled until resume.
Mark the regulator core as suspending in the PM prepare phase. Flush each regulator's pending disable work before device suspend starts. Process new deferred-disable requests synchronously until PM completes. Synchronize the transition with the regulator lock so a request racing with prepare is either flushed or handled synchronously.
---
Changes in v2:
- Flush pending disables during PM prepare instead of freezing the work.
- Process new deferred disables synchronously until PM completes.
- Synchronize requests racing with PM prepare using the regulator lock.
Link to v1: https://lore.kernel.org/all/[email protected]/
--- drivers/regulator/core.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/regulator/core.c +29 -1
@@ -44,6 +44,7 @@ static LIST_HEAD(regulator_ena_gpio_list);static LIST_HEAD (regulator_supply_alias_list);static LIST_HEAD (regulator_coupler_list);static bool has_full_constraints; +static bool regulator_suspending;static const struct bus_type regulator_bus;
@@ -3463,10 +3464,15 @@ int regulator_disable_deferred(struct regulator *regulator, int ms) {struct regulator_dev *rdev = regulator->rdev; -if (!ms) +if (!ms ||READ_ONCE (regulator_suspending))return regulator_disable (regulator);regulator_lock (rdev); +if (unlikely (READ_ONCE (regulator_suspending))) { +regulator_unlock (rdev); +return regulator_disable (regulator); + } + regulator->deferred_disables++;mod_delayed_work (system_power_efficient_wq, &rdev->disable_work,msecs_to_jiffies (ms));
@@ -6327,6 +6333,24 @@ void regulator_unregister(struct regulator_dev *rdev)EXPORT_SYMBOL_GPL (regulator_unregister);#ifdef CONFIG_SUSPEND +static int regulator_prepare (struct device *dev) +{ +struct regulator_dev *rdev =dev_to_rdev (dev); + +regulator_lock (rdev); +WRITE_ONCE (regulator_suspending, true); +regulator_unlock (rdev); + +flush_delayed_work (&rdev->disable_work); + +return 0 ; +} + +static void regulator_complete (struct device *dev) +{ +WRITE_ONCE (regulator_suspending, false); +} +/** * regulator_suspend - prepare regulators for system wide suspend * @dev: ``&struct device`` pointer that is passed to _regulator_suspend()
@@ -6380,6 +6404,8 @@ static int regulator_resume(struct device *dev) }#else /* !CONFIG_SUSPEND */ +#define regulator_prepare NULL +#define regulator_complete NULL#define regulator_suspend NULL#define regulator_resume NULL
@@ -6387,6 +6413,8 @@ static int regulator_resume(struct device *dev)#ifdef CONFIG_PM static const struct dev_pm_ops __maybe_unused regulator_pm_ops = { + .prepare = regulator_prepare, + .complete = regulator_complete, .suspend = regulator_suspend, .resume = regulator_resume, };
Signature · 1 line
2.34.1
Mark Brown
maintainerQuoted 1 line · Jiale Yao
regulator: core: flush deferred disables before suspend
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-7.5
Thanks!
[1/1] regulator: core: flush deferred disables before suspend
https://git.kernel.org/broonie/regulator/c/cf828ffc92a2
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark