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: 106576 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp315208qge; Wed, 28 Jun 2017 13:09:47 -0700 (PDT) X-Received: by 10.101.76.3 with SMTP id u3mr11925799pgq.119.1498680587247; Wed, 28 Jun 2017 13:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498680587; cv=none; d=google.com; s=arc-20160816; b=LHxXvxu7ExEi5hp9dWkVwzpY0FRCJ6Dm56JmmkT/5Q5ui/O60VFomSrzPRZy9Y02XN lSDqEBKanQ4SwNN6Unyr7ctXamI8yB1L4ii9a+qs18cnoKcorOts2dQnuAvLNchOdcaR RgUeXbREJpPy/lvn3nR+yDUvNzr3VIBFk85WwSRM8Dnkcc1SDaDtOGFXrarG2FpZYgsG 61oVlU2ztDjiu7Yiy+3Wi7WwR/5e8fLp4KgEJ5QDCKOb8M654llPkUHluENq+kSp6CI1 yhkrt7Gw8yGjTosJE84pfdP01gmJRzTt4WYCNZABHVNgwnAwbDTFWvDJS9D4khSbsQ+c taxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=PFRQWq5vH9vg1Ij/lVq9e4F/rp7QybNMxGuHbqJIiPQ=; b=Fu4p29qNijfWLbvQSdMNyGfqLAMIeX80G8fscRoNJ2CiXx+fWajQs8uT3vMbMXXGJ5 iP10+ylWxHluEXP+y52t45m+Kt0HVlFy1W163+T0Cam06fNXA2MFqkYl68SJMdwRKveK WW3/pd6+wsmJMzlGRpN0f7aCNGmfp/gBSHRVrvFjaKZnakB5F82lcY8/kJDxKKw72rOF 2ji6WkMlvCUZ5z1izOARA85VO9tErNCX4/h5E1PYE6KviEmP/DOfvrXuJ2uKxLdSdD+I MfbyKQIYSBmln4284qu7E0uVsr61RKdZCupCZpYElgZQSqhWdOsK1GvEJ8XXixIi4hYX sM2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l91si2444592plb.581.2017.06.28.13.09.46; Wed, 28 Jun 2017 13:09:47 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751974AbdF1UJj (ORCPT + 25 others); Wed, 28 Jun 2017 16:09:39 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- drivers/rtc/rtc-brcmstb-waketimer.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) -- 2.9.0 Reviewed-by: Florian Fainelli 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;