Skip to content

Commit

Permalink
PM-runtime: Fix autosuspend_delay on 32bits arch
Browse files Browse the repository at this point in the history
Cast autosuspend_delay to 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 converting delay from msec to nsec.

Fixes: 8234f67 (PM-runtime: Switch autosuspend over to using hrtimers)
Reported-by: Tony Lindgren <[email protected]>
Tested-by: Tony Lindgren <[email protected]>
Signed-off-by: Vincent Guittot <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
vingu-linaro authored and rafaeljw committed Jan 10, 2019
1 parent 1f7b708 commit ca27e4c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/base/power/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ca27e4c

Please sign in to comment.