Message ID | 1462950684-3661-3-git-send-email-uwe@kleine-koenig.org |
---|---|
State | Rejected |
Headers | show
Return-Path: <rtc-linux+bncBDS7HNEFSALRB764664QKGQESCROZAQ@googlegroups.com> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-lb0-x23c.google.com (mail-lb0-x23c.google.com [IPv6:2a00:1450:4010:c04::23c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r9cTt0jRkz9t3n for <incoming@patchwork.ozlabs.org>; Fri, 20 May 2016 02:49:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=q8h8ZZcM; dkim-atps=neutral Received: by mail-lb0-x23c.google.com with SMTP id mx9sf12050186lbb.0 for <incoming@patchwork.ozlabs.org>; Thu, 19 May 2016 09:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=sender:resent-from:resent-date:resent-message-id:resent-to:from:to :cc:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=KP1ZKcOpKQwdUZE96nBsIwBKlq65iF3ivK+1k45BK0Y=; b=q8h8ZZcM/RZlLBMbSdwrtXjjgXmr9D5u3PvoDvAWMVswIIRJmuW0zko7O/paV42uC6 VfAqRA8dguhB0aFh0Beo5JA9VLCOba4Aj/Hlbw5I0sboE4RyA7/qScN9ykOrYc0Z16MC zoDAc+JAXg6zkmocGLS8elwAI8umQ6/oryfbRg/vIfcyQIVGdkSyQQP30J+8EYemGXDt aBgT2yhiBZcWKAyC2b2SUqo5pI+2MMALCK6TofleMwdxj/3U5q4ps4fTpaAN+kqA4RXr MtxLb/t+rzkivRNnZpkr2TNsC2Vm8YntzOHLd8tLPMmPmXTJFceavd85T5OaGoKQeu2t SDqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=sender:x-gm-message-state:resent-from:resent-date:resent-message-id :resent-to:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=KP1ZKcOpKQwdUZE96nBsIwBKlq65iF3ivK+1k45BK0Y=; b=T4zloIYpu8IwGEewIr87nbQtE4bmP65H0qPoKQXHBthx0mdoeZN4Dz3BBoc1fsBuFo YOgld34sjLsbjme2Li3yILq5ryOEjOOptV1hkrEx2I+U9VTR2DnZw2UeJHDMYy1w7ms5 DLBBrCEe762CDYPkCjdbKKeKmCZcV3/V3CEr+F8JxY4wbnAH+v9lDUElKiYDwc9m2vWD 3RkdxtMy1t6Xj2auHxH4dIy3svOTgRFTKiS9BURC8yuaEvTbAXDc+Wh5mKcCQ/+gaY1A 5cmC/QlIbF2SOuj601T+Gu+k6+kxMvfmznYbQDkXc1q60J7wdxovZ0zvyWorKLi3oldS BX/w== Sender: rtc-linux@googlegroups.com X-Gm-Message-State: AOPr4FUggxmAzaWBzUXxtdSeIufXQSaP7J2WDWxE0OFhlbNcab/XX9NRfG5QhuUj7WE2AQ== X-Received: by 10.25.25.211 with SMTP id 202mr518055lfz.16.1463676543450; Thu, 19 May 2016 09:49:03 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.25.146.138 with SMTP id u132ls296653lfd.55.gmail; Thu, 19 May 2016 09:49:03 -0700 (PDT) X-Received: by 10.112.141.104 with SMTP id rn8mr5258218lbb.12.1463676542989; Thu, 19 May 2016 09:49:02 -0700 (PDT) Received: from mail.free-electrons.com (down.free-electrons.com. [37.187.137.238]) by gmr-mx.google.com with ESMTP id b193si12712wmb.1.2016.05.19.09.49.02 for <rtc-linux@googlegroups.com>; Thu, 19 May 2016 09:49:02 -0700 (PDT) Received-SPF: pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) client-ip=37.187.137.238; Received: by mail.free-electrons.com (Postfix, from userid 110) id 388A420CC; Thu, 19 May 2016 18:49:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,URIBL_BLOCKED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id 22C8412D for <rtc-linux@googlegroups.com>; Thu, 19 May 2016 18:48:48 +0200 (CEST) Resent-From: Alexandre Belloni <alexandre.belloni@free-electrons.com> Resent-Date: Thu, 19 May 2016 18:48:48 +0200 Resent-Message-ID: <20160519164848.GL2890@piout.net> Resent-To: rtc-linux@googlegroups.com Received: by mail.free-electrons.com (Postfix, from userid 110) id CC4A54A4; Wed, 11 May 2016 09:11:34 +0200 (CEST) Received: from arcturus.kleine-koenig.org (arcturus.kleine-koenig.org [78.47.169.190]) by mail.free-electrons.com (Postfix) with ESMTPS id 60596613 for <alexandre.belloni@free-electrons.com>; Wed, 11 May 2016 09:11:33 +0200 (CEST) Received: by arcturus.kleine-koenig.org (Postfix, from userid 1000) id 595ECA2949; Wed, 11 May 2016 09:11:33 +0200 (CEST) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <uwe@kleine-koenig.org> To: Alessandro Zummo <a.zummo@towertech.it>, Alexandre Belloni <alexandre.belloni@free-electrons.com> Cc: rtc-linux@googlegroups.com, Michael Langer <michael.brainbug.langer@googlemail.com>, Byron Bradley <byron.bbradley@gmail.com>, =?UTF-8?q?Manuel=20R=C3=B6der?= <manuel_roeder@gmx.de> Subject: [rtc-linux] [PATCH RESEND 2/2] rtc: make rtc_time64_to_tm save to use for dates before 1970 Date: Wed, 11 May 2016 09:11:24 +0200 Message-Id: <1462950684-3661-3-git-send-email-uwe@kleine-koenig.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1462950684-3661-1-git-send-email-uwe@kleine-koenig.org> References: <1462950684-3661-1-git-send-email-uwe@kleine-koenig.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-TUID: uyfhsieUw6uV X-Original-Sender: alexandre.belloni@free-electrons.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of alexandre.belloni@free-electrons.com designates 37.187.137.238 as permitted sender) smtp.mailfrom=alexandre.belloni@free-electrons.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: <rtc-linux.googlegroups.com> X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: <https://groups.google.com/group/rtc-linux/post>, <mailto:rtc-linux@googlegroups.com> List-Help: <https://groups.google.com/support/>, <mailto:rtc-linux+help@googlegroups.com> List-Archive: <https://groups.google.com/group/rtc-linux List-Subscribe: <https://groups.google.com/group/rtc-linux/subscribe>, <mailto:rtc-linux+subscribe@googlegroups.com> List-Unsubscribe: <mailto:googlegroups-manage+712029733259+unsubscribe@googlegroups.com>, <https://groups.google.com/group/rtc-linux/subscribe> |
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index e6bfb9c42a10..0140ce7088ac 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -53,15 +53,20 @@ EXPORT_SYMBOL(rtc_year_days); void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) { unsigned int month, year; - unsigned long secs; + s32 secs int days; - /* time must be positive */ - days = div_s64(time, 86400); - secs = time - (unsigned int) days * 86400; + days = div_s64_rem(time, 86400, &secs); + + if (secs < 0) { + secs += 86400; + days -= 1; + } /* day of the week, 1970-01-01 was a Thursday */ tm->tm_wday = (days + 4) % 7; + if (tm->tm_wday < 0) + tm->tm_wday += 7; year = 1970 + days / 365; days -= (year - 1970) * 365
When the time parameter to rtc_time64_to_tm is negative and so represents a date before 1970 several outputs were calculated wrongly. A comment in the code signaled that the code doesn't handle negative times but that didn't stop __rtc_read_alarm to still pass negative values. For example with time=-2208565980 (1900-01-05 21:27 UTC) the days variable was assigned a negative value (-25562) which was then used to calculate secs = time - (unsigned int) days * 86400; resulting in an overflow in both the multiplication and the subtraction yielding secs = 4294958116 which is then used to calculate tm_hour = 1193043; tm_min = 55; tm_sec = 16. With the changes in this patch the time stamp from the example above is converted correctly. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> --- drivers/rtc/rtc-lib.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)