Skip to content

Commit bc10aa9

Browse files
Xunlei Pangjohnstultz-work
authored andcommitted
rtc: Update interface.c to use y2038-safe time interfaces
Currently, interface.c uses y2038 problematic rtc_tm_to_time() and rtc_time_to_tm(). So replace them with their corresponding y2038-safe versions: rtc_tm_to_time64() and rtc_time64_to_tm(). Cc: pang.xunlei <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Signed-off-by: Xunlei Pang <[email protected]> Signed-off-by: John Stultz <[email protected]>
1 parent 2e0c78e commit bc10aa9

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

drivers/rtc/interface.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
7373
else if (rtc->ops->set_time)
7474
err = rtc->ops->set_time(rtc->dev.parent, tm);
7575
else if (rtc->ops->set_mmss) {
76-
unsigned long secs;
77-
err = rtc_tm_to_time(tm, &secs);
78-
if (err == 0)
79-
err = rtc->ops->set_mmss(rtc->dev.parent, secs);
76+
time64_t secs64 = rtc_tm_to_time64(tm);
77+
err = rtc->ops->set_mmss(rtc->dev.parent, secs64);
8078
} else
8179
err = -EINVAL;
8280

@@ -105,7 +103,7 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
105103

106104
err = rtc->ops->read_time(rtc->dev.parent, &old);
107105
if (err == 0) {
108-
rtc_time_to_tm(secs, &new);
106+
rtc_time64_to_tm(secs, &new);
109107

110108
/*
111109
* avoid writing when we're going to change the day of
@@ -157,7 +155,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
157155
int err;
158156
struct rtc_time before, now;
159157
int first_time = 1;
160-
unsigned long t_now, t_alm;
158+
time64_t t_now, t_alm;
161159
enum { none, day, month, year } missing = none;
162160
unsigned days;
163161

@@ -258,8 +256,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
258256
}
259257

260258
/* with luck, no rollover is needed */
261-
rtc_tm_to_time(&now, &t_now);
262-
rtc_tm_to_time(&alarm->time, &t_alm);
259+
t_now = rtc_tm_to_time64(&now);
260+
t_alm = rtc_tm_to_time64(&alarm->time);
263261
if (t_now < t_alm)
264262
goto done;
265263

@@ -273,7 +271,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
273271
case day:
274272
dev_dbg(&rtc->dev, "alarm rollover: %s\n", "day");
275273
t_alm += 24 * 60 * 60;
276-
rtc_time_to_tm(t_alm, &alarm->time);
274+
rtc_time64_to_tm(t_alm, &alarm->time);
277275
break;
278276

279277
/* Month rollover ... if it's the 31th, an alarm on the 3rd will
@@ -346,19 +344,19 @@ EXPORT_SYMBOL_GPL(rtc_read_alarm);
346344
static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
347345
{
348346
struct rtc_time tm;
349-
long now, scheduled;
347+
time64_t now, scheduled;
350348
int err;
351349

352350
err = rtc_valid_tm(&alarm->time);
353351
if (err)
354352
return err;
355-
rtc_tm_to_time(&alarm->time, &scheduled);
353+
scheduled = rtc_tm_to_time64(&alarm->time);
356354

357355
/* Make sure we're not setting alarms in the past */
358356
err = __rtc_read_time(rtc, &tm);
359357
if (err)
360358
return err;
361-
rtc_tm_to_time(&tm, &now);
359+
now = rtc_tm_to_time64(&tm);
362360
if (scheduled <= now)
363361
return -ETIME;
364362
/*

0 commit comments

Comments
 (0)