From: claudio Date: Tue, 1 Aug 2023 06:40:18 +0000 (+0000) Subject: Implement time_after() and firends as static inline functions. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=746f1522d75c5289ed72f4ac7161fce0f0c5ed3d;p=openbsd Implement time_after() and firends as static inline functions. The previous macros were too optimistic about types and also did a signed subtraction that could overflow. OK miod@ kettenis@ deraadt@ jsg@ --- diff --git a/sys/dev/pci/drm/include/linux/jiffies.h b/sys/dev/pci/drm/include/linux/jiffies.h index 24e15fecfc1..8278b761a7e 100644 --- a/sys/dev/pci/drm/include/linux/jiffies.h +++ b/sys/dev/pci/drm/include/linux/jiffies.h @@ -41,9 +41,20 @@ jiffies_to_nsecs(const unsigned long x) #define nsecs_to_jiffies(x) (((uint64_t)(x)) * hz / 1000000000) #define nsecs_to_jiffies64(x) (((uint64_t)(x)) * hz / 1000000000) #define get_jiffies_64() jiffies -#define time_after(a,b) ((long)(b) - (long)(a) < 0) + +static inline int +time_after(const unsigned long a, const unsigned long b) +{ + return((long)(b - a) < 0); +} +#define time_before(a,b) time_after(b,a) + +static inline int +time_after_eq(const unsigned long a, const unsigned long b) +{ + return((long)(b - a) <= 0); +} + #define time_after32(a,b) ((int32_t)((uint32_t)(b) - (uint32_t)(a)) < 0) -#define time_after_eq(a,b) ((long)(b) - (long)(a) <= 0) -#define time_before(a,b) ((long)(a) - (long)(b) < 0) #endif