diff mbox series

[v2] PM/runtime: Fix autosuspend_delay on 32bits arch

Message ID 1547110840-15396-1-git-send-email-vincent.guittot@linaro.org
State Accepted
Commit ca27e4cd0bdd87e33fda38e6e3d18d36d54356d4
Headers show
Series [v2] PM/runtime: Fix autosuspend_delay on 32bits arch | expand

Commit Message

Vincent Guittot Jan. 10, 2019, 9 a.m. UTC
Cast autosuspend_delay in u64 to make sure that the full computation of
expires or slack will be done in u64, even on 32bits arch.
Otherwise, any delay greater than 2^31 nsec can overflow if signed 32bits
is used when moving delay from msec to nsec

Fixes: 8234f6734c5d ("PM-runtime: Switch autosuspend over to using hrtimers")
Reported-by: Tony Lindgren <tony@atomide.com>
Tested-by: Tony Lindgren <tony@atomide.com>

Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>

---

Change since v1:
- add u64 cast for slack computation

 drivers/base/power/runtime.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.7.4

Comments

Tony Lindgren Jan. 10, 2019, 4:44 p.m. UTC | #1
* Vincent Guittot <vincent.guittot@linaro.org> [190110 09:00]:
> Cast autosuspend_delay in u64 to make sure that the full computation of

> expires or slack will be done in u64, even on 32bits arch.

> Otherwise, any delay greater than 2^31 nsec can overflow if signed 32bits

> is used when moving delay from msec to nsec

> 

> Fixes: 8234f6734c5d ("PM-runtime: Switch autosuspend over to using hrtimers")

> Reported-by: Tony Lindgren <tony@atomide.com>

> Tested-by: Tony Lindgren <tony@atomide.com>

> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---

> 

> Change since v1:

> - add u64 cast for slack computation


Still works for me.

Thanks,

Tony
Rafael J. Wysocki Jan. 11, 2019, 10:39 a.m. UTC | #2
On Thursday, January 10, 2019 5:44:31 PM CET Tony Lindgren wrote:
> * Vincent Guittot <vincent.guittot@linaro.org> [190110 09:00]:

> > Cast autosuspend_delay in u64 to make sure that the full computation of

> > expires or slack will be done in u64, even on 32bits arch.

> > Otherwise, any delay greater than 2^31 nsec can overflow if signed 32bits

> > is used when moving delay from msec to nsec

> > 

> > Fixes: 8234f6734c5d ("PM-runtime: Switch autosuspend over to using hrtimers")

> > Reported-by: Tony Lindgren <tony@atomide.com>

> > Tested-by: Tony Lindgren <tony@atomide.com>

> > Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>

> > ---

> > 

> > Change since v1:

> > - add u64 cast for slack computation

> 

> Still works for me.


Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 7062469..76d0676 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -141,7 +141,7 @@  u64 pm_runtime_autosuspend_expiration(struct device *dev)
 
 	last_busy = READ_ONCE(dev->power.last_busy);
 
-	expires = last_busy + autosuspend_delay * NSEC_PER_MSEC;
+	expires = last_busy + (u64)autosuspend_delay * NSEC_PER_MSEC;
 	if (expires <= now)
 		expires = 0;	/* Already expired. */
 
@@ -525,7 +525,7 @@  static int rpm_suspend(struct device *dev, int rpmflags)
 				 * We add a slack of 25% to gather wakeups
 				 * without sacrificing the granularity.
 				 */
-				u64 slack = READ_ONCE(dev->power.autosuspend_delay) *
+				u64 slack = (u64)READ_ONCE(dev->power.autosuspend_delay) *
 						    (NSEC_PER_MSEC >> 2);
 
 				dev->power.timer_expires = expires;