i2c: designware: Fix unbalanced suspended flag
Subsystems (3)
PATCH v3 1/1 i2c: designware: Fix unbalanced suspended flag
Ensure that i2c_mark_adapter_suspended() is always balanced by a call to i2c_mark_adapter_resumed().
dw_i2c_plat_resume() must always be called, so that i2c_mark_adapter_resumed() is called. This is not compatible with DPM_FLAG_MAY_SKIP_RESUME, so remove the flag.
Since the controller is always resumed on system resume the dw_i2c_plat_complete() callback is redundant and has been removed.
The unbalanced suspended flag was introduced by
commit c57813b8b288 ("i2c: designware: Lock the adapter while setting the suspended flag")
Before that commit, the system and runtime PM used the same functions. The DPM_FLAG_MAY_SKIP_RESUME was used to skip the system resume if the driver had been in runtime-suspend. If system resume was skipped, the suspended flag would be cleared by the next runtime resume. The check of the suspended flag was _after_ the call to pm_runtime_get_sync() in i2c_dw_xfer(). So either a system resume or a runtime resume would clear the flag before it was checked.
Having introduced the unbalanced suspended flag with that commit, a further commit 80704a84a9f8 ("i2c: designware: Use the i2c_mark_adapter_suspended/resumed() helpers")
changed from using a local suspended flag to using the i2c_mark_adapter_suspended/resumed() functions. These use a flag that is checked by I2C core code before issuing the transfer to the bus driver, so there was no opportunity for the bus driver to runtime resume itself before the flag check.
--- drivers/i2c/busses/i2c-designware-platdrv.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +2 -18
@@ -351,13 +351,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)if (dev->flags &ACCESS_NO_IRQ_SUSPEND ) {dev_pm_set_driver_flags (&pdev->dev, -DPM_FLAG_SMART_PREPARE | -DPM_FLAG_MAY_SKIP_RESUME ); +DPM_FLAG_SMART_PREPARE ); }else {dev_pm_set_driver_flags (&pdev->dev,DPM_FLAG_SMART_PREPARE | -DPM_FLAG_SMART_SUSPEND | -DPM_FLAG_MAY_SKIP_RESUME ); +DPM_FLAG_SMART_SUSPEND ); }device_enable_async_suspend (&pdev->dev);
@@ -419,21 +417,8 @@ static int dw_i2c_plat_prepare(struct device *dev)*/ return !has_acpi_companion(dev); } - -static void dw_i2c_plat_complete (struct device *dev) -{ -/* -* The device can only be in runtime suspend at this point if it has not -* been resumed throughout the ending system suspend/resume cycle, so if -* the platform firmware might mess up with it, request the runtime PM -* framework to resume it. -*/ -if (pm_runtime_suspended (dev) &&pm_resume_via_firmware ()) -pm_request_resume (dev); -}#else #define dw_i2c_plat_prepare NULL -#define dw_i2c_plat_complete NULL#endif #ifdef CONFIG_PM
@@ -483,7 +468,6 @@ static int __maybe_unused dw_i2c_plat_resume(struct device *dev)static const struct dev_pm_ops dw_i2c_dev_pm_ops = { .prepare = dw_i2c_plat_prepare, - .complete = dw_i2c_plat_complete, SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume)SET_RUNTIME_PM_OPS (dw_i2c_plat_runtime_suspend, dw_i2c_plat_runtime_resume,NULL ) };
Signature · 1 line
2.30.2
Hi,
Quoted 26 lines · Richard Fitzgerald
Ensure that
i2c_mark_adapter_suspended()is always balanced by a call toi2c_mark_adapter_resumed().
dw_i2c_plat_resume()must always be called, so thati2c_mark_adapter_resumed()is called. This is not compatible withDPM_FLAG_MAY_SKIP_RESUME, so remove the flag.Since the controller is always resumed on system resume the
dw_i2c_plat_complete()callback is redundant and has been removed.The unbalanced suspended flag was introduced by
commitc57813b8b288("i2c: designware: Lock the adapter while setting the suspended flag")Before that commit, the system and runtime PM used the same functions. The
DPM_FLAG_MAY_SKIP_RESUMEwas used to skip the system resume if the driver had been in runtime-suspend. If system resume was skipped, the suspended flag would be cleared by the next runtime resume. The check of the suspended flag was _after_ the call topm_runtime_get_sync()ini2c_dw_xfer(). So either a system resume or a runtime resume would clear the flag before it was checked.Having introduced the unbalanced suspended flag with that commit, a further commit
80704a84a9f8("i2c: designware: Use the i2c_mark_adapter_suspended/resumed() helpers")
Quoted 8 lines
changed from using a local suspended flag to using the i2c_mark_adapter_suspended/resumed() functions. These use a flag that is checked by I2C core code before issuing the transfer to the bus driver, so there was no opportunity for the bus driver to runtime resume itself before the flag check.
Signed-off-by Richard Fitzgerald <[email protected]>Fixes c57813b8b288 ("i2c: designware: Lock the adapter while setting the suspended flag")
Thanks, patch looks good to me:
Regards,
Hans
Quoted 54 lines
--- drivers/i2c/busses/i2c-designware-platdrv.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)drivers/i2c/busses/i2c-designware-platdrv.c +2
-18@@ -351,13 +351,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)if (dev->flags &ACCESS_NO_IRQ_SUSPEND ) {dev_pm_set_driver_flags (&pdev->dev, -DPM_FLAG_SMART_PREPARE | -DPM_FLAG_MAY_SKIP_RESUME ); +DPM_FLAG_SMART_PREPARE ); }else {dev_pm_set_driver_flags (&pdev->dev,DPM_FLAG_SMART_PREPARE | -DPM_FLAG_SMART_SUSPEND | -DPM_FLAG_MAY_SKIP_RESUME ); +DPM_FLAG_SMART_SUSPEND ); }device_enable_async_suspend (&pdev->dev);@@ -419,21 +417,8 @@ static int dw_i2c_plat_prepare(struct device *dev)*/ return !has_acpi_companion(dev); } - -static void dw_i2c_plat_complete (struct device *dev) -{ -/* -* The device can only be in runtime suspend at this point if it has not -* been resumed throughout the ending system suspend/resume cycle, so if -* the platform firmware might mess up with it, request the runtime PM -* framework to resume it. -*/ -if (pm_runtime_suspended (dev) &&pm_resume_via_firmware ()) -pm_request_resume (dev); -}#else #define dw_i2c_plat_prepare NULL -#define dw_i2c_plat_complete NULL#endif #ifdef CONFIG_PM @@ -483,7 +468,6 @@ static int __maybe_unused dw_i2c_plat_resume(struct device *dev)static const struct dev_pm_ops dw_i2c_dev_pm_ops = { .prepare = dw_i2c_plat_prepare, - .complete = dw_i2c_plat_complete, SET_LATE_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume)SET_RUNTIME_PM_OPS (dw_i2c_plat_runtime_suspend, dw_i2c_plat_runtime_resume,NULL ) };
Andy Shevchenko
reviewerQuoted 7 lines · Richard Fitzgerald
Ensure that
i2c_mark_adapter_suspended()is always balanced by a call toi2c_mark_adapter_resumed().
dw_i2c_plat_resume()must always be called, so thati2c_mark_adapter_resumed()is called. This is not compatible withDPM_FLAG_MAY_SKIP_RESUME, so remove the flag.
Quoted 6 lines
Since the controller is always resumed on system resume the
dw_i2c_plat_complete()callback is redundant and has been removed.The unbalanced suspended flag was introduced by
commitc57813b8b288("i2c: designware: Lock the adapter while setting the suspended flag")
Seems like indentation got broken - the commit and hash can be on previous line, but it's minor thingy here.
Quoted 12 lines
Before that commit, the system and runtime PM used the same functions. The
DPM_FLAG_MAY_SKIP_RESUMEwas used to skip the system resume if the driver had been in runtime-suspend. If system resume was skipped, the suspended flag would be cleared by the next runtime resume. The check of the suspended flag was _after_ the call topm_runtime_get_sync()ini2c_dw_xfer(). So either a system resume or a runtime resume would clear the flag before it was checked.Having introduced the unbalanced suspended flag with that commit, a further commit
80704a84a9f8("i2c: designware: Use the i2c_mark_adapter_suspended/resumed() helpers")
Quoted 8 lines
changed from using a local suspended flag to using the i2c_mark_adapter_suspended/resumed() functions. These use a flag that is checked by I2C core code before issuing the transfer to the bus driver, so there was no opportunity for the bus driver to runtime resume itself before the flag check.
Signed-off-by Richard Fitzgerald <[email protected]>Fixes c57813b8b288 ("i2c: designware: Lock the adapter while setting the suspended flag")
Usually we put other tags, that submitter brought themselves, before SoB. But again, it's minor thingy.
Signature · 2 lines
With Best Regards, Andy Shevchenko