From patchwork Fri Jun 12 02:04:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 49778 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EB3072460E for ; Fri, 12 Jun 2015 02:07:15 +0000 (UTC) Received: by wgez8 with SMTP id z8sf5868072wge.2 for ; Thu, 11 Jun 2015 19:07:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=kFxn5Yj+NBTaNbzPLypje0B9uphmnmmUArB3Svik1OM=; b=gFutCpX1N6C+CeRXBXSOfAu4o8nN8ov1UJ6jWN2NeEMIhdtMElB74l5NeNpS9C8aU8 NxaQ4slI2bCEHgqVtlhmuRa3GrNsDu8sPzTzJaeQN5RvzCHv1zZskzFHZLmmVl3NBzCV DpzM0+BCUuqfQLQv7H4RPDJQOFqz0ztJDc54u4vXH0bUw6revTvx+GxNZz2LXvXeU3NX O866uzgQtu8UDNf+RHpTk0d3Wrbvejjy8bnJFylr5hIYvfhtaCM3XTKROixBwws3kZw2 l5sUp2Ka8suW8cwGxvVjb+R+P6lmoZGHt+AgQPys/b6dOVMCQR0QbVe7hboRk2Iaptn/ ccew== X-Gm-Message-State: ALoCoQn1NNH9vqfuxbaVWot21A+O7WmL7SqQRW7Aqz4xn5PvifmP5k9Xktm5FWLdiXSMOYw8snWg X-Received: by 10.152.5.2 with SMTP id o2mr11646339lao.0.1434074835189; Thu, 11 Jun 2015 19:07:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.65 with SMTP id r1ls516964lag.61.gmail; Thu, 11 Jun 2015 19:07:15 -0700 (PDT) X-Received: by 10.112.42.16 with SMTP id j16mr12566232lbl.98.1434074835003; Thu, 11 Jun 2015 19:07:15 -0700 (PDT) Received: from mail-la0-x233.google.com (mail-la0-x233.google.com. [2a00:1450:4010:c03::233]) by mx.google.com with ESMTPS id r1si2159877lar.2.2015.06.11.19.07.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 19:07:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::233 as permitted sender) client-ip=2a00:1450:4010:c03::233; Received: by lazv15 with SMTP id v15so13102683laz.3 for ; Thu, 11 Jun 2015 19:07:14 -0700 (PDT) X-Received: by 10.112.234.200 with SMTP id ug8mr12650717lbc.117.1434074834718; Thu, 11 Jun 2015 19:07:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp217472lbb; Thu, 11 Jun 2015 19:07:13 -0700 (PDT) X-Received: by 10.68.57.170 with SMTP id j10mr19319154pbq.150.1434074832667; Thu, 11 Jun 2015 19:07:12 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id by3si2093831pdb.201.2015.06.11.19.07.11; Thu, 11 Jun 2015 19:07:12 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751319AbbFLCGT (ORCPT + 29 others); Thu, 11 Jun 2015 22:06:19 -0400 Received: from m50-112.126.com ([123.125.50.112]:51695 "EHLO m50-112.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750737AbbFLCGQ (ORCPT ); Thu, 11 Jun 2015 22:06:16 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp6 (Coremail) with SMTP id j9KowAAnryswPnpVKTVCAA--.101S5; Fri, 12 Jun 2015 10:04:48 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Alessandro Zummo , Alexandre Belloni , John Stultz , Arnd Bergmann , Xunlei Pang , Carlo Caione Subject: [PATCH v3 4/4] drivers/rtc/sunxi: Replace deprecated rtc_tm_to_time() Date: Fri, 12 Jun 2015 10:04:12 +0800 Message-Id: <1434074652-16054-4-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434074652-16054-1-git-send-email-xlpang@126.com> References: <1434074652-16054-1-git-send-email-xlpang@126.com> X-CM-TRANSID: j9KowAAnryswPnpVKTVCAA--.101S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF45Kr1xurW3tr4xZw1fZwb_yoW5JF47pa 1aqa43Xr4jqryagr97Jrs5Za45Gw1UJw4xtwsxt3yFvan5JFn8JF1kCryktr15WrykAay3 JFWrJa45Wry7Kw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jDF4iUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbirxwXv0X9w-FZwwAAsL Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: xlpang@126.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::233 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@126.com; dmarc=fail (p=NONE dis=NONE) header.from=126.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Xunlei Pang sunxi_rtc_setalarm() uses deprecated rtc_tm_to_time(), which will overflow in year 2106 on 32-bit machines. This patch solves this by: - Replacing rtc_tm_to_time() with rtc_tm_sub() Also remove the unnecessary initial zeroing of some local variables in sunxi_rtc_setalarm(). Cc: Carlo Caione Signed-off-by: Xunlei Pang --- v2->v3: Rename rtc_tm_subtract() to rtc_tm_sub(). drivers/rtc/rtc-sunxi.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c index 6e678fa..52543ae 100644 --- a/drivers/rtc/rtc-sunxi.c +++ b/drivers/rtc/rtc-sunxi.c @@ -269,14 +269,13 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm) struct sunxi_rtc_dev *chip = dev_get_drvdata(dev); struct rtc_time *alrm_tm = &wkalrm->time; struct rtc_time tm_now; - u32 alrm = 0; - unsigned long time_now = 0; - unsigned long time_set = 0; - unsigned long time_gap = 0; - unsigned long time_gap_day = 0; - unsigned long time_gap_hour = 0; - unsigned long time_gap_min = 0; - int ret = 0; + u32 alrm; + time64_t diff; + unsigned long time_gap; + unsigned long time_gap_day; + unsigned long time_gap_hour; + unsigned long time_gap_min; + int ret; ret = sunxi_rtc_gettime(dev, &tm_now); if (ret < 0) { @@ -284,14 +283,18 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm) return -EINVAL; } - rtc_tm_to_time(alrm_tm, &time_set); - rtc_tm_to_time(&tm_now, &time_now); - if (time_set <= time_now) { + diff = rtc_tm_sub(alrm_tm, &tm_now); + if (diff <= 0) { dev_err(dev, "Date to set in the past\n"); return -EINVAL; } - time_gap = time_set - time_now; + if (diff > 255 * SEC_IN_DAY) { + dev_err(dev, "Day must be in the range 0 - 255\n"); + return -EINVAL; + } + + time_gap = diff; time_gap_day = time_gap / SEC_IN_DAY; time_gap -= time_gap_day * SEC_IN_DAY; time_gap_hour = time_gap / SEC_IN_HOUR; @@ -299,11 +302,6 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm) time_gap_min = time_gap / SEC_IN_MIN; time_gap -= time_gap_min * SEC_IN_MIN; - if (time_gap_day > 255) { - dev_err(dev, "Day must be in the range 0 - 255\n"); - return -EINVAL; - } - sunxi_rtc_setaie(0, chip); writel(0, chip->base + SUNXI_ALRM_DHMS); usleep_range(100, 300);