From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753616AbbF2O1H (ORCPT ); Mon, 29 Jun 2015 10:27:07 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:36149 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752960AbbF2O0j (ORCPT ); Mon, 29 Jun 2015 10:26:39 -0400 From: Bamvor Zhang Jian To: arnd@arndb.de, john.stultz@linaro.org, tglx@linutronix.de Cc: y2039@lists.linaro.org, linux-kernel@vger.kernel.org, bamvor.zhangjian@linaro.org Subject: [RFC PATCH v2 4/4] y2038: convert ppdev to 2038 safe Date: Mon, 29 Jun 2015 22:23:27 +0800 Message-Id: <1435587807-10008-5-git-send-email-bamvor.zhangjian@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435587807-10008-1-git-send-email-bamvor.zhangjian@linaro.org> References: <1435587807-10008-1-git-send-email-bamvor.zhangjian@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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