Re: [PATCH] ktime: Simplify ktime_* comparison functions

From: Thomas Gleixner
Date: Fri May 26 2017 - 06:31:35 EST


On Fri, 26 May 2017, Mariusz Skamra wrote:
> -static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2)
> -{
> - if (cmp1 < cmp2)
> - return -1;
> - if (cmp1 > cmp2)
> - return 1;
> - return 0;
> -}
> +#define ktime_compare(cmp1, cmp2) ktime_sub(cmp1, cmp2)

What's wrong with modifying the inline itself?

> -static inline bool ktime_after(const ktime_t cmp1, const ktime_t cmp2)
> -{
> - return ktime_compare(cmp1, cmp2) > 0;
> -}
> +#define ktime_after(cmp1, cmp2) (ktime_compare(cmp1, cmp2) > 0)

> -static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2)
> -{
> - return ktime_compare(cmp1, cmp2) < 0;
> -}
> +#define ktime_before(cmp1, cmp2) (ktime_compare(cmp1, cmp2) < 0)

Sorry, but those two are just crap. That inline compiles to exactly the
same code as the macro. If not, yell at your compiler people.

Thanks,

tglx