From patchwork Wed Jun 28 20:07:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 781905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wyYmB5hh3z9s65 for ; Thu, 29 Jun 2017 06:09:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751787AbdF1UJ3 (ORCPT ); Wed, 28 Jun 2017 16:09:29 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:55993 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751874AbdF1UJ2 (ORCPT ); Wed, 28 Jun 2017 16:09:28 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0MPoeo-1dMTma3jxi-004xJh; Wed, 28 Jun 2017 22:08:43 +0200 From: Arnd Bergmann To: Alexandre Belloni Cc: Arnd Bergmann , Alessandro Zummo , Brian Norris , Gregory Fong , Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, Markus Mayer , linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] rtc: brcmstb-waketimer: fix settime function Date: Wed, 28 Jun 2017 22:07:34 +0200 Message-Id: <20170628200839.3114345-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:E+dgdViIIx+FgsT0BemZijbHmVP4f5LvgDFy5STVRUezLLdmHsv gjz5WxJsvPLjxuSvYPDSmlaXdBJm/TXGaptKPFS7jmVqeM5wgW3WvyIrkZy/8q1V1BQMG43 W8F+ejQXA5TtZOVoZQoGn+90oLLEemLlasq+LctNQKdqcHMnVKo4MW7Kpl9uiSD2f/MJMCb w/M7wIJGOl9ec/nsOMPsw== X-UI-Out-Filterresults: notjunk:1; V01:K0:ZrVYTPFJP14=:pwHPCYFj7qds//sYkKOFmd Rk/RBVfRPZVaVv/PlK75chbLQYny0I8meG2vtwkqmAs5APVLRU+BW2B4fC06mDbvDutSfLM0e Is6ROboQniNDNwJtgt/8IfHGlIIBftp/RvlbbcSZ55WezGPVKCxPmBEdeCOBrX6FXdlgiHNk1 fsovdfwuuVfYo4YUlAQnW2wGNxLEESGI7vYAfQ0dOp3Y0lSlS+llTMYpR0x1m3D0P8fhdqh8V lykbMJT7A4jwQ0tfnFbXdkEtHbtluZSRnYKybBjZyofnVbGIjRaRYLloDKa2R36eQCBwGVExv sE88aZWpJSRhPVAwEFxdOj+01+PzHjVe1jV8a1jum6d98VdGBq3REneiWDkhBpBkQlb4QEi9J kGatQktdbC7O8FO326hKNg6deQ0nasLxz7TUwY0Hd1RBg13a+ku2Ygb2XPRlKDxVzjZz4sh5a BAkpDlYnRLcdJ4Pjb/eREG9o/Wj8J8/DG8eI75KEM3jKd+w/lVQDnASo7HQUBP0VOASv1h+gX 8xBvNKoM6kOOYeuXm/obpNE0hEcxHUnhFJUl0GzzorHAoSph8t2UXIEtbaJRHeFwsn52KBNtJ plnUD8KJ/ADC/8h6lNQwBlbRm1QQYZanV6wjbDqnafW/kcnd3+Nlx5QZX2bXyPO+bOIvA8fGT LxcJ/JvvZ4QciSg0YYObw5PcAQiHQrMUxzOcZAwxh3fJkHsOEdsUwy6cObqeG7Pz7dcs= Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org gcc warns about an unused variable in the new driver: drivers/rtc/rtc-brcmstb-waketimer.c: In function 'brcmstb_waketmr_settime': drivers/rtc/rtc-brcmstb-waketimer.c:142:6: error: unused variable 'ret' [-Werror=unused-variable] The same function also doesn't handle overflow correctly, this makes it return -EINVAL when passed a time that doesn't fit within the range of the register. Fixes: 9f4ad359c801 ("rtc: brcmstb-waketimer: Add Broadcom STB wake-timer") Signed-off-by: Arnd Bergmann Reviewed-by: Florian Fainelli --- drivers/rtc/rtc-brcmstb-waketimer.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-brcmstb-waketimer.c b/drivers/rtc/rtc-brcmstb-waketimer.c index 5dea6d0627d8..796ac792a381 100644 --- a/drivers/rtc/rtc-brcmstb-waketimer.c +++ b/drivers/rtc/rtc-brcmstb-waketimer.c @@ -138,10 +138,12 @@ static int brcmstb_waketmr_settime(struct device *dev, struct rtc_time *tm) { struct brcmstb_waketmr *timer = dev_get_drvdata(dev); - unsigned long sec; - int ret; + time64_t sec; + + sec = rtc_tm_to_time64(tm); - rtc_tm_to_time(tm, &sec); + if (sec > U32_MAX || sec < 0) + return -EINVAL; writel_relaxed(sec, timer->base + BRCMSTB_WKTMR_COUNTER); @@ -152,14 +154,14 @@ static int brcmstb_waketmr_getalarm(struct device *dev, struct rtc_wkalrm *alarm) { struct brcmstb_waketmr *timer = dev_get_drvdata(dev); - unsigned long sec; + time64_t sec; u32 reg; sec = readl_relaxed(timer->base + BRCMSTB_WKTMR_ALARM); if (sec != 0) { /* Alarm is enabled */ alarm->enabled = 1; - rtc_time_to_tm(sec, &alarm->time); + rtc_time64_to_tm(sec, &alarm->time); } reg = readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT); @@ -172,13 +174,16 @@ static int brcmstb_waketmr_setalarm(struct device *dev, struct rtc_wkalrm *alarm) { struct brcmstb_waketmr *timer = dev_get_drvdata(dev); - unsigned long sec; + time64_t sec; if (alarm->enabled) - rtc_tm_to_time(&alarm->time, &sec); + sec = rtc_tm_to_time64(&alarm->time); else sec = 0; + if (sec > U32_MAX || sec < 0) + return -EINVAL; + brcmstb_waketmr_set_alarm(timer, sec); return 0;