public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Li Yu <raise.sail@gmail.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] fix potential 32bits truncation for result of timespec/timeval_compare()
Date: Thu, 21 Jun 2012 14:53:57 +0800	[thread overview]
Message-ID: <4FE2C505.4000905@gmail.com> (raw)


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@taobao.com>

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;

                 reply	other threads:[~2012-06-21  6:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FE2C505.4000905@gmail.com \
    --to=raise.sail@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox