public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: sa1100: detect rcnr overflow with dates after 2038
@ 2016-01-19  0:57 Alexandre Belloni
  2016-01-19 20:16 ` Robert Jarzmik
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Belloni @ 2016-01-19  0:57 UTC (permalink / raw)
  To: Alessandro Zummo
  Cc: Rob Herring, Robert Jarzmik, rtc-linux, linux-kernel,
	Alexandre Belloni

rcnr will overflow in 2038, detect that overflow when setting the time and
get rid of the deprecated rtc_tm_to_time()

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

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index c2187bf6c7e4..239dd3d7df1b 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -162,13 +162,16 @@ static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
 	struct sa1100_rtc *info = dev_get_drvdata(dev);
-	unsigned long time;
+	time64_t time;
 	int ret;
 
-	ret = rtc_tm_to_time(tm, &time);
-	if (ret == 0)
-		writel_relaxed(time, info->rcnr);
-	return ret;
+	time = rtc_tm_to_time64(tm);
+	if (time > U32_MAX)
+		return -EINVAL;
+
+	writel_relaxed(time, info->rcnr);
+
+	return 0;
 }
 
 static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc: sa1100: detect rcnr overflow with dates after 2038
  2016-01-19  0:57 [PATCH] rtc: sa1100: detect rcnr overflow with dates after 2038 Alexandre Belloni
@ 2016-01-19 20:16 ` Robert Jarzmik
  2016-01-19 20:46   ` Alexandre Belloni
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Jarzmik @ 2016-01-19 20:16 UTC (permalink / raw)
  To: Alexandre Belloni, Alessandro Zummo; +Cc: Rob Herring, rtc-linux, linux-kernel

Alexandre Belloni <alexandre.belloni@free-electrons.com> writes:

> rcnr will overflow in 2038, detect that overflow when setting the time and
> get rid of the deprecated rtc_tm_to_time()
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

Hi Alexandre,

That's very nice, but doesn't that limitation touch almost all drivers, and
could benefit from a global solution in rtc_set_time() ?

What I'm thinking of is a field in rtc_device, a u64 which represents the
maximal time that can be set (or 0 if no maximum). rtc_set_time() would check
against that maximum and return -EINVAL.

For the rtc drivers, upon registration they can modify this value to set up this
clamp. This will require to set only a value in each driver, which looks more
robust to me.

Alessandro, what do you think ?

Cheers.

--
Robert

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc: sa1100: detect rcnr overflow with dates after 2038
  2016-01-19 20:16 ` Robert Jarzmik
@ 2016-01-19 20:46   ` Alexandre Belloni
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2016-01-19 20:46 UTC (permalink / raw)
  To: Robert Jarzmik; +Cc: Alessandro Zummo, Rob Herring, rtc-linux, linux-kernel

Hi,

On 19/01/2016 at 21:16:11 +0100, Robert Jarzmik wrote :
> Alexandre Belloni <alexandre.belloni@free-electrons.com> writes:
> 
> > rcnr will overflow in 2038, detect that overflow when setting the time and
> > get rid of the deprecated rtc_tm_to_time()
> >
> > Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> 
> That's very nice, but doesn't that limitation touch almost all drivers, and
> could benefit from a global solution in rtc_set_time() ?
> 
> What I'm thinking of is a field in rtc_device, a u64 which represents the
> maximal time that can be set (or 0 if no maximum). rtc_set_time() would check
> against that maximum and return -EINVAL.
> 
> For the rtc drivers, upon registration they can modify this value to set up this
> clamp. This will require to set only a value in each driver, which looks more
> robust to me.
> 

Actually, that is something I'm currently working on but it is not ready
yet.


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-19 20:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-19  0:57 [PATCH] rtc: sa1100: detect rcnr overflow with dates after 2038 Alexandre Belloni
2016-01-19 20:16 ` Robert Jarzmik
2016-01-19 20:46   ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox