]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
util: Use local variable in get_backoff_delta_msec
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 29 Jun 2025 11:40:46 +0000 (13:40 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Mon, 7 Jul 2025 15:20:33 +0000 (10:20 -0500)
This might make the code easier to read.

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>
shared/util.c

index 58672a9fc15898ac186cdfbac6d9b5a968d6ecfb..b4ce172a5c82b8e98ef02d054ca8f7eb502dbd8e 100644 (file)
@@ -536,32 +536,34 @@ int sleep_until_msec(unsigned long long msec)
 unsigned long long get_backoff_delta_msec(unsigned long long tend,
                                          unsigned long long *delta)
 {
-       unsigned long long t;
+       unsigned long long d, t;
 
+       d = *delta;
        t = now_msec();
 
        if (tend <= t) {
                /* Timeout already reached */
-               *delta = 0;
+               d = 0;
        } else {
                const unsigned long long limit = tend - t;
 
                /* Double the amount of requested delta, if possible */
-               if (!*delta)
-                       *delta = 1;
-               else if (umulll_overflow(*delta, 2, delta))
-                       *delta = ULLONG_MAX;
+               if (!d)
+                       d = 1;
+               else if (umulll_overflow(d, 2, &d))
+                       d = ULLONG_MAX;
 
                /* Search for a fitting backoff delta */
-               while (*delta > limit)
-                       *delta >>= 1;
+               while (d > limit)
+                       d >>= 1;
 
                /* If none found, use maximum wait time */
-               if (!*delta)
-                       *delta = limit;
+               if (!d)
+                       d = limit;
        }
 
-       return t + *delta;
+       *delta = d;
+       return t + d;
 }
 
 unsigned long long now_usec(void)