diff options
author | Baolin Wang <baolin.wang@linaro.org> | 2017-11-09 02:09:20 -0500 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2017-11-10 03:57:38 -0500 |
commit | 9a06da2ecc92a81e969bd8c3768f63b63cb02e80 (patch) | |
tree | 4ba5522beded6b402ec7dbf338760ff82d57a040 | |
parent | 573e2bf05421d0dc69dc3c604f286b3473d2f2cd (diff) |
rtc: sysfs: Use time64_t variables to set time/alarm
Use time64_t variables and related APIs for sysfs interfaces to
support setting time or alarm after the year 2038 on 32-bit system.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
-rw-r--r-- | drivers/rtc/rtc-sysfs.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c index e364550eb9a7..92ff2edb86a6 100644 --- a/drivers/rtc/rtc-sysfs.c +++ b/drivers/rtc/rtc-sysfs.c | |||
@@ -72,9 +72,10 @@ since_epoch_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
72 | 72 | ||
73 | retval = rtc_read_time(to_rtc_device(dev), &tm); | 73 | retval = rtc_read_time(to_rtc_device(dev), &tm); |
74 | if (retval == 0) { | 74 | if (retval == 0) { |
75 | unsigned long time; | 75 | time64_t time; |
76 | rtc_tm_to_time(&tm, &time); | 76 | |
77 | retval = sprintf(buf, "%lu\n", time); | 77 | time = rtc_tm_to_time64(&tm); |
78 | retval = sprintf(buf, "%lld\n", time); | ||
78 | } | 79 | } |
79 | 80 | ||
80 | return retval; | 81 | return retval; |
@@ -132,7 +133,7 @@ static ssize_t | |||
132 | wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf) | 133 | wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf) |
133 | { | 134 | { |
134 | ssize_t retval; | 135 | ssize_t retval; |
135 | unsigned long alarm; | 136 | time64_t alarm; |
136 | struct rtc_wkalrm alm; | 137 | struct rtc_wkalrm alm; |
137 | 138 | ||
138 | /* Don't show disabled alarms. For uniformity, RTC alarms are | 139 | /* Don't show disabled alarms. For uniformity, RTC alarms are |
@@ -145,8 +146,8 @@ wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
145 | */ | 146 | */ |
146 | retval = rtc_read_alarm(to_rtc_device(dev), &alm); | 147 | retval = rtc_read_alarm(to_rtc_device(dev), &alm); |
147 | if (retval == 0 && alm.enabled) { | 148 | if (retval == 0 && alm.enabled) { |
148 | rtc_tm_to_time(&alm.time, &alarm); | 149 | alarm = rtc_tm_to_time64(&alm.time); |
149 | retval = sprintf(buf, "%lu\n", alarm); | 150 | retval = sprintf(buf, "%lld\n", alarm); |
150 | } | 151 | } |
151 | 152 | ||
152 | return retval; | 153 | return retval; |
@@ -157,8 +158,8 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, | |||
157 | const char *buf, size_t n) | 158 | const char *buf, size_t n) |
158 | { | 159 | { |
159 | ssize_t retval; | 160 | ssize_t retval; |
160 | unsigned long now, alarm; | 161 | time64_t now, alarm; |
161 | unsigned long push = 0; | 162 | time64_t push = 0; |
162 | struct rtc_wkalrm alm; | 163 | struct rtc_wkalrm alm; |
163 | struct rtc_device *rtc = to_rtc_device(dev); | 164 | struct rtc_device *rtc = to_rtc_device(dev); |
164 | const char *buf_ptr; | 165 | const char *buf_ptr; |
@@ -170,7 +171,7 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, | |||
170 | retval = rtc_read_time(rtc, &alm.time); | 171 | retval = rtc_read_time(rtc, &alm.time); |
171 | if (retval < 0) | 172 | if (retval < 0) |
172 | return retval; | 173 | return retval; |
173 | rtc_tm_to_time(&alm.time, &now); | 174 | now = rtc_tm_to_time64(&alm.time); |
174 | 175 | ||
175 | buf_ptr = buf; | 176 | buf_ptr = buf; |
176 | if (*buf_ptr == '+') { | 177 | if (*buf_ptr == '+') { |
@@ -181,7 +182,7 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, | |||
181 | } else | 182 | } else |
182 | adjust = 1; | 183 | adjust = 1; |
183 | } | 184 | } |
184 | retval = kstrtoul(buf_ptr, 0, &alarm); | 185 | retval = kstrtos64(buf_ptr, 0, &alarm); |
185 | if (retval) | 186 | if (retval) |
186 | return retval; | 187 | return retval; |
187 | if (adjust) { | 188 | if (adjust) { |
@@ -197,7 +198,7 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, | |||
197 | return retval; | 198 | return retval; |
198 | if (alm.enabled) { | 199 | if (alm.enabled) { |
199 | if (push) { | 200 | if (push) { |
200 | rtc_tm_to_time(&alm.time, &push); | 201 | push = rtc_tm_to_time64(&alm.time); |
201 | alarm += push; | 202 | alarm += push; |
202 | } else | 203 | } else |
203 | return -EBUSY; | 204 | return -EBUSY; |
@@ -212,7 +213,7 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, | |||
212 | */ | 213 | */ |
213 | alarm = now + 300; | 214 | alarm = now + 300; |
214 | } | 215 | } |
215 | rtc_time_to_tm(alarm, &alm.time); | 216 | rtc_time64_to_tm(alarm, &alm.time); |
216 | 217 | ||
217 | retval = rtc_set_alarm(rtc, &alm); | 218 | retval = rtc_set_alarm(rtc, &alm); |
218 | return (retval < 0) ? retval : n; | 219 | return (retval < 0) ? retval : n; |