* [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time()
@ 2015-06-12 2:04 Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 2/4] rtc/lib: Introduce rtc_tm_sub() helper function Xunlei Pang
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Xunlei Pang @ 2015-06-12 2:04 UTC (permalink / raw)
To: linux-kernel
Cc: rtc-linux, Alessandro Zummo, Alexandre Belloni, John Stultz,
Arnd Bergmann, Xunlei Pang
From: Xunlei Pang <pang.xunlei@linaro.org>
pcf8563_rtc_set_alarm() uses deprecated rtc_tm_to_time()
and rtc_time_to_tm(), which will overflow in year 2106
on 32-bit machines.
This patch solves this by:
- Replacing rtc_time_to_tm() with rtc_time64_to_tm()
- Replacing rtc_tm_to_time() with rtc_tm_to_time64()
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
v2->v3:
no changes.
drivers/rtc/rtc-pcf8563.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 0ba7e59..5f87f84 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -363,13 +363,13 @@ static int pcf8563_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
struct i2c_client *client = to_i2c_client(dev);
unsigned char buf[4];
int err;
- unsigned long alarm_time;
/* The alarm has no seconds, round up to nearest minute */
if (tm->time.tm_sec) {
- rtc_tm_to_time(&tm->time, &alarm_time);
- alarm_time += 60-tm->time.tm_sec;
- rtc_time_to_tm(alarm_time, &tm->time);
+ time64_t alarm_time = rtc_tm_to_time64(&tm->time);
+
+ alarm_time += 60 - tm->time.tm_sec;
+ rtc_time64_to_tm(alarm_time, &tm->time);
}
dev_dbg(dev, "%s, min=%d hour=%d wday=%d mday=%d "
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/4] rtc/lib: Introduce rtc_tm_sub() helper function
2015-06-12 2:04 [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Xunlei Pang
@ 2015-06-12 2:04 ` Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 3/4] drivers/rtc/isl1208: Replace deprecated rtc_tm_to_time() Xunlei Pang
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Xunlei Pang @ 2015-06-12 2:04 UTC (permalink / raw)
To: linux-kernel
Cc: rtc-linux, Alessandro Zummo, Alexandre Belloni, John Stultz,
Arnd Bergmann, Xunlei Pang
From: Xunlei Pang <pang.xunlei@linaro.org>
There're many sites need comparing the two rtc_time variants for many
rtc drivers, especially in the instances of rtc_class_ops::set_alarm().
So add this common helper function to make things easy.
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
v2->v3:
Respin rtc_tm_subtract() to rtc_tm_sub() using "static inline".
include/linux/rtc.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 8dcf682..f46f765 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -24,6 +24,14 @@ extern void rtc_time64_to_tm(time64_t time, struct rtc_time *tm);
ktime_t rtc_tm_to_ktime(struct rtc_time tm);
struct rtc_time rtc_ktime_to_tm(ktime_t kt);
+/*
+ * rtc_tm_sub - Return the difference in seconds.
+ */
+static inline time64_t rtc_tm_sub(struct rtc_time *lhs, struct rtc_time *rhs)
+{
+ return rtc_tm_to_time64(lhs) - rtc_tm_to_time64(rhs);
+}
+
/**
* Deprecated. Use rtc_time64_to_tm().
*/
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 3/4] drivers/rtc/isl1208: Replace deprecated rtc_tm_to_time()
2015-06-12 2:04 [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 2/4] rtc/lib: Introduce rtc_tm_sub() helper function Xunlei Pang
@ 2015-06-12 2:04 ` Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 4/4] drivers/rtc/sunxi: " Xunlei Pang
2015-06-12 8:40 ` [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Alexandre Belloni
3 siblings, 0 replies; 7+ messages in thread
From: Xunlei Pang @ 2015-06-12 2:04 UTC (permalink / raw)
To: linux-kernel
Cc: rtc-linux, Alessandro Zummo, Alexandre Belloni, John Stultz,
Arnd Bergmann, Xunlei Pang, Herbert Valerio Riedel
From: Xunlei Pang <pang.xunlei@linaro.org>
isl1208_i2c_set_alarm() uses deprecated rtc_tm_to_time(),
which will overflow in year 2106 on 32-bit machines.
This patch solves this by:
- Replacing rtc_tm_to_time() with rtc_tm_sub()
Cc: Herbert Valerio Riedel <hvr@gnu.org>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
v2->v3:
Rename rtc_tm_subtract() to rtc_tm_sub().
drivers/rtc/rtc-isl1208.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index c3c549d..aa3b8f1 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -370,22 +370,15 @@ isl1208_i2c_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
struct rtc_time *alarm_tm = &alarm->time;
u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
const int offs = ISL1208_REG_SCA;
- unsigned long rtc_secs, alarm_secs;
struct rtc_time rtc_tm;
int err, enable;
err = isl1208_i2c_read_time(client, &rtc_tm);
if (err)
return err;
- err = rtc_tm_to_time(&rtc_tm, &rtc_secs);
- if (err)
- return err;
- err = rtc_tm_to_time(alarm_tm, &alarm_secs);
- if (err)
- return err;
/* If the alarm time is before the current time disable the alarm */
- if (!alarm->enabled || alarm_secs <= rtc_secs)
+ if (!alarm->enabled || rtc_tm_sub(alarm_tm, &rtc_tm) <= 0)
enable = 0x00;
else
enable = 0x80;
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 4/4] drivers/rtc/sunxi: Replace deprecated rtc_tm_to_time()
2015-06-12 2:04 [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 2/4] rtc/lib: Introduce rtc_tm_sub() helper function Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 3/4] drivers/rtc/isl1208: Replace deprecated rtc_tm_to_time() Xunlei Pang
@ 2015-06-12 2:04 ` Xunlei Pang
2015-06-12 8:40 ` [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Alexandre Belloni
3 siblings, 0 replies; 7+ messages in thread
From: Xunlei Pang @ 2015-06-12 2:04 UTC (permalink / raw)
To: linux-kernel
Cc: rtc-linux, Alessandro Zummo, Alexandre Belloni, John Stultz,
Arnd Bergmann, Xunlei Pang, Carlo Caione
From: Xunlei Pang <pang.xunlei@linaro.org>
sunxi_rtc_setalarm() uses deprecated rtc_tm_to_time(),
which will overflow in year 2106 on 32-bit machines.
This patch solves this by:
- Replacing rtc_tm_to_time() with rtc_tm_sub()
Also remove the unnecessary initial zeroing of some
local variables in sunxi_rtc_setalarm().
Cc: Carlo Caione <carlo.caione@gmail.com>
Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
---
v2->v3:
Rename rtc_tm_subtract() to rtc_tm_sub().
drivers/rtc/rtc-sunxi.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c
index 6e678fa..52543ae 100644
--- a/drivers/rtc/rtc-sunxi.c
+++ b/drivers/rtc/rtc-sunxi.c
@@ -269,14 +269,13 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
struct sunxi_rtc_dev *chip = dev_get_drvdata(dev);
struct rtc_time *alrm_tm = &wkalrm->time;
struct rtc_time tm_now;
- u32 alrm = 0;
- unsigned long time_now = 0;
- unsigned long time_set = 0;
- unsigned long time_gap = 0;
- unsigned long time_gap_day = 0;
- unsigned long time_gap_hour = 0;
- unsigned long time_gap_min = 0;
- int ret = 0;
+ u32 alrm;
+ time64_t diff;
+ unsigned long time_gap;
+ unsigned long time_gap_day;
+ unsigned long time_gap_hour;
+ unsigned long time_gap_min;
+ int ret;
ret = sunxi_rtc_gettime(dev, &tm_now);
if (ret < 0) {
@@ -284,14 +283,18 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
return -EINVAL;
}
- rtc_tm_to_time(alrm_tm, &time_set);
- rtc_tm_to_time(&tm_now, &time_now);
- if (time_set <= time_now) {
+ diff = rtc_tm_sub(alrm_tm, &tm_now);
+ if (diff <= 0) {
dev_err(dev, "Date to set in the past\n");
return -EINVAL;
}
- time_gap = time_set - time_now;
+ if (diff > 255 * SEC_IN_DAY) {
+ dev_err(dev, "Day must be in the range 0 - 255\n");
+ return -EINVAL;
+ }
+
+ time_gap = diff;
time_gap_day = time_gap / SEC_IN_DAY;
time_gap -= time_gap_day * SEC_IN_DAY;
time_gap_hour = time_gap / SEC_IN_HOUR;
@@ -299,11 +302,6 @@ static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
time_gap_min = time_gap / SEC_IN_MIN;
time_gap -= time_gap_min * SEC_IN_MIN;
- if (time_gap_day > 255) {
- dev_err(dev, "Day must be in the range 0 - 255\n");
- return -EINVAL;
- }
-
sunxi_rtc_setaie(0, chip);
writel(0, chip->base + SUNXI_ALRM_DHMS);
usleep_range(100, 300);
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time()
2015-06-12 2:04 [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Xunlei Pang
` (2 preceding siblings ...)
2015-06-12 2:04 ` [PATCH v3 4/4] drivers/rtc/sunxi: " Xunlei Pang
@ 2015-06-12 8:40 ` Alexandre Belloni
2015-06-12 9:17 ` pang.xunlei
3 siblings, 1 reply; 7+ messages in thread
From: Alexandre Belloni @ 2015-06-12 8:40 UTC (permalink / raw)
To: Xunlei Pang
Cc: linux-kernel, rtc-linux, Alessandro Zummo, John Stultz,
Arnd Bergmann, Xunlei Pang
Hi Xunlei,
Just to let you know that your series are usually classified as spam
when coming from 126.com. This series in particular didn't make it to
the mailing list.
I'll take it anyway but you may want to check that your other patches
are being received by the maintainers.
On 12/06/2015 at 10:04:09 +0800, Xunlei Pang wrote :
> From: Xunlei Pang <pang.xunlei@linaro.org>
>
> pcf8563_rtc_set_alarm() uses deprecated rtc_tm_to_time()
> and rtc_time_to_tm(), which will overflow in year 2106
> on 32-bit machines.
>
> This patch solves this by:
> - Replacing rtc_time_to_tm() with rtc_time64_to_tm()
> - Replacing rtc_tm_to_time() with rtc_tm_to_time64()
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
> ---
> v2->v3:
> no changes.
>
> drivers/rtc/rtc-pcf8563.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
> index 0ba7e59..5f87f84 100644
> --- a/drivers/rtc/rtc-pcf8563.c
> +++ b/drivers/rtc/rtc-pcf8563.c
> @@ -363,13 +363,13 @@ static int pcf8563_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
> struct i2c_client *client = to_i2c_client(dev);
> unsigned char buf[4];
> int err;
> - unsigned long alarm_time;
>
> /* The alarm has no seconds, round up to nearest minute */
> if (tm->time.tm_sec) {
> - rtc_tm_to_time(&tm->time, &alarm_time);
> - alarm_time += 60-tm->time.tm_sec;
> - rtc_time_to_tm(alarm_time, &tm->time);
> + time64_t alarm_time = rtc_tm_to_time64(&tm->time);
> +
> + alarm_time += 60 - tm->time.tm_sec;
> + rtc_time64_to_tm(alarm_time, &tm->time);
> }
>
> dev_dbg(dev, "%s, min=%d hour=%d wday=%d mday=%d "
> --
> 1.9.1
>
>
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time()
2015-06-12 8:40 ` [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Alexandre Belloni
@ 2015-06-12 9:17 ` pang.xunlei
2015-06-12 12:29 ` Alexandre Belloni
0 siblings, 1 reply; 7+ messages in thread
From: pang.xunlei @ 2015-06-12 9:17 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Alessandro Zummo, Arnd Bergmann, John Stultz, linux-kernel,
Xunlei Pang, rtc-linux, Xunlei Pang
Hi Alexandre,
Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote 2015-06-12
PM 04:40:27:
>
> Re: [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated
> rtc_time_to_tm() and rtc_tm_to_time()
>
> Hi Xunlei,
>
> Just to let you know that your series are usually classified as spam
> when coming from 126.com. This series in particular didn't make it to
> the mailing list.
Seems ok, I can see it in the mailing list now:
https://lkml.org/lkml/2015/6/11/767
Thanks,
-Xunlei
>
> I'll take it anyway but you may want to check that your other patches
> are being received by the maintainers.
>
> On 12/06/2015 at 10:04:09 +0800, Xunlei Pang wrote :
> > From: Xunlei Pang <pang.xunlei@linaro.org>
> >
> > pcf8563_rtc_set_alarm() uses deprecated rtc_tm_to_time()
> > and rtc_time_to_tm(), which will overflow in year 2106
> > on 32-bit machines.
> >
> > This patch solves this by:
> > - Replacing rtc_time_to_tm() with rtc_time64_to_tm()
> > - Replacing rtc_tm_to_time() with rtc_tm_to_time64()
> >
> > Acked-by: Arnd Bergmann <arnd@arndb.de>
> > Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
> > ---
> > v2->v3:
> > no changes.
> >
> > drivers/rtc/rtc-pcf8563.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
> > index 0ba7e59..5f87f84 100644
> > --- a/drivers/rtc/rtc-pcf8563.c
> > +++ b/drivers/rtc/rtc-pcf8563.c
> > @@ -363,13 +363,13 @@ static int pcf8563_rtc_set_alarm(struct
> device *dev, struct rtc_wkalrm *tm)
> > struct i2c_client *client = to_i2c_client(dev);
> > unsigned char buf[4];
> > int err;
> > - unsigned long alarm_time;
> >
> > /* The alarm has no seconds, round up to nearest minute */
> > if (tm->time.tm_sec) {
> > - rtc_tm_to_time(&tm->time, &alarm_time);
> > - alarm_time += 60-tm->time.tm_sec;
> > - rtc_time_to_tm(alarm_time, &tm->time);
> > + time64_t alarm_time = rtc_tm_to_time64(&tm->time);
> > +
> > + alarm_time += 60 - tm->time.tm_sec;
> > + rtc_time64_to_tm(alarm_time, &tm->time);
> > }
> >
> > dev_dbg(dev, "%s, min=%d hour=%d wday=%d mday=%d "
> > --
> > 1.9.1
> >
> >
>
> --
> Alexandre Belloni, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com
--------------------------------------------------------
ZTE Information Security Notice: The information contained in this mail (and any attachment transmitted herewith) is privileged and confidential and is intended for the exclusive use of the addressee(s). If you are not an intended recipient, any disclosure, reproduction, distribution or other dissemination or use of the information contained is strictly prohibited. If you have received this mail in error, please delete it and notify us immediately.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time()
2015-06-12 9:17 ` pang.xunlei
@ 2015-06-12 12:29 ` Alexandre Belloni
0 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2015-06-12 12:29 UTC (permalink / raw)
To: pang.xunlei
Cc: Alessandro Zummo, Arnd Bergmann, John Stultz, linux-kernel,
Xunlei Pang, rtc-linux, Xunlei Pang
On 12/06/2015 at 17:17:39 +0800, pang.xunlei@zte.com.cn wrote :
> Hi Alexandre,
>
> Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote 2015-06-12
> PM 04:40:27:
> >
> > Re: [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated
> > rtc_time_to_tm() and rtc_tm_to_time()
> >
> > Hi Xunlei,
> >
> > Just to let you know that your series are usually classified as spam
> > when coming from 126.com. This series in particular didn't make it to
> > the mailing list.
>
> Seems ok, I can see it in the mailing list now:
> https://lkml.org/lkml/2015/6/11/767
>
Yeah, but for example it didn't go through the RTC mailing list:
https://groups.google.com/forum/#!forum/rtc-linux so the patch are not
in patchwork.
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-06-12 12:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-12 2:04 [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 2/4] rtc/lib: Introduce rtc_tm_sub() helper function Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 3/4] drivers/rtc/isl1208: Replace deprecated rtc_tm_to_time() Xunlei Pang
2015-06-12 2:04 ` [PATCH v3 4/4] drivers/rtc/sunxi: " Xunlei Pang
2015-06-12 8:40 ` [PATCH v3 1/4] drivers/rtc/pcf8563: Replace deprecated rtc_time_to_tm() and rtc_tm_to_time() Alexandre Belloni
2015-06-12 9:17 ` pang.xunlei
2015-06-12 12:29 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox