Linux RTC
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Brian Norris <computersforpeace@gmail.com>,
	Gregory Fong <gregory.0xf0@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	bcm-kernel-feedback-list@broadcom.com,
	Markus Mayer <mmayer@broadcom.com>,
	linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rtc: brcmstb-waketimer: fix settime function
Date: Wed, 5 Jul 2017 23:13:27 +0200	[thread overview]
Message-ID: <20170705211327.guccztud22hcmfjy@piout.net> (raw)
In-Reply-To: <20170628200839.3114345-1-arnd@arndb.de>

Hi,

On 28/06/2017 at 22:07:34 +0200, Arnd Bergmann wrote:
> 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 <arnd@arndb.de>
> ---
>  drivers/rtc/rtc-brcmstb-waketimer.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 

I've squashed it in the original commit, I hope this is fine for you.

> 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;
> -- 
> 2.9.0
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

  parent reply	other threads:[~2017-07-05 21:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-28 20:07 [PATCH] rtc: brcmstb-waketimer: fix settime function Arnd Bergmann
2017-06-28 23:14 ` Florian Fainelli
2017-07-05 21:13 ` Alexandre Belloni [this message]
2017-07-05 21:52   ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170705211327.guccztud22hcmfjy@piout.net \
    --to=alexandre.belloni@free-electrons.com \
    --cc=a.zummo@towertech.it \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=computersforpeace@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregory.0xf0@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=mmayer@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox