Skip to content

Commit

Permalink
timers: Add a warning to usleep_range_state() for wrong order of argu…
Browse files Browse the repository at this point in the history
…ments

There is a warning in checkpatch script that triggers, when min and max
arguments of usleep_range_state() are in reverse order. This check does
only cover callsites which uses constants. Add this check into the code as
a WARN_ON_ONCE() to also cover callsites not using constants and fix the
mis-usage by resetting the delta to 0.

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://lore.kernel.org/all/20241014-devel-anna-maria-b4-timers-flseep-v3-9-dc8b907cb62f@linutronix.de
  • Loading branch information
anna-marialx authored and KAGA-KOKO committed Oct 15, 2024
1 parent ef02455 commit 6279abf
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kernel/time/sleep_timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ void __sched usleep_range_state(unsigned long min, unsigned long max, unsigned i
ktime_t exp = ktime_add_us(ktime_get(), min);
u64 delta = (u64)(max - min) * NSEC_PER_USEC;

if (WARN_ON_ONCE(max < min))
delta = 0;

for (;;) {
__set_current_state(state);
/* Do not return before the requested sleep time has elapsed */
Expand Down

0 comments on commit 6279abf

Please sign in to comment.