* [PATCH] staging: comedi: avoid using timeval
@ 2016-06-17 16:06 Arnd Bergmann
0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2016-06-17 16:06 UTC (permalink / raw)
To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, Leslie Klein
Cc: y2038, Arnd Bergmann, devel, linux-kernel
It depends on user space whether this is safe or not: if programs
interpret the data as a signed time_t value, they will be broken
in y2038, and we have to redesign the entire interface.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/staging/comedi/comedi_fops.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 629080f39db0..fe50d1f823c6 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1256,16 +1256,17 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
switch (insn->insn) {
case INSN_GTOD:
{
- struct timeval tv;
+ struct timespec64 tv;
if (insn->n != 2) {
ret = -EINVAL;
break;
}
- do_gettimeofday(&tv);
+ ktime_get_real_ts64(&tv);
data[0] = tv.tv_sec;
- data[1] = tv.tv_usec;
+ /* unsigned data safe until 2106 */
+ data[1] = tv.tv_nsec / NSEC_PER_USEC;
ret = 2;
break;
--
2.9.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] staging: comedi: avoid using timeval
@ 2016-06-17 19:56 Arnd Bergmann
0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2016-06-17 19:56 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: y2038, Arnd Bergmann, Ian Abbott, H Hartley Sweeten, devel, linux-kernel
Comedi uses 32-bit seconds for its timestamps, on both 32-bit and
64-bit machines. For all I can tell, this was originally meant as
a 'timespec', which would overflow in 2038 because of the use of
a signed 'long' on 32-bit machines, but it is now used as an
array of two unsigned 'lsampl_t' values in comedilib, which will
only overflow in 2106, on both 32-bit and 64-bit machines.
In an effort to get rid of all uses of 'struct timeval' in the kernel,
this replaces the internal code with a call to ktime_get_real_ts64()
and a comment at the location of the conversion.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/staging/comedi/comedi_fops.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 629080f39db0..10a8a9245925 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1256,16 +1256,17 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
switch (insn->insn) {
case INSN_GTOD:
{
- struct timeval tv;
+ struct timespec64 tv;
if (insn->n != 2) {
ret = -EINVAL;
break;
}
- do_gettimeofday(&tv);
- data[0] = tv.tv_sec;
- data[1] = tv.tv_usec;
+ ktime_get_real_ts64(&tv);
+ /* unsigned data safe until 2106 */
+ data[0] = (unsigned int)tv.tv_sec;
+ data[1] = tv.tv_nsec / NSEC_PER_USEC;
ret = 2;
break;
--
2.9.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-06-17 19:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-17 16:06 [PATCH] staging: comedi: avoid using timeval Arnd Bergmann
2016-06-17 19:56 Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®