Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/rtc: Provide y2038 safe rtc_class_ops.set_mmss() replacement

Currently the rtc_class_op's set_mmss() function takes a 32-bit
second value (on 32-bit systems), which is problematic for dates
past y2038.

This patch provides a safe version named set_mmss64() using
y2038 safe time64_t.

After this patch, set_mmss() is deprecated and all its users
will be fixed to use set_mmss64(), it can be removed when having
no users.

Signed-off-by: Xunlei Pang <pang.xunlei@linaro.org>
[jstultz: Add whitespace fix for checkpatch]
Signed-off-by: John Stultz <john.stultz@linaro.org>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1427945681-29972-8-git-send-email-john.stultz@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Xunlei Pang and committed by
Ingo Molnar
8e4ff1a8 cb850717

+12 -2
+7 -1
drivers/rtc/interface.c
··· 72 72 err = -ENODEV; 73 73 else if (rtc->ops->set_time) 74 74 err = rtc->ops->set_time(rtc->dev.parent, tm); 75 - else if (rtc->ops->set_mmss) { 75 + else if (rtc->ops->set_mmss64) { 76 + time64_t secs64 = rtc_tm_to_time64(tm); 77 + 78 + err = rtc->ops->set_mmss64(rtc->dev.parent, secs64); 79 + } else if (rtc->ops->set_mmss) { 76 80 time64_t secs64 = rtc_tm_to_time64(tm); 77 81 err = rtc->ops->set_mmss(rtc->dev.parent, secs64); 78 82 } else ··· 100 96 101 97 if (!rtc->ops) 102 98 err = -ENODEV; 99 + else if (rtc->ops->set_mmss64) 100 + err = rtc->ops->set_mmss64(rtc->dev.parent, secs); 103 101 else if (rtc->ops->set_mmss) 104 102 err = rtc->ops->set_mmss(rtc->dev.parent, secs); 105 103 else if (rtc->ops->read_time && rtc->ops->set_time) {
+4 -1
drivers/rtc/systohc.c
··· 35 35 if (rtc) { 36 36 /* rtc_hctosys exclusively uses UTC, so we call set_time here, 37 37 * not set_mmss. */ 38 - if (rtc->ops && (rtc->ops->set_time || rtc->ops->set_mmss)) 38 + if (rtc->ops && 39 + (rtc->ops->set_time || 40 + rtc->ops->set_mmss64 || 41 + rtc->ops->set_mmss)) 39 42 err = rtc_set_time(rtc, &tm); 40 43 rtc_class_close(rtc); 41 44 }
+1
include/linux/rtc.h
··· 77 77 int (*read_alarm)(struct device *, struct rtc_wkalrm *); 78 78 int (*set_alarm)(struct device *, struct rtc_wkalrm *); 79 79 int (*proc)(struct device *, struct seq_file *); 80 + int (*set_mmss64)(struct device *, time64_t secs); 80 81 int (*set_mmss)(struct device *, unsigned long secs); 81 82 int (*read_callback)(struct device *, int data); 82 83 int (*alarm_irq_enable)(struct device *, unsigned int enabled);