From patchwork Tue Jun 2 09:04:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 49349 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E315A2052D for ; Tue, 2 Jun 2015 09:08:08 +0000 (UTC) Received: by lbcue7 with SMTP id ue7sf40316226lbc.3 for ; Tue, 02 Jun 2015 02:08:07 -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=2DZ59zQCJSp1jqBzqpYAG5B63Z2MTeLhLEjuD/nrxFM=; b=XLF8FBXkAGyYhWXOPTItz9B5EXf5sykDSaeYYurfwGUQeD0p2dGrCsHaYzaDPu+H3c IEy9UZI5f4rm/u2TsYEvKQfNAwjFJ5Mhyn9hQmnbwek1AIHhi4ijtcumViugvA93V+TL n1m6n1TLjndKjWl9Tod7Qxt8sp51UHKJH47e592EpthnbVWYVNdbJmJTxXbqmTZHMhTC 6voQHHGSs+pbj1SHYxC8pTJ+AZ6XggfpJ2q+GNNsOqwxllXlFLDqiyTfzhxHTFmG3BAY x4Iwd0us3IVpiGdXwYez65d38V67G0HZ7HAv/9i9lu6NY05qDSls4bFHLH0wOCMQxMeW rkDQ== X-Gm-Message-State: ALoCoQlcnRx4rdr5RK2CyruGMnhvso9utbVf0DJ30LW/8C4MbyrOuNCekfi7/chTaoOoLDUtV8xV X-Received: by 10.112.93.203 with SMTP id cw11mr24708568lbb.0.1433236087737; Tue, 02 Jun 2015 02:08:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.41 with SMTP id bd9ls579997lab.109.gmail; Tue, 02 Jun 2015 02:08:07 -0700 (PDT) X-Received: by 10.112.97.194 with SMTP id ec2mr8683184lbb.88.1433236087539; Tue, 02 Jun 2015 02:08:07 -0700 (PDT) Received: from mail-lb0-x22f.google.com (mail-lb0-x22f.google.com. [2a00:1450:4010:c04::22f]) by mx.google.com with ESMTPS id cn6si14544636lbb.126.2015.06.02.02.08.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2015 02:08:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22f as permitted sender) client-ip=2a00:1450:4010:c04::22f; Received: by lbcue7 with SMTP id ue7so100214496lbc.0 for ; Tue, 02 Jun 2015 02:08:07 -0700 (PDT) X-Received: by 10.152.4.72 with SMTP id i8mr25719842lai.32.1433236087442; Tue, 02 Jun 2015 02:08:07 -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 hn6csp2909944lbb; Tue, 2 Jun 2015 02:08:06 -0700 (PDT) X-Received: by 10.70.119.36 with SMTP id kr4mr49066792pdb.39.1433236085196; Tue, 02 Jun 2015 02:08:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mk3si25429441pdb.222.2015.06.02.02.08.04; Tue, 02 Jun 2015 02:08:05 -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 S1757317AbbFBJHz (ORCPT + 28 others); Tue, 2 Jun 2015 05:07:55 -0400 Received: from m50-110.126.com ([123.125.50.110]:44318 "EHLO m50-110.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755022AbbFBJHZ (ORCPT ); Tue, 2 Jun 2015 05:07:25 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp4 (Coremail) with SMTP id jdKowADHAkWqcW1V1JEqAQ--.1798S5; Tue, 02 Jun 2015 17:04:52 +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 v2 4/4] drivers/rtc/sunxi: Replace deprecated rtc_tm_to_time() Date: Tue, 2 Jun 2015 17:04:22 +0800 Message-Id: <1433235862-1638-4-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433235862-1638-1-git-send-email-xlpang@126.com> References: <1433235862-1638-1-git-send-email-xlpang@126.com> X-CM-TRANSID: jdKowADHAkWqcW1V1JEqAQ--.1798S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF45Kr1xurW3tFyfXr4fKrg_yoW5Jr4kpa 1aqa43XrWjqrWagryxJFs5Za45Gw1UJ3yxtanxt3yF9an5JFn8Jr1kCryktr15Wr95Aay3 JFWrAa45uFy7Kw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jDF4iUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiXBINv1R0Wcs-1QABsl 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:c04::22f as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; 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_subtract() Also remove the unnecessary initial zeroing of some local variables in sunxi_rtc_setalarm(). Cc: Carlo Caione Signed-off-by: Xunlei Pang --- 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..ecff5ed 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_subtract(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);