From patchwork Fri Apr 29 16:39:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 8984011 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 585529F1D3 for ; Fri, 29 Apr 2016 16:40:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B6BD201DD for ; Fri, 29 Apr 2016 16:40:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87895201FA for ; Fri, 29 Apr 2016 16:40:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752622AbcD2Qkv (ORCPT ); Fri, 29 Apr 2016 12:40:51 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35807 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752613AbcD2Qku (ORCPT ); Fri, 29 Apr 2016 12:40:50 -0400 Received: by mail-pf0-f196.google.com with SMTP id r187so15318121pfr.2; Fri, 29 Apr 2016 09:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MOPftaORDB2h/uSmhamfsr8EUYcrBZ9dAlTNoCP8QMQ=; b=R5jonF9OKQ2xYcjON8NNXBHVMvxjjSIdsr9j5/dfdCgxmiEzQkbHcwVOPxNlh39AHg E9Qci+mD4s+lFI8DhgOebjt9wlfk5kOvVp8l71RUHOLfJICjXiTChiH1QY5J8EmO0WRf pMCuK5WysGF0iJJfv6arRJ4lVzvju65Dd1MThJVwXTfsGaFHwUqyEpuGM2KhWurIOyxD jeb3QwG2YAiCsUnAO69Qz5COedJvcPl6iFO8xzsspTGYKFiW24hA83s0PjMNkm42giEY 35/NpiTCVVDJO30I24EcM8o/vfxp5YV+K2dJ6EgEpLgylrnFlax2B96JyLx8ZoOvJBzo 5tFA== 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:in-reply-to :references; bh=MOPftaORDB2h/uSmhamfsr8EUYcrBZ9dAlTNoCP8QMQ=; b=it44ppwp9C6A3B8t3zhD6XPb6+nDvdk01YRkhmFdPhxkT3qIWRp8XvT0YjMFXK5TOz ux3Szo9oOs8yZg4xwGR7VGmW1o5fLlQwOiRL9Ib3BYTvVq9ajXkLfikTRijHyP/NXplM oxx4+sGsmd7boRNqnCzYv3eHwg21u6z9L1/KNliQaTqqsXZBQo8EuRV+u/4hsqCCjRdc iXmNKsrFZ4ZbuUsX0XCwSV5HZjVH4yb9ETwHtmXBJK0MIxdayH9U6i1ryaRgosOv43GB 6naD6FJjfzm1YeHzVMuM9NIUsXhDL8zI0AMhu5kaoYXtKdY8hZTHPSWswwpRjm+aECvV TP2A== X-Gm-Message-State: AOPr4FWszRhKjurKOFJa1vNDTGD1blm9rqq1G6FVEL4KmtZxuDg4VqRP+BJEISsFKfCMtQ== X-Received: by 10.98.19.131 with SMTP id 3mr30410008pft.17.1461948049914; Fri, 29 Apr 2016 09:40:49 -0700 (PDT) Received: from deepa-ubuntu.hsd1.ca.comcast.net (c-73-252-251-201.hsd1.ca.comcast.net. [73.252.251.201]) by smtp.gmail.com with ESMTPSA id b64sm24666578pfa.48.2016.04.29.09.40.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Apr 2016 09:40:49 -0700 (PDT) From: Deepa Dinamani To: linux-kernel@vger.kernel.org Cc: arnd@arndb.de, y2038@lists.linaro.org, linux-fsdevel@vger.kernel.org, John Stultz , Thomas Gleixner Subject: [PATCH 1/3] time: Add missing implementation for timespec64_add_safe() Date: Fri, 29 Apr 2016 09:39:47 -0700 Message-Id: <1461947989-21926-2-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461947989-21926-1-git-send-email-deepa.kernel@gmail.com> References: <1461947989-21926-1-git-send-email-deepa.kernel@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP timespec64_add_safe() has been defined in time64.h for 64 bit systems. But, 32 bit systems only have an extern function prototype defined. Provide a definition for the above function. The function will be necessary as part of y2038 changes. struct timespec is not y2038 safe. All references to timespec will be replaced by struct timespec64. The function is meant to be a replacement for timespec_add_safe(). The implementation is similar to timespec_add_safe(). Signed-off-by: Deepa Dinamani Cc: John Stultz Cc: Thomas Gleixner --- include/linux/time64.h | 4 +--- kernel/time/time.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/linux/time64.h b/include/linux/time64.h index 367d5af..1778937 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -136,13 +136,11 @@ extern void set_normalized_timespec64(struct timespec64 *ts, time64_t sec, s64 n /* * timespec64_add_safe assumes both values are positive and checks for - * overflow. It will return TIME_T_MAX if the returned value would be - * smaller then either of the arguments. + * overflow. It will return TIME64_MAX in case of overflow. */ extern struct timespec64 timespec64_add_safe(const struct timespec64 lhs, const struct timespec64 rhs); - static inline struct timespec64 timespec64_add(struct timespec64 lhs, struct timespec64 rhs) { diff --git a/kernel/time/time.c b/kernel/time/time.c index be115b0..558f5fe 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -769,3 +769,28 @@ struct timespec timespec_add_safe(const struct timespec lhs, return res; } + +#if __BITS_PER_LONG != 64 + +/* + * Add two timespec64 values and do a safety check for overflow. + * It's assumed that both values are valid (>= 0). + * And, each timespec64 is in normalized form. + */ +struct timespec64 timespec64_add_safe(const struct timespec64 lhs, + const struct timespec64 rhs) +{ + struct timespec64 res; + + set_normalized_timespec64(&res, lhs.tv_sec + rhs.tv_sec, + lhs.tv_nsec + rhs.tv_nsec); + + if (unlikely(res.tv_sec < lhs.tv_sec || res.tv_sec < rhs.tv_sec)) { + res.tv_sec = TIME64_MAX; + res.tv_nsec = 0; + } + + return res; +} + +#endif