From patchwork Sun Dec 13 04:26:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deng Chao X-Patchwork-Id: 58318 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp769002lbv; Sat, 12 Dec 2015 20:27:59 -0800 (PST) X-Received: by 10.98.74.129 with SMTP id c1mr26496139pfj.124.1449980879290; Sat, 12 Dec 2015 20:27:59 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qz6si8846213pab.168.2015.12.12.20.27.58; Sat, 12 Dec 2015 20:27:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751640AbbLME15 (ORCPT + 28 others); Sat, 12 Dec 2015 23:27:57 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:33209 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751369AbbLME1z (ORCPT ); Sat, 12 Dec 2015 23:27:55 -0500 Received: by pabur14 with SMTP id ur14so86316636pab.0 for ; Sat, 12 Dec 2015 20:27:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=HCk4hphPulYW5KrL1R+BCkojm05uNfbEn73Ebinuqcc=; b=p126hZrrM/GbP71lXH+jYGjDJ/uANQY0Uny37UL4tfZux6t7LJQryqB3z9D8k1Y9CV st2JwInlb0Zu9cMRT7/yUl6MgGAqUDSWRr0R9lQ2X3xT7hNOFMlxISy7yegLg9lhmzJ4 mc9FMd/Tbre6eTegZ7ZAU84wPGodO3x095maq0Pxb/shLKcn1wh5LMsYfUby5OtkGqqY YXR0ts4f9XBLjUn39+f2W83vqcvxqOSCoNMJCMqCpDm7h6WJX2IC1dwTaEZJHl44UTtc lNhT+eZ0ov1qAFgW+JLPFTegznBuyY7F2KClAhSZQ1RvCGU7FLC6OZ4/So9YIgguLTF4 hTyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HCk4hphPulYW5KrL1R+BCkojm05uNfbEn73Ebinuqcc=; b=KJU/AQ6YVts4HbH8hwpHNt4XloXqo65z1E6556WXm9dLGxpXYR2jhbO3OrTp9nAGB4 HNXg55Qc05Pn9ve3DvXWcJlwjy1R1+jtoKL7Kct/j7uIAGSF8RG6mdWiKjwnq5Ak75g9 Y48V1F3hjfW57JDwkekLk6x3TyC0kUJ868wSxppSjsxqiPpGTJFewkHXzQtj3CzvH2xa LVKgnWsq3Rrn/vTpNojdNSlf6B+c8UnCmFspebzlBOhr5gu/1Y9G8VZtHqZXrG5AkBVY mb5BdF0tm26kTldN8C+1F3ohUt2lQKYgfA4E5NMTu/OtoF36Q0n1kY4edYyPdeqs8Gb9 GnaA== X-Gm-Message-State: ALoCoQmUqQSJyRxLO1XFMj37IT/yrC3Qz9xs924vPgxsIH0UXm7tKbvhIL9x9zze7ULLeGxl1bLo7fbnpXr2sfGkyAipCjoylg== X-Received: by 10.67.5.164 with SMTP id cn4mr35453506pad.141.1449980875473; Sat, 12 Dec 2015 20:27:55 -0800 (PST) Received: from localhost.localdomain ([167.160.116.42]) by smtp.gmail.com with ESMTPSA id b17sm33994943pfj.43.2015.12.12.20.27.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 12 Dec 2015 20:27:54 -0800 (PST) From: DengChao To: linux-kernel@vger.kernel.org, tglx@linutronix.de, john.stultz@linaro.org Cc: chao.deng@linaro.org Subject: [PATCH] ntp:Fix second_overflow's input parameter type Date: Sun, 13 Dec 2015 12:26:42 +0800 Message-Id: <1449980802-3026-1-git-send-email-chao.deng@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function "second_overflow" uses "unsign long" as its input parameter type which will overflow after year 2106 on 32bit systems. Replace it with time64_t type. Because 64-bit division is expensive, since "next_ntp_leap_sec" has been calculated already, we can just re-use it in the TIME_INS/DEL cases instead of re-doing divsion which may occur once a second. Signed-off-by: DengChao --- kernel/time/ntp.c | 16 +++++++++------- kernel/time/ntp_internal.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 149cc80..37479305 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "ntp_internal.h" @@ -390,10 +391,11 @@ ktime_t ntp_get_next_leap(void) * * Also handles leap second processing, and returns leap offset */ -int second_overflow(unsigned long secs) +int second_overflow(time64_t secs) { s64 delta; int leap = 0; + s32 rem; /* * Leap second processing. If in leap-insert state at the end of the @@ -404,19 +406,19 @@ int second_overflow(unsigned long secs) case TIME_OK: if (time_status & STA_INS) { time_state = TIME_INS; - ntp_next_leap_sec = secs + SECS_PER_DAY - - (secs % SECS_PER_DAY); + div_s64_rem(secs, SECS_PER_DAY, &rem); + ntp_next_leap_sec = secs + SECS_PER_DAY - rem; } else if (time_status & STA_DEL) { time_state = TIME_DEL; - ntp_next_leap_sec = secs + SECS_PER_DAY - - ((secs+1) % SECS_PER_DAY); + div_s64_rem(secs + 1, SECS_PER_DAY, &rem); + ntp_next_leap_sec = secs + SECS_PER_DAY - rem; } break; case TIME_INS: if (!(time_status & STA_INS)) { ntp_next_leap_sec = TIME64_MAX; time_state = TIME_OK; - } else if (secs % SECS_PER_DAY == 0) { + } else if (secs == ntp_next_leap_sec) { leap = -1; time_state = TIME_OOP; printk(KERN_NOTICE @@ -427,7 +429,7 @@ int second_overflow(unsigned long secs) if (!(time_status & STA_DEL)) { ntp_next_leap_sec = TIME64_MAX; time_state = TIME_OK; - } else if ((secs + 1) % SECS_PER_DAY == 0) { + } else if (secs == ntp_next_leap_sec) { leap = 1; ntp_next_leap_sec = TIME64_MAX; time_state = TIME_WAIT; diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h index af92447..d8a7c11 100644 --- a/kernel/time/ntp_internal.h +++ b/kernel/time/ntp_internal.h @@ -6,7 +6,7 @@ extern void ntp_clear(void); /* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */ extern u64 ntp_tick_length(void); extern ktime_t ntp_get_next_leap(void); -extern int second_overflow(unsigned long secs); +extern int second_overflow(time64_t secs); extern int ntp_validate_timex(struct timex *); extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *); extern void __hardpps(const struct timespec64 *, const struct timespec64 *);