[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1435587807-10008-5-git-send-email-bamvor.zhangjian@linaro.org>
Date: Mon, 29 Jun 2015 22:23:27 +0800
From: Bamvor Zhang Jian <bamvor.zhangjian@...aro.org>
To: arnd@...db.de, john.stultz@...aro.org, tglx@...utronix.de
Cc: y2039@...ts.linaro.org, linux-kernel@...r.kernel.org,
bamvor.zhangjian@...aro.org
Subject: [RFC PATCH v2 4/4] y2038: convert ppdev to 2038 safe
Convert ppdev use 64bit time_t internally by replacing timeval to
timeval64.
In order to migrate to y2038 safe, split ioctl command PP[SG]ETTIME
to PP[SG]ETTIME64(y2038 safe) and PP[SG]ETTIME32 (the legacy
behavior in 32bit application). The 32bit application should make
use of PP[SG]ETTIME64 and __kernel_timeval to migrate to time64_t.
Signed-off-by: Bamvor Zhang Jian <bamvor.zhangjian@...aro.org>
---
drivers/char/ppdev.c | 32 +++++++++++++++++++++++++-------
include/uapi/linux/ppdev.h | 14 ++++++++++++--
2 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 9207658..a103d3d 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -497,8 +497,9 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
unsigned char mask;
int mode;
int ret;
- struct timeval par_timeout;
+ struct timeval64 par_timeout;
long to_jiffies;
+ int is_not_compat_timeval = 0;
case PPRSTATUS:
reg = parport_read_status (port);
@@ -593,9 +594,17 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
atomic_sub (ret, &pp->irqc);
return 0;
- case PPSETTIME:
- if (copy_from_user (&par_timeout, argp, sizeof(struct timeval))) {
- return -EFAULT;
+ case PPSETTIME64:
+ is_not_compat_timeval = 1;
+ case PPSETTIME32:
+ if (is_not_compat_timeval) {
+ if (get_timeval64(&par_timeout, argp)) {
+ return -EFAULT;
+ }
+ } else {
+ if (compat_get_timeval64(&par_timeout, argp)) {
+ return -EFAULT;
+ }
}
/* Convert to jiffies, place in pp->pdev->timeout */
if ((par_timeout.tv_sec < 0) || (par_timeout.tv_usec < 0)) {
@@ -609,13 +618,22 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
pp->pdev->timeout = to_jiffies;
return 0;
- case PPGETTIME:
+ case PPGETTIME64:
+ is_not_compat_timeval = 1;
+ case PPGETTIME32:
to_jiffies = pp->pdev->timeout;
memset(&par_timeout, 0, sizeof(par_timeout));
par_timeout.tv_sec = to_jiffies / HZ;
par_timeout.tv_usec = (to_jiffies % (long)HZ) * (1000000/HZ);
- if (copy_to_user (argp, &par_timeout, sizeof(struct timeval)))
- return -EFAULT;
+ if (is_not_compat_timeval) {
+ if (put_timeval64(&par_timeout, argp)) {
+ return -EFAULT;
+ }
+ } else {
+ if (compat_put_timeval64(&par_timeout, argp)) {
+ return -EFAULT;
+ }
+ }
return 0;
default:
diff --git a/include/uapi/linux/ppdev.h b/include/uapi/linux/ppdev.h
index dc18c5d..d62a47d 100644
--- a/include/uapi/linux/ppdev.h
+++ b/include/uapi/linux/ppdev.h
@@ -74,8 +74,18 @@ struct ppdev_frob_struct {
#define PPSETPHASE _IOW(PP_IOCTL, 0x94, int)
/* Set and get port timeout (struct timeval's) */
-#define PPGETTIME _IOR(PP_IOCTL, 0x95, struct timeval)
-#define PPSETTIME _IOW(PP_IOCTL, 0x96, struct timeval)
+/* Force application use 64 time_t ioctl */
+/* TODO: It is an open question about we should use a __xxx_timeval or an
+ * implicit array.
+ * replace struct __kernel_timeval with __s32[4]
+ * replace struct compat_timeval with __s32[2]
+ */
+#define PPGETTIME PPGETTIME64
+#define PPSETTIME PPSETTIME64
+#define PPGETTIME64 _IOR(PP_IOCTL, 0x95, struct __kernel_timeval)
+#define PPSETTIME64 _IOW(PP_IOCTL, 0x96, struct __kernel_timeval)
+#define PPGETTIME32 _IOR(PP_IOCTL, 0x9c, struct __kernel_compat_timeval)
+#define PPSETTIME32 _IOW(PP_IOCTL, 0x9d, struct __kernel_compat_timeval)
/* Get available modes (what the hardware can do) */
#define PPGETMODES _IOR(PP_IOCTL, 0x97, unsigned int)
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists