Hi everyone,
This is a conversion of all subsystem-wide v4l2 code to avoid the
use of types based on time_t. The first five patches should all
be harmless and obvious, so they can get applied for 4.3 after
normal review.
The last two patches are marked RFC for now because their possible
impact on the user space ABI and to decide if this is the best
approach or whether we should instead introduce extra code in
the kernel to handle modified user space.
There are a few device drivers beyond this series that rely on
time_t/timeval/timespec internally, but they are all easy to fix
and can be taken care of later.
Arnd
Arnd Bergmann (7):
[media] dvb: use ktime_t for internal timeout
[media] dvb: remove unused systime() function
[media] dvb: don't use 'time_t' in event ioctl
[media] exynos4-is: use monotonic timestamps as advertized
[media] use v4l2_get_timestamp where possible
[RFC] [media]: v4l2: introduce v4l2_timeval
[RFC] [media] introduce v4l2_timespec type for timestamps
drivers/media/dvb-core/demux.h | 2 +-
drivers/media/dvb-core/dmxdev.c | 2 +-
drivers/media/dvb-core/dvb_demux.c | 17 ++++++-----------
drivers/media/dvb-core/dvb_demux.h | 4 ++--
drivers/media/dvb-core/dvb_net.c | 2 +-
drivers/media/dvb-frontends/dibx000_common.c | 10 ----------
drivers/media/dvb-frontends/dibx000_common.h | 2 --
drivers/media/pci/bt8xx/bttv-driver.c | 7 ++-----
drivers/media/pci/cx18/cx18-mailbox.c | 2 +-
drivers/media/pci/meye/meye.h | 2 +-
drivers/media/pci/zoran/zoran.h | 2 +-
drivers/media/platform/coda/coda.h | 2 +-
drivers/media/platform/exynos4-is/fimc-capture.c | 8 +-------
drivers/media/platform/exynos4-is/fimc-lite.c | 7 +------
drivers/media/platform/omap/omap_vout.c | 4 ++--
drivers/media/platform/omap3isp/ispstat.c | 5 ++---
drivers/media/platform/omap3isp/ispstat.h | 2 +-
drivers/media/platform/s3c-camif/camif-capture.c | 8 +-------
drivers/media/platform/vim2m.c | 2 +-
drivers/media/platform/vivid/vivid-ctrls.c | 2 +-
drivers/media/usb/cpia2/cpia2.h | 2 +-
drivers/media/usb/cpia2/cpia2_v4l.c | 2 +-
drivers/media/usb/gspca/gspca.c | 6 +++---
drivers/media/usb/usbvision/usbvision.h | 2 +-
drivers/media/v4l2-core/v4l2-common.c | 6 +++---
drivers/media/v4l2-core/v4l2-event.c | 20 +++++++++++++-------
drivers/staging/media/omap4iss/iss_video.c | 5 +----
include/media/v4l2-common.h | 2 +-
include/media/videobuf-core.h | 2 +-
include/trace/events/v4l2.h | 12 ++++++++++--
include/uapi/linux/dvb/video.h | 3 ++-
include/uapi/linux/omap3isp.h | 2 +-
include/uapi/linux/videodev2.h | 16 ++++++++++++++--
33 files changed, 79 insertions(+), 93 deletions(-)
--
2.1.0.rc2
This patch replaces timeval with timespec64 as 32 bit 'struct timeval'
will not give current time beyond 2038.
The patch changes the code to use ktime_get_real_ts64() which returns
a 'struct timespec64' instead of do_gettimeofday() which returns a
'struct timeval'
This patch also alters the format strings in sprintf() for now.tv_sec
and now.tv_nsec to incorporate 'long long' on 32 bit architectures and
leading zeroes respectively.
Signed-off-by: Amitoj Kaur Chawla <amitoj1606(a)gmail.com>
Reviewed-by: Arnd Bergmann <arnd(a)arndb.de>
---
Changes in v2:
-change format string of now.tv_sec to '%llu'
-change format string of now.tv_nsec to '%.08lu'
Changes in v3:
-Replace tv_usec with tv_nsec, error made in v2
-Build tested
drivers/misc/ibmasm/ibmasm.h | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/ibmasm/ibmasm.h b/drivers/misc/ibmasm/ibmasm.h
index 9b08344..82380ae 100644
--- a/drivers/misc/ibmasm/ibmasm.h
+++ b/drivers/misc/ibmasm/ibmasm.h
@@ -34,6 +34,7 @@
#include <linux/kref.h>
#include <linux/device.h>
#include <linux/input.h>
+#include <linux/time64.h>
/* Driver identification */
#define DRIVER_NAME "ibmasm"
@@ -53,9 +54,10 @@ extern int ibmasm_debug;
static inline char *get_timestamp(char *buf)
{
- struct timeval now;
- do_gettimeofday(&now);
- sprintf(buf, "%lu.%lu", now.tv_sec, now.tv_usec);
+ struct timespec64 now;
+ ktime_get_real_ts64(&now);
+ sprintf(buf, "%llu.%.08lu", (long long)now.tv_sec,
+ now.tv_nsec / NSEC_PER_USEC);
return buf;
}
--
1.9.1
These series of patches try to convert parport device(ppdev) to
y2038 safe, and support y2038 safe and unsafe application at the
same time. The first version is here[1].
An y2038 safe application/kernel use 64bit time_t(aka time64_t)
to avoid 32-bit time types broken in the year 2038. Given that
some time relative struct(e.g. timeval in ppdev.c) is mainly the
offset of the real time, the old 32bit time_t in such application
is safe. We need to handle the 32bit time_t and 64bit time_t
application at the same time. My approach here is handle them as
different ioctl command for different size of timeval.
Build successful on arm64, arm and x86_64.
Changes since v1:
1. Fix the warning when build against x86_64.
[1] https://lkml.org/lkml/2015/12/9/32
Bamvor Jian Zhang (2):
ppdev: convert to y2038 safe
ppdev: add support for compat ioctl
drivers/char/ppdev.c | 87 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 67 insertions(+), 20 deletions(-)
--
2.1.4
These series of patches try to convert parport device(ppdev) to
y2038 safe, and support y2038 safe and unsafe application at the
same time. The first two version is here[1][2].
An y2038 safe application/kernel use 64bit time_t(aka time64_t)
to avoid 32-bit time types broken in the year 2038. Given that
some time relative struct(e.g. timeval in ppdev.c) is mainly the
offset of the real time, the old 32bit time_t in such application
is safe. We need to handle the 32bit time_t and 64bit time_t
application at the same time. My approach here is handle them as
different ioctl command for different size of timeval.
Build successful on arm64, arm and x86_64.
Changes since v2:
1. Fix the wrong parameter in copy_to_user.
Changes since v1:
1. Fix the warning when build against x86_64.
[1] https://lkml.org/lkml/2015/12/9/32
[2] https://lkml.org/lkml/2015/12/17/111
Bamvor Jian Zhang (2):
ppdev: convert to y2038 safe
ppdev: add support for compat ioctl
drivers/char/ppdev.c | 87 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 67 insertions(+), 20 deletions(-)
--
2.1.4
The y2038 issue of printer exist in the time_t of timeval in ioctl
LPSETTIME. This patch try to convert it to y2038 safe by the
following steps:
1. Remove timeval from lp_set_timeout in order to support 32bit and
64bit time_t in the same function without the new definition
of timeval64 or something else.
2. Handle both 32bit and 64bit time in the same LPSETTIMEOUT switch
case in order to support y2038 safe and non-safe cases.
3. Merge compat of LPSETTIMEOUT into non-comapt one.
I thought split these steps into three different patches. But I feel
these changes are simple and direct.
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian(a)linaro.org>
---
drivers/char/lp.c | 94 ++++++++++++++++++++++++++++++-------------------------
1 file changed, 52 insertions(+), 42 deletions(-)
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index c4094c4..a207e0c 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -136,6 +136,14 @@
#include <asm/irq.h>
#include <asm/uaccess.h>
+/*
+ * FIXME: It should be removed after COMPAT_USE_64BIT_TIME is accessible for
+ * 32bit architecture.
+ */
+#ifndef COMPAT_USE_64BIT_TIME
+#define COMPAT_USE_64BIT_TIME (0)
+#endif /* COMPAT_USE_64BIT_TIME */
+
/* if you have more than 8 printers, remember to increase LP_NO */
#define LP_NO 8
@@ -572,6 +580,22 @@ static int lp_release(struct inode * inode, struct file * file)
return 0;
}
+static int lp_set_timeout(unsigned int minor, s64 tv_sec, s64 tv_usec)
+{
+ long to_jiffies;
+
+ if ((tv_sec < 0) || (tv_usec < 0))
+ return -EINVAL;
+
+ to_jiffies = usecs_to_jiffies(tv_usec);
+ to_jiffies += tv_sec * (long)HZ;
+ if (to_jiffies <= 0)
+ return -EINVAL;
+
+ lp_table[minor].timeout = to_jiffies;
+ return 0;
+}
+
static int lp_do_ioctl(unsigned int minor, unsigned int cmd,
unsigned long arg, void __user *argp)
{
@@ -586,6 +610,9 @@ static int lp_do_ioctl(unsigned int minor, unsigned int cmd,
if ((LP_F(minor) & LP_EXIST) == 0)
return -ENODEV;
switch ( cmd ) {
+ s32 time32[2];
+ s64 time64[2];
+
case LPTIME:
if (arg > UINT_MAX / HZ)
return -EINVAL;
@@ -647,58 +674,49 @@ static int lp_do_ioctl(unsigned int minor, unsigned int cmd,
sizeof(struct lp_stats));
break;
#endif
- case LPGETFLAGS:
- status = LP_F(minor);
+ case LPGETFLAGS:
+ status = LP_F(minor);
if (copy_to_user(argp, &status, sizeof(int)))
return -EFAULT;
break;
+ case LPSETTIMEOUT:
+ /*
+ * For 64bit application or 32bit application with 64bit
+ * time_t
+ */
+ if ((IS_ENABLED(CONFIG_64BIT) && !is_compat_task())
+ || COMPAT_USE_64BIT_TIME) {
+ if (copy_from_user(time64, argp,
+ sizeof(time64)))
+ return -EFAULT;
+
+ return lp_set_timeout(minor, time64[0],
+ time64[1]);
+ } else {
+ if (copy_from_user(time32, argp,
+ sizeof(time32)))
+ return -EFAULT;
+
+ return lp_set_timeout(minor, time32[0],
+ time32[1]);
+ }
+ break;
default:
retval = -EINVAL;
}
return retval;
}
-static int lp_set_timeout(unsigned int minor, struct timeval *par_timeout)
-{
- long to_jiffies;
-
- /* Convert to jiffies, place in lp_table */
- if ((par_timeout->tv_sec < 0) ||
- (par_timeout->tv_usec < 0)) {
- return -EINVAL;
- }
- to_jiffies = DIV_ROUND_UP(par_timeout->tv_usec, 1000000/HZ);
- to_jiffies += par_timeout->tv_sec * (long) HZ;
- if (to_jiffies <= 0) {
- return -EINVAL;
- }
- lp_table[minor].timeout = to_jiffies;
- return 0;
-}
-
static long lp_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
unsigned int minor;
- struct timeval par_timeout;
int ret;
minor = iminor(file_inode(file));
mutex_lock(&lp_mutex);
- switch (cmd) {
- case LPSETTIMEOUT:
- if (copy_from_user(&par_timeout, (void __user *)arg,
- sizeof (struct timeval))) {
- ret = -EFAULT;
- break;
- }
- ret = lp_set_timeout(minor, &par_timeout);
- break;
- default:
- ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
- break;
- }
+ ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
mutex_unlock(&lp_mutex);
return ret;
@@ -709,19 +727,11 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
unsigned int minor;
- struct timeval par_timeout;
int ret;
minor = iminor(file_inode(file));
mutex_lock(&lp_mutex);
switch (cmd) {
- case LPSETTIMEOUT:
- if (compat_get_timeval(&par_timeout, compat_ptr(arg))) {
- ret = -EFAULT;
- break;
- }
- ret = lp_set_timeout(minor, &par_timeout);
- break;
#ifdef LP_STATS
case LPGETSTATS:
/* FIXME: add an implementation if you set LP_STATS */
--
2.1.4
From: Shraddha Barke <shraddha.6596(a)gmail.com>
32-bit systems using 'struct timeval' will break in the year 2038,
in order to avoid that replace the code with more appropriate types.
This patch replaces the use of struct timeval and do_gettimeofday()
with ktime_get_real_seconds() which returns a 64 bit seconds value.
Real time is used since if monotonic time is used we would get
duplicate timestamps after reboot as monotonic time starts from
zero on every reboot.
Signed-off-by: Shraddha Barke <shraddha.6596(a)gmail.com>
---
Changes in v2-
Used real time and updated commit message.
drivers/block/sx8.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index 59c91d4..1ec9fd2 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -23,7 +23,7 @@
#include <linux/workqueue.h>
#include <linux/bitops.h>
#include <linux/delay.h>
-#include <linux/time.h>
+#include <linux/ktime.h>
#include <linux/hdreg.h>
#include <linux/dma-mapping.h>
#include <linux/completion.h>
@@ -671,17 +671,17 @@ static int carm_send_special (struct carm_host *host, carm_sspc_t func)
static unsigned int carm_fill_sync_time(struct carm_host *host,
unsigned int idx, void *mem)
{
- struct timeval tv;
struct carm_msg_sync_time *st = mem;
- do_gettimeofday(&tv);
+ time64_t kt = ktime_get_real_seconds();
memset(st, 0, sizeof(*st));
st->type = CARM_MSG_MISC;
st->subtype = MISC_SET_TIME;
st->handle = cpu_to_le32(TAG_ENCODE(idx));
- st->timestamp = cpu_to_le32(tv.tv_sec);
+ st->timestamp = cpu_to_le32(kt);
+ /* This driver will break in 2106 */
return sizeof(struct carm_msg_sync_time);
}
--
2.1.4
A new fax document for you.
To view it please open the attachment.
Scanned at: Wed, 23 Dec 2015 10:26:50 +0300
Scanned by: Ernest Hoover
Filesize: 116 Kb
Pages: 12
Quality: 400 DPI
File name: fax_00325060.doc
Processed in: 50 seconds
Thanks for choosing Interfax!