diff mbox series

[2/7] rtc: jz4740: switch to rtc_time64_to_tm/rtc_tm_to_time64

Message ID 20190418100045.29288-2-alexandre.belloni@bootlin.com (mailing list archive)
State New, archived
Headers show
Series [1/7] rtc: jz4740: set range | expand

Commit Message

Alexandre Belloni April 18, 2019, 10 a.m. UTC
Call the 64bit versions of rtc_tm time conversion now that the range is
enforced by the core.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-jz4740.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Mathieu Malaterre April 26, 2019, 2:29 p.m. UTC | #1
On Thu, Apr 18, 2019 at 12:00 PM Alexandre Belloni
<alexandre.belloni@bootlin.com> wrote:
>
> Call the 64bit versions of rtc_tm time conversion now that the range is
> enforced by the core.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/rtc-jz4740.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
> index 079469627bd7..15b6832f3931 100644
> --- a/drivers/rtc/rtc-jz4740.c
> +++ b/drivers/rtc/rtc-jz4740.c
> @@ -171,7 +171,7 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
>         if (timeout == 0)
>                 return -EIO;
>
> -       rtc_time_to_tm(secs, time);
> +       rtc_time64_to_tm(secs, time);
>
>         return 0;
>  }
> @@ -196,7 +196,7 @@ static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>         alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE);
>         alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF);
>
> -       rtc_time_to_tm(secs, &alrm->time);
> +       rtc_time64_to_tm(secs, &alrm->time);
>
>         return rtc_valid_tm(&alrm->time);
>  }
> @@ -205,9 +205,7 @@ static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  {
>         int ret;
>         struct jz4740_rtc *rtc = dev_get_drvdata(dev);
> -       unsigned long secs;
> -
> -       rtc_tm_to_time(&alrm->time, &secs);
> +       unsigned long secs = rtc_tm_to_time64(&alrm->time);

nitpick: all other declarations are done with uint32_t, so to make it
clear (maybe) with something like:

uint32_t secs = lower_32_bits(rtc_tm_to_time64(&alrm->time));

Technically I would have stored the full time64_t here and put a
WARN_ON(secs > U32_MAX) but I am not sure what other driver are
supposed to do in this case.

>
>         ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs);
>         if (!ret)
> --
> 2.20.1
>
Alexandre Belloni April 26, 2019, 2:38 p.m. UTC | #2
On 26/04/2019 16:29:36+0200, Mathieu Malaterre wrote:
> On Thu, Apr 18, 2019 at 12:00 PM Alexandre Belloni
> <alexandre.belloni@bootlin.com> wrote:
> >
> > Call the 64bit versions of rtc_tm time conversion now that the range is
> > enforced by the core.
> >
> > Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> > ---
> >  drivers/rtc/rtc-jz4740.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
> > index 079469627bd7..15b6832f3931 100644
> > --- a/drivers/rtc/rtc-jz4740.c
> > +++ b/drivers/rtc/rtc-jz4740.c
> > @@ -171,7 +171,7 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
> >         if (timeout == 0)
> >                 return -EIO;
> >
> > -       rtc_time_to_tm(secs, time);
> > +       rtc_time64_to_tm(secs, time);
> >
> >         return 0;
> >  }
> > @@ -196,7 +196,7 @@ static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> >         alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE);
> >         alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF);
> >
> > -       rtc_time_to_tm(secs, &alrm->time);
> > +       rtc_time64_to_tm(secs, &alrm->time);
> >
> >         return rtc_valid_tm(&alrm->time);
> >  }
> > @@ -205,9 +205,7 @@ static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
> >  {
> >         int ret;
> >         struct jz4740_rtc *rtc = dev_get_drvdata(dev);
> > -       unsigned long secs;
> > -
> > -       rtc_tm_to_time(&alrm->time, &secs);
> > +       unsigned long secs = rtc_tm_to_time64(&alrm->time);
> 
> nitpick: all other declarations are done with uint32_t, so to make it
> clear (maybe) with something like:
> 
> uint32_t secs = lower_32_bits(rtc_tm_to_time64(&alrm->time));
> 

Ok, I'll change that.

> Technically I would have stored the full time64_t here and put a
> WARN_ON(secs > U32_MAX) but I am not sure what other driver are
> supposed to do in this case.
> 

Because range_max is set properly, the core will ensure that all the
times passed to the driver fit within the range.

Thanks for the review!
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 079469627bd7..15b6832f3931 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -171,7 +171,7 @@  static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
 	if (timeout == 0)
 		return -EIO;
 
-	rtc_time_to_tm(secs, time);
+	rtc_time64_to_tm(secs, time);
 
 	return 0;
 }
@@ -196,7 +196,7 @@  static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE);
 	alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF);
 
-	rtc_time_to_tm(secs, &alrm->time);
+	rtc_time64_to_tm(secs, &alrm->time);
 
 	return rtc_valid_tm(&alrm->time);
 }
@@ -205,9 +205,7 @@  static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
 	int ret;
 	struct jz4740_rtc *rtc = dev_get_drvdata(dev);
-	unsigned long secs;
-
-	rtc_tm_to_time(&alrm->time, &secs);
+	unsigned long secs = rtc_tm_to_time64(&alrm->time);
 
 	ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs);
 	if (!ret)