From patchwork Fri Dec 4 00:12:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 552490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-yk0-x240.google.com (mail-yk0-x240.google.com [IPv6:2607:f8b0:4002:c07::240]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8A3061402A8 for ; Fri, 4 Dec 2015 11:12:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=aWkHeJVd; dkim-atps=neutral Received: by ykdr82 with SMTP id r82sf19826639ykd.0 for ; Thu, 03 Dec 2015 16:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:x-original-sender :x-original-authentication-results:reply-to:content-type:precedence :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help :list-archive:sender:list-subscribe:list-unsubscribe; bh=8SwHbyM1MXaWkY18FhNgLCPUMevhXob1vYWrHasw7DM=; b=aWkHeJVdsBRmStlKblnehY9zF8u5mWAyiAzUwLsSlbUOcDdlCAtgmpgJw6xlr5ssvP GYESRG59nfr2h13Bc8TWf7Kh50gfv2IARcSiWBsgDtDFUxzNBHyiK88yRjEg40boBmIg ofeVmiaaPsWCcriU+dXfoshnbJx3eHI+sXWh5URon9nP0NgdWupTuHl1DoJcwzAF7lSq TcS8Ka0NicTctqnNH8ZatQzHjFx7qjPmN2ShHJt3sfmjT8fPYuTk5OyNvAcPnUDFxCAK QuWJ0DtnL2TWStI8SmXr+q6dImw+PjCWeSY9c2vQVRAN12e6fopFk778eRP//gMCdj6b i4lQ== X-Received: by 10.50.109.229 with SMTP id hv5mr60272igb.0.1449187955317; Thu, 03 Dec 2015 16:12:35 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.50.225.38 with SMTP id rh6ls795igc.29.gmail; Thu, 03 Dec 2015 16:12:34 -0800 (PST) X-Received: by 10.66.192.234 with SMTP id hj10mr10963954pac.28.1449187954913; Thu, 03 Dec 2015 16:12:34 -0800 (PST) Received: from aserp1040.oracle.com (aserp1040.oracle.com. [141.146.126.69]) by gmr-mx.google.com with ESMTPS id mv7si100954igb.0.2015.12.03.16.12.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Dec 2015 16:12:34 -0800 (PST) Received-SPF: pass (google.com: domain of sasha.levin@oracle.com designates 141.146.126.69 as permitted sender) client-ip=141.146.126.69; Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tB40CUtB018145 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Dec 2015 00:12:30 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id tB40CTLA012539 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 4 Dec 2015 00:12:30 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id tB40CSr8004706; Fri, 4 Dec 2015 00:12:29 GMT Received: from lappy.us.oracle.com (/10.154.152.43) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 03 Dec 2015 16:12:28 -0800 From: Sasha Levin To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Sasha Levin Subject: [rtc-linux] [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Date: Thu, 3 Dec 2015 19:12:24 -0500 Message-Id: <1449187944-11730-1-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 2.5.0 X-Source-IP: aserv0022.oracle.com [141.146.126.234] X-Original-Sender: sasha.levin@oracle.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of sasha.levin@oracle.com designates 141.146.126.69 as permitted sender) smtp.mailfrom=sasha.levin@oracle.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , At some point after humans go extinct and robots cotrol the world, dividing he time64_t by 86400 to extract the days will overflow a 32bit integer, leading to incorrect conversion into rtc_time in rtc_time64_to_tm(). Signed-off-by: Sasha Levin --- drivers/rtc/rtc-lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index e6bfb9c..459cd4d 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -54,11 +54,11 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) { unsigned int month, year; unsigned long secs; - int days; + time64_t days; /* time must be positive */ days = div_s64(time, 86400); - secs = time - (unsigned int) days * 86400; + secs = time - days * 86400; /* day of the week, 1970-01-01 was a Thursday */ tm->tm_wday = (days + 4) % 7;