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

From: Li Yu
Date: Thu Jun 21 2012 - 02:54:04 EST



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

Signed-off-by: Li Yu <bingtian.ly@xxxxxxxxxx>

diff --git a/include/linux/time.h b/include/linux/time.h
index 179f4d6..be381f6 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -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;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/