From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751922AbdBOObp (ORCPT ); Wed, 15 Feb 2017 09:31:45 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:35856 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626AbdBOObj (ORCPT ); Wed, 15 Feb 2017 09:31:39 -0500 From: Andrey Drobyshev To: linux-kernel@vger.kernel.org Cc: gq@cs.msu.su, giometti@enneenne.com Subject: [PATCH 3/8] hardpps: fix some pps_jitter issues. Date: Wed, 15 Feb 2017 17:31:04 +0300 Message-Id: <1487169069-15721-4-git-send-email-immortalguardian1@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1487169069-15721-1-git-send-email-immortalguardian1@gmail.com> References: <1487169069-15721-1-git-send-email-immortalguardian1@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Handle possible overflow, implementation-defined result of signed right shift and replace unsuitable constant. Signed-off-by: Andrey Drobyshev Signed-off-by: Alexander GQ Gerasiov --- kernel/time/ntp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 22f2235..9cef1b9 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -91,6 +91,7 @@ static time64_t ntp_next_leap_sec = TIME64_MAX; */ #define PPS_VALID 10 /* PPS signal watchdog max (s) */ #define PPS_POPCORN 4 /* popcorn spike threshold (shift) */ +#define PPS_JITUPD 2 /* pps_jitter update factor (shift) */ #define PPS_INTMIN 2 /* min freq interval (s) (shift) */ #define PPS_INTMAX 8 /* max freq interval (s) (shift) */ #define PPS_INTCOUNT 4 /* number of consecutive good intervals to @@ -941,7 +942,7 @@ static void hardpps_update_phase(long error) * threshold, the sample is discarded; otherwise, if so enabled, * the time offset is updated. */ - if (jitter > (pps_jitter << PPS_POPCORN)) { + if (pps_jitter && (jitter > ((long long)pps_jitter << PPS_POPCORN))) { printk_deferred(KERN_WARNING "hardpps: PPSJITTER: jitter=%ld, limit=%ld\n", jitter, (pps_jitter << PPS_POPCORN)); @@ -955,7 +956,7 @@ static void hardpps_update_phase(long error) time_adjust = 0; } /* update jitter */ - pps_jitter += (jitter - pps_jitter) >> PPS_INTMIN; + pps_jitter += shift_right(jitter - pps_jitter, PPS_JITUPD); } /* -- 2.1.4