public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: john.stultz@linaro.org, tglx@linutronix.de,
	a.p.zijlstra@chello.nl, richardcochran@gmail.com,
	prarit@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH] time: Fix adjustment cleanup bug in timekeeping_adjust()
Date: Sat, 4 Aug 2012 21:21:14 +0200	[thread overview]
Message-ID: <20120804192114.GA28347@gmail.com> (raw)
In-Reply-To: <201208042246.HBH81275.FVOOSLtJFMQOFH@I-love.SAKURA.ne.jp>


* Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:

> Hello.
> 
> Bisected to 2a8c0883 "time: Move xtime_nsec adjustment 
> underflow handling timekeeping_adjust".
> 
> Would you check?

probably caused by this stray return in timekeeping_adjust():

        } else
                return;

which should really be a proper goto - like the (totally 
untested!) patch below.

Does this fix the bug for you?

Thanks,

	Ingo

-------------

Subject: time: Fix adjustment cleanup bug in timekeeping_adjust()

Also make the flow more readable by properly balancing curly 
braces.

Signed-off-by: Ingo Molnar <mingo@kernel.org>


diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 2988bc8..e16af19 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -923,20 +923,22 @@ static void timekeeping_adjust(struct timekeeper *tk, s64 offset)
 		if (likely(error <= interval))
 			adj = 1;
 		else
-			adj = timekeeping_bigadjust(tk, error, &interval,
-							&offset);
-	} else if (error < -interval) {
-		/* See comment above, this is just switched for the negative */
-		error >>= 2;
-		if (likely(error >= -interval)) {
-			adj = -1;
-			interval = -interval;
-			offset = -offset;
-		} else
-			adj = timekeeping_bigadjust(tk, error, &interval,
-							&offset);
-	} else
-		return;
+			adj = timekeeping_bigadjust(tk, error, &interval, &offset);
+	} else {
+		if (error < -interval) {
+			/* See comment above, this is just switched for the negative */
+			error >>= 2;
+			if (likely(error >= -interval)) {
+				adj = -1;
+				interval = -interval;
+				offset = -offset;
+			} else {
+				adj = timekeeping_bigadjust(tk, error, &interval, &offset);
+			}
+		} else {
+			goto out_adjust;
+		}
+	}
 
 	if (unlikely(tk->clock->maxadj &&
 		(tk->mult + adj > tk->clock->mult + tk->clock->maxadj))) {
@@ -999,6 +1001,7 @@ static void timekeeping_adjust(struct timekeeper *tk, s64 offset)
 	tk->xtime_nsec -= offset;
 	tk->ntp_error -= (interval - offset) << tk->ntp_error_shift;
 
+out_adjust:
 	/*
 	 * It may be possible that when we entered this function, xtime_nsec
 	 * was very small.  Further, if we're slightly speeding the clocksource

  reply	other threads:[~2012-08-04 19:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03 14:18 [3.6-rc1] sched: clock counts too quickly Tetsuo Handa
2012-08-04 11:24 ` Tetsuo Handa
2012-08-04 12:10   ` Tetsuo Handa
2012-08-04 13:46     ` Tetsuo Handa
2012-08-04 19:21       ` Ingo Molnar [this message]
2012-08-05  0:50         ` [PATCH] time: Fix adjustment cleanup bug in timekeeping_adjust() Tetsuo Handa
2012-08-05 17:00         ` [tip:timers/urgent] " tip-bot for Ingo Molnar
2012-08-06 17:21         ` [PATCH] " John Stultz

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=20120804192114.GA28347@gmail.com \
    --to=mingo@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=prarit@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=tglx@linutronix.de \
    /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