Skip to contentSkip to conversation

fix potential 32bits truncation for result of timespec/timeval_compare()

PATCH New Li Yu 1 participant 1 message Jun 21, 2012 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore

Li Yu

author
#0 lore raw

PATCH 1/1 fix potential 32bits truncation for result of timespec/timeval_compare()

The tv_nsec field of timespec struct and tv_usec field of timeval struct are defined as long type, but two comparison API return int type of result value, this may result in wrong result.

This simple patch fixed it, thanks

include/linux/time.h +0 -1
index 179f4d6..be381f6 100644
@@ -53,7 +53,7 @@ static inline int timespec_equal(const struct timespec *a,
  * lhs == rhs: return 0
  * lhs > rhs:  return >0
  */
-static inline int timespec_compare(const struct timespec *lhs, const

struct timespec *rhs)
+static inline long timespec_compare(const struct timespec *lhs, const struct timespec *rhs)
{
if (lhs->tv_sec < rhs->tv_sec)
return -1;
@@ -62,7 +62,7 @@ static inline int timespec_compare(const struct timespec *lhs, const struct time
return lhs->tv_nsec - rhs->tv_nsec;
}

-static inline int timeval_compare(const struct timeval *lhs, const struct timeval *rhs)
+static inline long timeval_compare(const struct timeval *lhs, const struct timeval *rhs)
{
if (lhs->tv_sec < rhs->tv_sec)
return -1;