From patchwork Wed Oct 28 12:37:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deng Chao X-Patchwork-Id: 55668 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp93709lbr; Wed, 28 Oct 2015 05:37:55 -0700 (PDT) X-Received: by 10.202.186.7 with SMTP id k7mr28413077oif.82.1446035875260; Wed, 28 Oct 2015 05:37:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xy5si27290570oeb.105.2015.10.28.05.37.54; Wed, 28 Oct 2015 05:37:55 -0700 (PDT) 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 S965523AbbJ1Mhx (ORCPT + 28 others); Wed, 28 Oct 2015 08:37:53 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:33684 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751004AbbJ1Mhv (ORCPT ); Wed, 28 Oct 2015 08:37:51 -0400 Received: by padhy1 with SMTP id hy1so451262pad.0 for ; Wed, 28 Oct 2015 05:37:51 -0700 (PDT) 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=j9Ij2gn+1MBRjdry5hrGXQ5DNAxW/7we4mBXo7Xe8zY=; b=DPPCrHi55DqtdzGbE4AfarwzguypLzFFHYFMCzOkHhAXSOMCOczBDEX2OM2jB/zoYV dHxGDOo4xacHboAJlXRedXLIQ3+qxxs45HtYbXSAheC3hQ7An2AxSL5Uo7GjMYsHcQ9a +mPi44515XaVkNjSehPCqb/5w4fM6OsIPdWDD/WHZWP/CL6jNjokOzziqAJLFe3K8/xB jysHNOVOcLqSXyBOW0nD7FwEtCb87TliPwLppYDKrA+DiPHIdJkkTFgFxZYBAQ+rfkx0 SGbArnYslmtWD53VsYhDgwpnQXfmQsZs4p3zBQSlQ77viA7UZvtd4zh72MX5PxGV+ljZ 6JSw== 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=j9Ij2gn+1MBRjdry5hrGXQ5DNAxW/7we4mBXo7Xe8zY=; b=dwarANwhA8mFTNca/gYpw6gJB2FOgwbOpSgp/skpLZMyoR9rlOHmEXVqEQD3L5qdN1 3hX1PXWmK2SCkwI0HkbMpqlXRoKw0lPKzlDDbdDR/Qz6gdt8ALVYOnh0FgPcD0m/avTL dtVU/Mw2ek5r1K+WqyruWA8AToTnqpOjpVRQ2l0gWxRic7qQn0zOvjPFmAwzVR5x6jrn tCE953mI/lAT38XoHxqIffa6H9yy5k6TMrLRa2CfDXcJfxJK0VbBgFSHieuafuljlg0K ppCtmXfVwz/GrAZflMHX0R27Vpmxs+d3AP7SnxW6Bpjor2Mbtr3ScktqYHhWgGp/y1Pe PmxQ== X-Gm-Message-State: ALoCoQkoOAgTW9uuTvixdI9ZX7dXlnoabDQOUnAjZW1izkkE1plPYVETR/IkiTRkbCPPzLzBapLK X-Received: by 10.66.150.3 with SMTP id ue3mr33463722pab.57.1446035871289; Wed, 28 Oct 2015 05:37:51 -0700 (PDT) Received: from localhost.localdomain ([167.160.116.42]) by smtp.gmail.com with ESMTPSA id w8sm45299296pbs.87.2015.10.28.05.37.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Oct 2015 05:37:50 -0700 (PDT) From: DengChao To: linux-kernel@vger.kernel.org Cc: chao.deng@linaro.org Subject: [PATCH] ntp:Fix second_overflow's input parameter type Date: Wed, 28 Oct 2015 20:37:27 +0800 Message-Id: <1446035847-3699-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 "unsigned long" as its input parameter type which will overflow after year 2106 on 32bit systems. This patch replaces it with a time64_t type. Since "next_ntp_leap_sec" is already calculated, we can reuse it and avoid re-doing the division (which is now moreexpensive with 64bit types) in the one-per-second TIME_INS/DEL checks. 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 df68cb8..f4a9e18 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 6543050..446846b 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 timespec *, const struct timespec *);