If current time t is already past tend, the while loop in
get_backoff_delta_msec never ends.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/377
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
t = now_msec();
- if (!*delta)
- *delta = 1;
- else
- *delta <<= 1;
+ if (tend <= t) {
+ /* Timeout already reached */
+ *delta = 0;
+ } else {
+ const unsigned long long limit = tend - t;
+
+ if (!*delta)
+ *delta = 1;
+ else
+ *delta <<= 1;
- while (t + *delta > tend)
- *delta >>= 1;
+ while (*delta > limit)
+ *delta >>= 1;
- if (!*delta && tend > t)
- *delta = tend - t;
+ if (!*delta)
+ *delta = limit;
+ }
return t + *delta;
}